summaryrefslogtreecommitdiffstats
path: root/js-old/controller/ExploreController.js
blob: 6d34efb407d068688b869724529a1fa878d8a496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
 * Nextcloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Bernhard Posselt 2014
 */
app.controller('ExploreController', function (sites, $rootScope, FeedResource, SettingsResource, $location) {
    'use strict';

    this.sites = sites;
    // join all sites
    this.feeds = Object.keys(sites).map(function (key) {
        return [key, sites[key]];
    }).reduce(function (xs, x) {
        var category = x[0];
        var feedList = x[1];
        feedList.forEach(function (feed) {
            feed.category = category;
        });
        return xs.concat(feedList);
    }, []);

    this.feedExists = function (location) {
        return FeedResource.getByLocation(location) !== undefined;
    };

    this.subscribeTo = function (location) {
        $rootScope.$broadcast('addFeed', location);
    };

    this.isCategoryShown = function (data) {
        return data.filter(function (element) {
            return FeedResource.getByLocation(element.feed) === undefined;
        }).length > 0;
    };

    this.getSupportedLanguageCodes = function () {
        return SettingsResource.getSupportedLanguageCodes();
    };

    this.getCurrentLanguageCode = function () {
        var language = $location.search().lang;
        if (!language) {
            language = SettingsResource.get('language');
        }
        return language;
    };

    this.showLanguage = function (languageCode) {
        $location.url('/explore/?lang=' + languageCode);
    };

    this.selectedLanguageCode = this.getCurrentLanguageCode();
});