summaryrefslogtreecommitdiffstats
path: root/js-old
diff options
context:
space:
mode:
authorHK2FB <tom.schmidt@helsana.ch>2022-05-15 13:16:56 +0200
committerSean Molenaar <sean@seanmolenaar.eu>2022-05-22 16:07:30 +0200
commitb036d309c27132e4f10df952e9335afdb3edfeb5 (patch)
treee888f1fa178f2fe36baefcfb2ccc080ef27645ce /js-old
parent50c8960f8d36ab6012f62034f815561078380dc0 (diff)
Vue Rewrite
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'js-old')
-rw-r--r--js-old/.jshintignore2
-rw-r--r--js-old/.jshintrc52
-rw-r--r--js-old/admin/Admin.js109
-rw-r--r--js-old/app/App.js18
-rw-r--r--js-old/app/Config.js221
-rw-r--r--js-old/app/Run.js133
-rw-r--r--js-old/controller/AppController.js22
-rw-r--r--js-old/controller/ContentController.js227
-rw-r--r--js-old/controller/ExploreController.js57
-rw-r--r--js-old/controller/NavigationController.js419
-rw-r--r--js-old/controller/SettingsController.js86
-rw-r--r--js-old/directive/AppNavigationEntryUtils.js37
-rw-r--r--js-old/directive/NewsAddFeed.js32
-rw-r--r--js-old/directive/NewsArticleActions.js28
-rw-r--r--js-old/directive/NewsAutoFocus.js24
-rw-r--r--js-old/directive/NewsBindUnsafeHtml.js18
-rw-r--r--js-old/directive/NewsDraggable.js30
-rw-r--r--js-old/directive/NewsDroppable.js34
-rw-r--r--js-old/directive/NewsFinishedTransition.js20
-rw-r--r--js-old/directive/NewsFocus.js22
-rw-r--r--js-old/directive/NewsInstantNotification.js26
-rw-r--r--js-old/directive/NewsOnActive.js23
-rw-r--r--js-old/directive/NewsPlayOne.js30
-rw-r--r--js-old/directive/NewsReadFile.js30
-rw-r--r--js-old/directive/NewsRefreshMasonry.js29
-rw-r--r--js-old/directive/NewsScroll.js111
-rw-r--r--js-old/directive/NewsSearch.js48
-rw-r--r--js-old/directive/NewsStickyMenu.js27
-rw-r--r--js-old/directive/NewsStopPropagation.js20
-rw-r--r--js-old/directive/NewsTimeout.js45
-rw-r--r--js-old/directive/NewsTitleUnreadCount.js35
-rw-r--r--js-old/directive/NewsToggleShow.js24
-rw-r--r--js-old/directive/NewsTriggerClick.js19
-rw-r--r--js-old/filter/TrustUrl.js16
-rw-r--r--js-old/filter/UnreadCountFormatter.js19
-rw-r--r--js-old/gui/ExternSubscription.js83
-rw-r--r--js-old/gui/Fixes.js25
-rw-r--r--js-old/gui/KeyboardShortcuts.js446
-rw-r--r--js-old/karma.conf.js80
-rw-r--r--js-old/plugin/ArticleActionPlugin.js18
-rw-r--r--js-old/protractor.conf.js46
-rw-r--r--js-old/service/FeedResource.js348
-rw-r--r--js-old/service/FolderResource.js123
-rw-r--r--js-old/service/ItemResource.js223
-rw-r--r--js-old/service/Loading.js27
-rw-r--r--js-old/service/OPMLImporter.js111
-rw-r--r--js-old/service/OPMLParser.js90
-rw-r--r--js-old/service/Publisher.js44
-rw-r--r--js-old/service/Resource.js90
-rw-r--r--js-old/service/SettingsResource.js85
-rw-r--r--js-old/tests/e2e/main.js34
-rw-r--r--js-old/tests/static/owncloud.org.rss639
-rw-r--r--js-old/tests/unit/controller/AppControllerSpec.js56
-rw-r--r--js-old/tests/unit/controller/ContentControllerSpec.js589
-rw-r--r--js-old/tests/unit/controller/ExploreControllerSpec.js72
-rw-r--r--js-old/tests/unit/controller/NavigationControllerSpec.js1141
-rw-r--r--js-old/tests/unit/controller/SettingsControllerSpec.js169
-rw-r--r--js-old/tests/unit/filter/UnreadCountFormatterSpec.js27
-rw-r--r--js-old/tests/unit/service/FeedResourceSpec.js338
-rw-r--r--js-old/tests/unit/service/FolderResourceSpec.js148
-rw-r--r--js-old/tests/unit/service/ItemResourceSpec.js387
-rw-r--r--js-old/tests/unit/service/LoadingSpec.js26
-rw-r--r--js-old/tests/unit/service/OPMLImporterSpec.js31
-rw-r--r--js-old/tests/unit/service/OPMLParserSpec.js87
-rw-r--r--js-old/tests/unit/service/PublisherSpec.js54
-rw-r--r--js-old/tests/unit/service/ResourceSpec.js140
-rw-r--r--js-old/tests/unit/service/SettingsResourceSpec.js101
-rw-r--r--js-old/tests/unit/stubs/App.js10
-rw-r--r--js-old/tests/unit/stubs/OC.js16
69 files changed, 7997 insertions, 0 deletions
diff --git a/js-old/.jshintignore b/js-old/.jshintignore
new file mode 100644
index 000000000..3e2e84b08
--- /dev/null
+++ b/js-old/.jshintignore
@@ -0,0 +1,2 @@
+build/
+node_modules/
diff --git a/js-old/.jshintrc b/js-old/.jshintrc
new file mode 100644
index 000000000..1f0c276f4
--- /dev/null
+++ b/js-old/.jshintrc
@@ -0,0 +1,52 @@
+{
+ "esnext": true,
+ "bitwise": true,
+ "camelcase": true,
+ "curly": true,
+ "eqeqeq": true,
+ "forin": false,
+ "immed": true,
+ "indent": 4,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "noempty": true,
+ "nonew": true,
+ "plusplus": true,
+ "quotmark": "single",
+ "undef": true,
+ "unused": true,
+ "strict": true,
+ "maxparams": false,
+ "maxdepth": 3,
+ "maxlen": 120,
+ "browser": true,
+ "devel": true,
+ "jquery": true,
+ "globals": {
+ "angular": true,
+ "app": true,
+ "OC": true,
+ "csrfToken": true,
+ "inject": true,
+ "module": true,
+ "protractor": true,
+ "browser": true,
+ "By": true,
+ "it": true,
+ "afterEach": true,
+ "jasmine": true,
+ "describe": true,
+ "beforeEach": true,
+ "expect": true,
+ "exports": true,
+ "reverse": true,
+ "items": true,
+ "enumerate": true,
+ "News": true,
+ "t": true,
+ "navigator": true,
+ "oc_requesttoken": true,
+ "_": true
+ }
+}
diff --git a/js-old/admin/Admin.js b/js-old/admin/Admin.js
new file mode 100644
index 000000000..5830f13f5
--- /dev/null
+++ b/js-old/admin/Admin.js
@@ -0,0 +1,109 @@
+/**
+ * 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
+ */
+
+/**
+ * Used to update the admin settings
+ */
+(function (window, document, $) {
+ 'use strict';
+
+ $(document).ready(function () {
+ var useCronUpdatesInput =
+ $('#news input[name="news-use-cron-updates"]');
+ var autoPurgeMinimumIntervalInput =
+ $('#news input[name="news-auto-purge-minimum-interval"]');
+ var autoPurgeCountInput =
+ $('#news input[name="news-auto-purge-count"]');
+ var maxRedirectsInput =
+ $('#news input[name="news-max-redirects"]');
+ var feedFetcherTimeoutInput =
+ $('#news input[name="news-feed-fetcher-timeout"]');
+ var maxSizeInput =
+ $('#news input[name="news-max-size"]');
+ var exploreUrlInput =
+ $('#news input[name="news-explore-url"]');
+ var updateIntervalInput =
+ $('#news input[name="news-update-interval"]');
+ var savedMessage = $('#news-saved-message');
+
+ var saved = function () {
+ if (savedMessage.is(':visible')) {
+ savedMessage.hide();
+ }
+
+ savedMessage.fadeIn(function () {
+ setTimeout(function () {
+ savedMessage.fadeOut();
+ }, 5000);
+ });
+ };
+
+ var submit = function () {
+ var autoPurgeMinimumInterval = autoPurgeMinimumIntervalInput.val();
+ var autoPurgeCount = autoPurgeCountInput.val();
+ var maxRedirects = maxRedirectsInput.val();
+ var feedFetcherTimeout = feedFetcherTimeoutInput.val();
+ var maxSize = maxSizeInput.val();
+ var exploreUrl = exploreUrlInput.val();
+ var updateInterval = updateIntervalInput.val()
+ var useCronUpdates = useCronUpdatesInput.is(':checked');
+
+ var data = {
+ autoPurgeMinimumInterval:
+ parseInt(autoPurgeMinimumInterval, 10),
+ autoPurgeCount: parseInt(autoPurgeCount, 10),
+ maxRedirects: parseInt(maxRedirects, 10),
+ feedFetcherTimeout: parseInt(feedFetcherTimeout, 10),
+ maxSize: parseInt(maxSize, 10),
+ useCronUpdates: useCronUpdates,
+ exploreUrl: exploreUrl,
+ updateInterval: parseInt(updateInterval, 10)
+ };
+
+ var url = OC.generateUrl('/apps/news/admin');
+
+ $.ajax({
+ type: 'PUT',
+ contentType: 'application/json; charset=utf-8',
+ url: url,
+ data: JSON.stringify(data),
+ dataType: 'json'
+ }).then(function (data) {
+ saved();
+ autoPurgeMinimumIntervalInput
+ .val(data.autoPurgeMinimumInterval);
+ autoPurgeCountInput.val(data.autoPurgeCount);
+ maxRedirectsInput.val(data.maxRedirects);
+ maxSizeInput.val(data.maxSize);
+ feedFetcherTimeoutInput.val(data.feedFetcherTimeout);
+ useCronUpdatesInput.prop('checked', data.useCronUpdates);
+ exploreUrlInput.val(data.exploreUrl);
+ updateIntervalInput.val(data.updateInterval);
+ });
+
+ };
+
+ $('#news input[type="text"]').blur(submit);
+ $('#news input[type="checkbox"]').change(submit);
+ $('#news-migrate').click(function () {
+ var button = $(this);
+ button.addClass('loading');
+
+ $.post(OC.generateUrl('/apps/news/admin/migrate'))
+ .always(function () {
+ button.removeClass('loading');
+ });
+
+ return false;
+ });
+ });
+
+
+}(window, document, jQuery));
diff --git a/js-old/app/App.js b/js-old/app/App.js
new file mode 100644
index 000000000..9e4ee5621
--- /dev/null
+++ b/js-old/app/App.js
@@ -0,0 +1,18 @@
+/**
+ * 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
+ */
+
+$('#content.app-news')
+ .attr('ng-app', 'News')
+ .attr('ng-cloak', '')
+ .attr('ng-strict-di', '')
+ .attr('ng-controller', 'AppController as App');
+
+/* jshint unused: false */
+var app = angular.module('News', ['ngRoute', 'ngSanitize', 'ngAnimate']);
diff --git a/js-old/app/Config.js b/js-old/app/Config.js
new file mode 100644
index 000000000..f7c62e7ae
--- /dev/null
+++ b/js-old/app/Config.js
@@ -0,0 +1,221 @@
+/**
+ * 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.config(function ($routeProvider, $provide, $httpProvider, $locationProvider) {
+ 'use strict';
+
+ var feedType = {
+ FEED: 0,
+ FOLDER: 1,
+ STARRED: 2,
+ SUBSCRIPTIONS: 3,
+ SHARED: 4,
+ EXPLORE: 5,
+ UNREAD: 6
+ };
+
+ // default hashPrefix changed in angular 1.6 to '!'
+ // change back to empty string to keep links working
+ $locationProvider.hashPrefix('');
+
+ // constants
+ $provide.constant('REFRESH_RATE', 60); // seconds
+ $provide.constant('ITEM_BATCH_SIZE', 40); // how many items should be
+ // fetched initially
+ $provide.constant('ITEM_AUTO_PAGE_SIZE', 20);
+ $provide.constant('BASE_URL', OC.generateUrl('/apps/news'));
+ $provide.constant('FEED_TYPE', feedType);
+ $provide.constant('MARK_READ_TIMEOUT', 0.5);
+ $provide.constant('SCROLL_TIMEOUT', 0.1);
+
+ // make sure that the CSRF header is only sent to the Nextcloud domain
+ $provide.factory('CSRFInterceptor', function ($q, BASE_URL, $window) {
+ return {
+ request: function (config) {
+ const token = $window.document.getElementsByTagName('head')[0]
+ .getAttribute('data-requesttoken');
+ const domain =
+ $window.location.href.split($window.location.pathname)[0];
+ if (config.url.indexOf(BASE_URL) === 0 ||
+ config.url.indexOf(domain) === 0) {
+ /*jshint camelcase: false */
+ config.headers.requesttoken = token;
+ }
+
+ return config || $q.when(config);
+ }
+ };
+ });
+ var errorMessages = {
+ 0: t('news', 'Request failed, network connection unavailable!'),
+ 401: t('news', 'Request unauthorized. Are you logged in?'),
+ 403: t('news', 'Request forbidden. Are you an admin?'),
+ 412: t('news', 'Token expired or app not enabled! Reload the page!'),
+ 500: t('news', 'Internal server error! Please check your ' +
+ 'data/nextcloud.log file for additional ' +
+ 'information!'),
+ 503: t('news', 'Request failed, Nextcloud is in currently ' +
+ 'in maintenance mode!')
+ };
+ $provide.factory('ConnectionErrorInterceptor', function ($q, $timeout) {
+ var timer;
+ return {
+ responseError: function (response) {
+ // status 0 is a network error
+ function sendNotification() {
+ OC.Notification.showHtml(errorMessages[response.status]);
+ timer = $timeout(function () {
+ OC.Notification.hide();
+ }, 5000);
+ }
+ if (response.status in errorMessages) {
+ if (timer) {
+ timer.then(function (){
+ sendNotification();
+ });
+ } else {
+ sendNotification();
+ }
+ }
+ return $q.reject(response);
+ }
+ };
+ });
+ $httpProvider.interceptors.push('CSRFInterceptor');
+ $httpProvider.interceptors.push('ConnectionErrorInterceptor');
+
+ // routing
+ var getItemResolve = function (type) {
+ return {
+ // request to items also returns feeds
+ data: /* @ngInject */ function (
+ $http, $route, $q, $location, BASE_URL, ITEM_BATCH_SIZE, FEED_TYPE,
+ SettingsResource, FeedResource) {
+
+ var showAll = SettingsResource.get('showAll');
+ var oldestFirst = SettingsResource.get('oldestFirst');
+ var search = $location.search().search || '';
+
+ // if those two values are null it means we did not receive
+ // the settings request from the server so dont query the server
+ if (showAll === null || oldestFirst === null) {
+ return {};
+ } else {
+ var parameters = {
+ type: type,
+ limit: ITEM_BATCH_SIZE,
+ showAll: showAll,
+ oldestFirst: oldestFirst,
+ search: search
+ };
+
+ if ($route.current !== undefined &&
+ $route.current.params !== undefined &&
+ $route.current.params.id !== undefined) {
+ parameters.id = $route.current.params.id;
+ }
+
+ // check if a custom ordering is set
+ if (type === FEED_TYPE.FEED) {
+ var feed = FeedResource.getById(parameters.id);
+
+ // on intial load, the feed ordering is undefined
+ if (feed === undefined || feed.ordering === 2) {
+ parameters.oldestFirst = false;
+ } else if (feed.ordering === 1) {
+ parameters.oldestFirst = true;
+ }
+ }
+
+ return $http({
+ url: BASE_URL + '/items',
+ method: 'GET',
+ params: parameters
+ }).then(function (response) {
+ return response.data;
+ });
+ }
+ }
+ };
+ };
+
+ var getExploreResolve = function () {
+ return {
+ sites: /* @ngInject */ function (
+ $http, $q, BASE_URL, $location, Publisher, SettingsResource) {
+ // always use the code from the url
+ var language = $location.search().lang;
+ if (!language) {
+ language = SettingsResource.get('language');
+ }
+
+ return $http.get(
+ BASE_URL + '/settings').then(function (response) {
+ Publisher.publishAll(response.data);
+
+ // get url and strip trailing slashes
+ var url = SettingsResource.get('exploreUrl')
+ .replace(/\/+$/, '');
+
+ var exploreUrl = url + '/feeds.' + language + '.json';
+ var defaultExploreUrl = url + '/feeds.en.json';
+ return $http
+ .get(exploreUrl)
+ .catch(function () {
+ return $http.get(defaultExploreUrl);
+ });
+
+ }).then(function (response) {
+ return response.data;
+ });
+ }
+ };
+ };
+
+ $routeProvider
+ .when('/items', {
+ controller: 'ContentController as Content',
+ templateUrl: 'content.html',
+ resolve: getItemResolve(feedType.SUBSCRIPTIONS),
+ type: feedType.SUBSCRIPTIONS
+ })
+ .when('/items/starred', {
+ controller: 'ContentController as Content',
+ templateUrl: 'content.html',
+ resolve: getItemResolve(feedType.STARRED),
+ type: feedType.STARRED
+ })
+ .when('/items/unread', {
+ controller: 'ContentController as Content',
+ templateUrl: 'content.html',
+ resolve: getItemResolve(feedType.UNREAD),
+ type: feedType.UNREAD
+ })
+ .when('/items/feeds/:id', {
+ controller: 'ContentController as Content',
+ templateUrl: 'content.html',
+ resolve: getItemResolve(feedType.FEED),
+ type: feedType.FEED
+ })
+ .when('/items/folders/:id', {
+ controller: 'ContentController as Content',
+ templateUrl: 'content.html',
+ resolve: getItemResolve(feedType.FOLDER),
+ type: feedType.FOLDER
+ }).when('/explore', {
+ controller: 'ExploreController as Explore',
+ templateUrl: 'explore.html',
+ resolve: getExploreResolve(),
+ type: feedType.EXPLORE
+ }).when('/shortcuts', {
+ templateUrl: 'shortcuts.html',
+ type: -1
+ });
+
+});
diff --git a/js-old/app/Run.js b/js-old/app/Run.js
new file mode 100644
index 000000000..1a1572864
--- /dev/null
+++ b/js-old/app/Run.js
@@ -0,0 +1,133 @@
+/**
+ * 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.run(function ($rootScope, $location, $http, $q, $interval, $route, Loading, ItemResource, FeedResource,
+ FolderResource, SettingsResource, Publisher, BASE_URL, FEED_TYPE, REFRESH_RATE) {
+ 'use strict';
+
+ // show Loading screen
+ Loading.setLoading('global', true);
+
+ // listen to keys in returned queries to automatically distribute the
+ // incoming values to models
+ Publisher.subscribe(ItemResource).toChannels(['items', 'newestItemId',
+ 'starred', 'unread']);
+ Publisher.subscribe(FolderResource).toChannels(['folders']);
+ Publisher.subscribe(FeedResource).toChannels(['feeds']);
+ Publisher.subscribe(SettingsResource).toChannels(['settings']);
+
+ // load feeds, settings and last read feed
+ var settingsPromise = $http.get(BASE