fossasia/loklak_webclient

View on GitHub
app/js/services/harvestingFrequency.js

Summary

Maintainability
A
1 hr
Test Coverage
'use strict';

var servicesModule = require('./_index.js');

/**
 * @ngInject
 */
// this should really come from loklak server to stay DRY
function HarvestingFrequencyService(moment) {

    const MAGIC_NUMBER = 2147483647; // max java int

    var service = {};

    service.values =
    [
        {
            'value' : 30
        },
        {
            'value' : 60
        },
        {
            'value' : 180
        },
        {
            'value' : 360
        },
        {
            'value' : 1440
        },
        {
            'value' : MAGIC_NUMBER
        }
    ];

    for (var key in service.values) {
        var value = service.values[key];
        if (value.value === MAGIC_NUMBER) {
            value.label = 'never update';
        } else {
            value.label = moment.duration(value.value, "minutes").humanize();
        }
    }

    return service;
}

servicesModule.service('HarvestingFrequencyService',['moment', HarvestingFrequencyService]);