From 9291123f8f6b58156ff278c894a0d7dbae599f70 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Fri, 23 Jan 2015 00:03:50 +0800 Subject: [PATCH] Add settings section for options syncing. Fix #7. --- omega-i18n/en/messages.json | 30 ++++++++++++++ omega-i18n/zh_CN/messages.json | 30 ++++++++++++++ omega-i18n/zh_HK/messages.json | 30 ++++++++++++++ omega-i18n/zh_TW/messages.json | 30 ++++++++++++++ omega-web/src/omega/controllers/io.coffee | 26 ++++++++++--- omega-web/src/omega/controllers/master.coffee | 4 ++ omega-web/src/partials/io.jade | 39 ++++++++++++++++++- 7 files changed, 182 insertions(+), 7 deletions(-) diff --git a/omega-i18n/en/messages.json b/omega-i18n/en/messages.json index 6a6825b..93270a3 100644 --- a/omega-i18n/en/messages.json +++ b/omega-i18n/en/messages.json @@ -259,6 +259,36 @@ "options_restoreOnlineSubmit": { "message": "Restore" }, + "options_group_syncing": { + "message": "Syncing (Experimental)" + }, + "options_syncEnable": { + "message": "Enable Syncing" + }, + "options_syncEnableForce": { + "message": "Download from Syncing" + }, + "options_syncDisable": { + "message": "Disable syncing" + }, + "options_syncPristineHelp": { + "message": "You can now automatically synchroize your settings and profiles across all your desktop devices running Chrome browser." + }, + "options_syncSyncAlert": { + "message": "Your options are automatically synchroized with your other devices." + }, + "options_syncSyncHelp": { + "message": "Please note that you must sign in to Chrome on each of your devices (including this one) for the syncing to actually work.
You may check this section on other devices to ensure that it is working." + }, + "options_syncConflictAlert": { + "message": "You have uploaded a copy of your options on another device via syncing." + }, + "options_syncConflictHelp": { + "message": "You may download the remote copy to your device if you like.
However, doing so would overwrite your existing settings and profiles on this device." + }, + "options_syncUnsupportedHelp": { + "message": "Options syncing is not supported on your platform or browser. For now, only Chrome browser on desktop is supported." + }, "options_profileTabPrefix": { "message": "Profile :: " }, diff --git a/omega-i18n/zh_CN/messages.json b/omega-i18n/zh_CN/messages.json index 89252bd..50c472c 100644 --- a/omega-i18n/zh_CN/messages.json +++ b/omega-i18n/zh_CN/messages.json @@ -259,6 +259,36 @@ "options_restoreOnlineSubmit": { "message": "恢复" }, + "options_group_syncing": { + "message": "选项同步 (测试中)" + }, + "options_syncEnable": { + "message": "启用同步" + }, + "options_syncEnableForce": { + "message": "下载云端版本" + }, + "options_syncDisable": { + "message": "禁用同步" + }, + "options_syncPristineHelp": { + "message": "您可以将设置和情景模式同步到所有使用Chrome浏览器的桌面设备。" + }, + "options_syncSyncAlert": { + "message": "您的设置将会自动与其他设备进行同步。" + }, + "options_syncSyncHelp": { + "message": "请注意:您需要在所有设备上(包括此设备)的Chrome浏览器中登录,这样同步的选项才能正常使用。
可以在其他设备上查看此页面,来检查同步是否生效。" + }, + "options_syncConflictAlert": { + "message": "您已经通过其他设备上传了一份选项用于同步。" + }, + "options_syncConflictHelp": { + "message": "您可以将云端的选项下载到此设备使用。
一旦选择下载,此设备上的设置和情景模式将会被覆盖。" + }, + "options_syncUnsupportedHelp": { + "message": "选项同步暂不支持您的平台或浏览器。目前只支持桌面版Chrome的浏览器的同步,请谅解。" + }, "options_profileTabPrefix": { "message": "情景模式: " }, diff --git a/omega-i18n/zh_HK/messages.json b/omega-i18n/zh_HK/messages.json index 2b2464b..da5fe80 100644 --- a/omega-i18n/zh_HK/messages.json +++ b/omega-i18n/zh_HK/messages.json @@ -259,6 +259,36 @@ "options_restoreOnlineSubmit": { "message": "恢復" }, + "options_group_syncing": { + "message": "選項同步 (測試中)" + }, + "options_syncEnable": { + "message": "啟用同步" + }, + "options_syncEnableForce": { + "message": "下載雲端版本" + }, + "options_syncDisable": { + "message": "禁用同步" + }, + "options_syncPristineHelp": { + "message": "您可以將設定和情景模式同步到所有使用Chrome瀏覽器的桌面裝置。" + }, + "options_syncSyncAlert": { + "message": "您的設定將會自動與其他裝置進行同步。" + }, + "options_syncSyncHelp": { + "message": "請注意:您需要在所有裝置上(包括此裝置)的Chrome瀏覽器中登入,這樣同步的選項才能正常使用。
可以在其他裝置上檢視此頁面,來檢查同步是否生效。" + }, + "options_syncConflictAlert": { + "message": "您已經通過其他裝置上傳了一份選項用於同步。" + }, + "options_syncConflictHelp": { + "message": "您可以將雲端的選項下載到此裝置使用。
一旦選擇下載,此裝置上的設定和情景模式將會被覆蓋。" + }, + "options_syncUnsupportedHelp": { + "message": "選項同步暫不支援您的平臺或瀏覽器。目前只支援桌面版Chrome的瀏覽器的同步,請諒解。" + }, "options_profileTabPrefix": { "message": "情景模式: " }, diff --git a/omega-i18n/zh_TW/messages.json b/omega-i18n/zh_TW/messages.json index 03621bd..960a387 100644 --- a/omega-i18n/zh_TW/messages.json +++ b/omega-i18n/zh_TW/messages.json @@ -259,6 +259,36 @@ "options_restoreOnlineSubmit": { "message": "恢復" }, + "options_group_syncing": { + "message": "選項同步 (測試中)" + }, + "options_syncEnable": { + "message": "啟用同步" + }, + "options_syncEnableForce": { + "message": "下載雲端版本" + }, + "options_syncDisable": { + "message": "禁用同步" + }, + "options_syncPristineHelp": { + "message": "您可以將設定和情景模式同步到所有使用Chrome瀏覽器的桌面裝置。" + }, + "options_syncSyncAlert": { + "message": "您的設定將會自動與其他裝置進行同步。" + }, + "options_syncSyncHelp": { + "message": "請注意:您需要在所有裝置上(包括此裝置)的Chrome瀏覽器中登入,這樣同步的選項才能正常使用。
可以在其他裝置上檢視此頁面,來檢查同步是否生效。" + }, + "options_syncConflictAlert": { + "message": "您已經通過其他裝置上傳了一份選項用於同步。" + }, + "options_syncConflictHelp": { + "message": "您可以將雲端的選項下載到此裝置使用。
一旦選擇下載,此裝置上的設定和情景模式將會被覆蓋。" + }, + "options_syncUnsupportedHelp": { + "message": "選項同步暫不支援您的平臺或瀏覽器。目前只支援桌面版Chrome的瀏覽器的同步,請諒解。" + }, "options_profileTabPrefix": { "message": "情景模式: " }, diff --git a/omega-web/src/omega/controllers/io.coffee b/omega-web/src/omega/controllers/io.coffee index b1d54ea..e73407b 100644 --- a/omega-web/src/omega/controllers/io.coffee +++ b/omega-web/src/omega/controllers/io.coffee @@ -1,4 +1,6 @@ -angular.module('omega').controller 'IoCtrl', ($scope, $rootScope) -> +angular.module('omega').controller 'IoCtrl', ($scope, $rootScope, + $window, omegaTarget) -> + $scope.exportOptions = -> $rootScope.applyOptionsConfirm().then -> plainOptions = angular.fromJson(angular.toJson($rootScope.options)) @@ -14,11 +16,11 @@ angular.module('omega').controller 'IoCtrl', ($scope, $rootScope) -> ) $scope.restoreLocal = (content) -> - $rootScope.resetOptions(content).then ( -> + $scope.restoringLocal = true + $rootScope.resetOptions(content).then(( -> $scope.importSuccess() - $rootScope.updateProfile().finally -> - $scope.importSuccess() - ), -> $scope.restoreLocalError() + ), -> $scope.restoreLocalError()).finally -> + $scope.restoringLocal = false $scope.restoreLocalError = -> $rootScope.showAlert( type: 'error' @@ -44,3 +46,17 @@ angular.module('omega').controller 'IoCtrl', ($scope, $rootScope) -> cache: false, timeout: 10000 ) + + $scope.enableOptionsSync = (args) -> + enable = -> + omegaTarget.setOptionsSync(true, args).finally -> + $window.location.reload() + if args?.force + enable() + else + $rootScope.applyOptionsConfirm().then enable + + $scope.disableOptionsSync = -> + omegaTarget.setOptionsSync(false).then -> + $rootScope.applyOptionsConfirm().then -> + $window.location.reload() diff --git a/omega-web/src/omega/controllers/master.coffee b/omega-web/src/omega/controllers/master.coffee index f79189e..882a5fa 100644 --- a/omega-web/src/omega/controllers/master.coffee +++ b/omega-web/src/omega/controllers/master.coffee @@ -10,6 +10,10 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window, omegaTarget.addOptionsChangeCallback (newOptions) -> $rootScope.options = angular.copy(newOptions) $rootScope.optionsOld = angular.copy(newOptions) + + omegaTarget.state('syncOptions').then (syncOptions) -> + $scope.syncOptions = syncOptions + $timeout -> $rootScope.optionsDirty = false diff --git a/omega-web/src/partials/io.jade b/omega-web/src/partials/io.jade index 5ce9fe4..b099f64 100644 --- a/omega-web/src/partials/io.jade +++ b/omega-web/src/partials/io.jade @@ -17,8 +17,10 @@ section.settings-group | {{'options_makeBackup' | tr}} span.help-inline {{'options_makeBackupHelp' | tr}} p - input#restore-local-file(type='file' omega-upload='restoreLocal($content)' omega-error='restoreLocalError($error)') - button.btn.btn-default(ng-click='triggerFileInput()') + input#restore-local-file(type='file' omega-upload='restoreLocal($content)' + omega-error='restoreLocalError($error)') + button.btn.btn-default(ng-click='triggerFileInput()' + ladda='restoringLocal' data-spinner-color="#000000") span.glyphicon.glyphicon-folder-open = ' ' | {{'options_restoreLocal' | tr}} @@ -29,3 +31,36 @@ section.settings-group input.form-control(type='url' ng-model='restoreOnlineUrl' placeholder="{{'options_restoreOnlinePlaceholder' | tr}}") span.input-group-btn button.btn.btn-default(ng-click='restoreOnline()') {{'options_restoreOnlineSubmit' | tr}} +section.settings-group + h3 {{'options_group_syncing' | tr}} + div(ng-show='syncOptions == "pristine" || syncOptions == "disabled"') + p.help-block(omega-html='"options_syncPristineHelp" | tr') + p + button.btn.btn-default(ng-click='enableOptionsSync()') + span.glyphicon.glyphicon-cloud-upload + = ' ' + | {{'options_syncEnable' | tr}} + div(ng-show='syncOptions == "sync"') + p.alert.alert-success.width-limit + span.glyphicon.glyphicon-ok + = ' ' + | {{"options_syncSyncAlert" | tr}} + p.help-block(omega-html='"options_syncSyncHelp" | tr') + p + button.btn.btn-warning(ng-click='disableOptionsSync()') + span.glyphicon.glyphicon-remove-sign + = ' ' + | {{'options_syncDisable' | tr}} + div(ng-show='syncOptions == "conflict"') + p.alert.alert-info.width-limit + span.glyphicon.glyphicon-info-sign + = ' ' + | {{"options_syncConflictAlert" | tr}} + p.help-block(omega-html='"options_syncConflictHelp" | tr') + p + button.btn.btn-danger(ng-click='enableOptionsSync({force: true})') + span.glyphicon.glyphicon-cloud-download + = ' ' + | {{'options_syncEnableForce' | tr}} + div(ng-show='syncOptions == "unsupported"') + p.help-block(omega-html='"options_syncUnsupportedHelp" | tr')