diff options
author | HK2FB <tom.schmidt@helsana.ch> | 2022-05-15 13:16:56 +0200 |
---|---|---|
committer | Sean Molenaar <sean@seanmolenaar.eu> | 2022-05-22 16:07:30 +0200 |
commit | b036d309c27132e4f10df952e9335afdb3edfeb5 (patch) | |
tree | e888f1fa178f2fe36baefcfb2ccc080ef27645ce /js-old | |
parent | 50c8960f8d36ab6012f62034f815561078380dc0 (diff) |
Vue Rewrite
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'js-old')
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', |