show tip when language resource is updated

master
MaysWind 2019-08-20 21:46:05 +08:00
parent d63058c3e0
commit ce1c2fed4b
6 changed files with 63 additions and 5 deletions

View File

@ -196,8 +196,9 @@ Downloading Count=正在下载数量
Waiting Count=正在等待数量
Stopped Count=已停止数量
You have disabled notification in your browser. You should change your browser's settings before you enable this function.=您已经在浏览器中禁用通知功能. 如需使用此功能, 请修改您浏览器的设置.
Language resource has been updated, please reload the page for the changes to take effect.=语言资源已经更新, 请重新加载页面使其生效.
Configuration has been modified, please reload the page for the changes to take effect.=配置已经修改, 请重新加载页面使其生效.
Reload Page=重新加载页面
Reload AriaNg=重新加载 AriaNg
Show Secret=显示密钥
Hide Secret=隐藏密钥
Aria2 Version=Aria2 版本

View File

@ -196,8 +196,9 @@ Current RPC Alias=目前 RPC 別名
Waiting Count=正在等待數量
Stopped Count=已停止數量
You have disabled notification in your browser. You should change your browser's settings before you enable this function.=您已經在瀏覽器中停用通知功能. 如需使用此功能, 請修改您瀏覽器的設定.
Language resource has been updated, please reload the page for the changes to take effect.=語言資源已經更新, 請重新載入頁面使其生效.
Configuration has been modified, please reload the page for the changes to take effect.=配置已經修改, 請重新載入頁面使其生效.
Reload Page=重新載入頁面
Reload AriaNg=重新載入 AriaNg
Show Secret=顯示金鑰
Hide Secret=隱藏金鑰
Aria2 Version=Aria2 版本

View File

@ -200,8 +200,9 @@
'Waiting Count': 'Waiting Count',
'Stopped Count': 'Stopped Count',
'You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.': 'You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.',
'Language resource has been updated, please reload the page for the changes to take effect.': 'Language resource has been updated, please reload the page for the changes to take effect.',
'Configuration has been modified, please reload the page for the changes to take effect.': 'Configuration has been modified, please reload the page for the changes to take effect.',
'Reload Page': 'Reload Page',
'Reload AriaNg': 'Reload AriaNg',
'Show Secret': 'Show Secret',
'Hide Secret': 'Hide Secret',
'Aria2 Version': 'Aria2 Version',

View File

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService) {
angular.module('ariaNg').run(['$window', '$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', function ($window, $rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService) {
var isUrlMatchUrl2 = function (url, url2) {
if (url === url2) {
return true;
@ -324,6 +324,10 @@
}
};
$rootScope.refreshPage = function () {
$window.location.reload();
};
ariaNgSettingService.onFirstAccess(function () {
ariaNgLocalizationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', {
delay: false,

View File

@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgAssetsCacheService', 'ariaNgNotificationService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, $q, ariaNgConstants, ariaNgLanguages, ariaNgAssetsCacheService, ariaNgNotificationService, ariaNgLogService, ariaNgStorageService) {
angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgAssetsCacheService', 'ariaNgNotificationService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, $q, ariaNgConstants, ariaNgLanguages, ariaNgAssetsCacheService, ariaNgNotificationService, ariaNgLocalizationService, ariaNgLogService, ariaNgStorageService) {
var getKeyValuePair = function (line) {
for (var i = 0; i < line.length; i++) {
if (i > 0 && line.charAt(i - 1) !== '\\' && line.charAt(i) === '=') {
@ -81,6 +81,33 @@
return langObj;
};
var isLanguageResourceEquals = function (langObj1, langObj2) {
if (!angular.isObject(langObj1) || !angular.isObject(langObj2)) {
return false;
}
for (var key in langObj2) {
if (!langObj2.hasOwnProperty(key)) {
continue;
}
var value = langObj2[key];
if (angular.isObject(value)) {
var result = isLanguageResourceEquals(langObj1[key], value);
if (!result) {
return false;
}
} else {
if (value !== langObj1[key]) {
return false;
}
}
}
return true;
};
return function (options) {
var deferred = $q.defer();
@ -111,7 +138,25 @@
method: 'GET'
}).then(function onSuccess(response) {
var languageObject = getLanguageObject(response.data);
var languageUpdated = false;
if (languageResource) {
languageUpdated = !isLanguageResourceEquals(languageResource, languageObject);
}
ariaNgStorageService.set(languageKey, languageObject);
if (languageUpdated) {
ariaNgLogService.info("[ariaNgLanguageLoader] load language resource successfully, and resource is updated");
ariaNgLocalizationService.notifyInPage('', 'Language resource has been updated, please reload the page for the changes to take effect.', {
delay: false,
type: 'info',
templateUrl: 'views/notification-reloadable.html'
});
} else {
ariaNgLogService.info("[ariaNgLanguageLoader] load language resource successfully, but resource is not updated");
}
return deferred.resolve(languageObject);
}).catch(function onError(response) {
ariaNgLogService.warn('[ariaNgLanguageLoader] cannot get language resource');

View File

@ -0,0 +1,6 @@
<div class="ui-notification custom-template">
<div class="message" ng-bind-html="message"></div>
<div class="message">
<a class="btn btn-small btn-primary close-notification" ng-click="refreshPage()" translate>Reload AriaNg</a>
</div>
</div>