From df8a2aea358ca3bcec60c878a6399df46390e3e1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 24 Feb 2018 02:46:09 +0900 Subject: [PATCH] Implement #1098 --- src/api/endpoints.ts | 7 +- src/api/endpoints/i/update_home.ts | 11 +- src/api/endpoints/i/update_mobile_home.ts | 50 +++++ src/web/app/common/define-widget.ts | 26 ++- .../app/common/scripts/check-for-update.ts | 4 +- src/web/app/common/views/components/index.ts | 30 +++ .../views/components/widgets/access-log.vue | 70 +++---- .../views/components/widgets/broadcast.vue | 10 +- .../views/components/widgets/calendar.vue | 7 + .../views/components/widgets/donation.vue | 15 +- .../views/components/widgets/nav.vue | 12 +- .../views/components/widgets/photo-stream.vue | 104 +++++++++++ .../views/components/widgets/profile.vue | 0 .../common/views/components/widgets/rss.vue | 93 ++++++++++ .../components/widgets/server.cpu-memory.vue | 0 .../views/components/widgets/server.cpu.vue | 0 .../views/components/widgets/server.disk.vue | 0 .../views/components/widgets/server.info.vue | 0 .../components/widgets/server.memory.vue | 0 .../views/components/widgets/server.pie.vue | 0 .../components/widgets/server.uptimes.vue | 0 .../views/components/widgets/server.vue | 93 ++++++++++ .../views/components/widgets/slideshow.vue | 0 .../views/components/widgets/tips.vue | 0 .../views/components/widgets/version.vue | 0 src/web/app/desktop/views/components/index.ts | 32 +--- .../views/components/widget-container.vue | 72 ++++++++ .../views/components/widgets/photo-stream.vue | 122 ------------ .../desktop/views/components/widgets/rss.vue | 111 ----------- .../views/components/widgets/server.vue | 131 ------------- .../activity.vue} | 4 +- src/web/app/mobile/views/components/home.vue | 29 --- src/web/app/mobile/views/components/index.ts | 14 +- .../app/mobile/views/components/ui.header.vue | 4 +- src/web/app/mobile/views/components/ui.vue | 6 +- .../views/components/widget-container.vue | 65 +++++++ .../views/components/widgets/activity.vue | 23 +++ src/web/app/mobile/views/pages/drive.vue | 4 +- src/web/app/mobile/views/pages/home.vue | 174 +++++++++++++++++- .../app/mobile/views/pages/notifications.vue | 4 +- src/web/app/mobile/views/pages/user.vue | 1 - src/web/app/mobile/views/pages/user/home.vue | 6 +- 42 files changed, 823 insertions(+), 511 deletions(-) create mode 100644 src/api/endpoints/i/update_mobile_home.ts rename src/web/app/{desktop => common}/views/components/widgets/access-log.vue (61%) rename src/web/app/{desktop => common}/views/components/widgets/broadcast.vue (96%) rename src/web/app/{desktop => common}/views/components/widgets/calendar.vue (96%) rename src/web/app/{desktop => common}/views/components/widgets/donation.vue (79%) rename src/web/app/{desktop => common}/views/components/widgets/nav.vue (67%) create mode 100644 src/web/app/common/views/components/widgets/photo-stream.vue rename src/web/app/{desktop => common}/views/components/widgets/profile.vue (100%) create mode 100644 src/web/app/common/views/components/widgets/rss.vue rename src/web/app/{desktop => common}/views/components/widgets/server.cpu-memory.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.cpu.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.disk.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.info.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.memory.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.pie.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/server.uptimes.vue (100%) create mode 100644 src/web/app/common/views/components/widgets/server.vue rename src/web/app/{desktop => common}/views/components/widgets/slideshow.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/tips.vue (100%) rename src/web/app/{desktop => common}/views/components/widgets/version.vue (100%) create mode 100644 src/web/app/desktop/views/components/widget-container.vue delete mode 100644 src/web/app/desktop/views/components/widgets/photo-stream.vue delete mode 100644 src/web/app/desktop/views/components/widgets/rss.vue delete mode 100644 src/web/app/desktop/views/components/widgets/server.vue rename src/web/app/mobile/views/{pages/user/home.activity.vue => components/activity.vue} (96%) delete mode 100644 src/web/app/mobile/views/components/home.vue create mode 100644 src/web/app/mobile/views/components/widget-container.vue create mode 100644 src/web/app/mobile/views/components/widgets/activity.vue diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index ff214c300..cbc016f20 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -182,7 +182,12 @@ const endpoints: Endpoint[] = [ { name: 'i/update_home', withCredential: true, - kind: 'account-write' + secure: true + }, + { + name: 'i/update_mobile_home', + withCredential: true, + secure: true }, { name: 'i/change_password', diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts index 429e88529..5dfb7d791 100644 --- a/src/api/endpoints/i/update_home.ts +++ b/src/api/endpoints/i/update_home.ts @@ -4,16 +4,7 @@ import $ from 'cafy'; import User from '../../models/user'; -/** - * Update myself - * - * @param {any} params - * @param {any} user - * @param {any} _ - * @param {boolean} isSecure - * @return {Promise} - */ -module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => { +module.exports = async (params, user) => new Promise(async (res, rej) => { // Get 'home' parameter const [home, homeErr] = $(params.home).optional.array().each( $().strict.object() diff --git a/src/api/endpoints/i/update_mobile_home.ts b/src/api/endpoints/i/update_mobile_home.ts new file mode 100644 index 000000000..a87d89cad --- /dev/null +++ b/src/api/endpoints/i/update_mobile_home.ts @@ -0,0 +1,50 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import User from '../../models/user'; + +module.exports = async (params, user) => new Promise(async (res, rej) => { + // Get 'home' parameter + const [home, homeErr] = $(params.home).optional.array().each( + $().strict.object() + .have('name', $().string()) + .have('id', $().string()) + .have('data', $().object())).$; + if (homeErr) return rej('invalid home param'); + + // Get 'id' parameter + const [id, idErr] = $(params.id).optional.string().$; + if (idErr) return rej('invalid id param'); + + // Get 'data' parameter + const [data, dataErr] = $(params.data).optional.object().$; + if (dataErr) return rej('invalid data param'); + + if (home) { + await User.update(user._id, { + $set: { + 'client_settings.mobile_home': home + } + }); + + res(); + } else { + if (id == null && data == null) return rej('you need to set id and data params if home param unset'); + + const _home = user.client_settings.mobile_home || []; + const widget = _home.find(w => w.id == id); + + if (widget == null) return rej('widget not found'); + + widget.data = data; + + await User.update(user._id, { + $set: { + 'client_settings.mobile_home': _home + } + }); + + res(); + } +}); diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts index fd13a3395..60cd1969c 100644 --- a/src/web/app/common/define-widget.ts +++ b/src/web/app/common/define-widget.ts @@ -8,6 +8,10 @@ export default function(data: { props: { widget: { type: Object + }, + isMobile: { + type: Boolean, + default: false } }, computed: { @@ -21,6 +25,7 @@ export default function(data: { }; }, created() { + if (this.widget.data == null) this.widget.data = {}; if (this.props) { Object.keys(this.props).forEach(prop => { if (this.widget.data.hasOwnProperty(prop)) { @@ -30,12 +35,21 @@ export default function(data: { } this.$watch('props', newProps => { - (this as any).api('i/update_home', { - id: this.id, - data: newProps - }).then(() => { - (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps; - }); + if (this.isMobile) { + (this as any).api('i/update_mobile_home', { + id: this.id, + data: newProps + }).then(() => { + (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id).data = newProps; + }); + } else { + (this as any).api('i/update_home', { + id: this.id, + data: newProps + }).then(() => { + (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps; + }); + } }, { deep: true }); diff --git a/src/web/app/common/scripts/check-for-update.ts b/src/web/app/common/scripts/check-for-update.ts index 0855676a4..fe539407d 100644 --- a/src/web/app/common/scripts/check-for-update.ts +++ b/src/web/app/common/scripts/check-for-update.ts @@ -9,7 +9,9 @@ export default async function(mios: MiOS) { // Clear cache (serive worker) try { - navigator.serviceWorker.controller.postMessage('clear'); + if (navigator.serviceWorker.controller) { + navigator.serviceWorker.controller.postMessage('clear'); + } navigator.serviceWorker.getRegistrations().then(registrations => { registrations.forEach(registration => registration.unregister()); diff --git a/src/web/app/common/views/components/index.ts b/src/web/app/common/views/components/index.ts index ab0f1767d..e66a32326 100644 --- a/src/web/app/common/views/components/index.ts +++ b/src/web/app/common/views/components/index.ts @@ -21,6 +21,21 @@ import urlPreview from './url-preview.vue'; import twitterSetting from './twitter-setting.vue'; import fileTypeIcon from './file-type-icon.vue'; +//#region widgets +import wAccessLog from './widgets/access-log.vue'; +import wVersion from './widgets/version.vue'; +import wRss from './widgets/rss.vue'; +import wProfile from './widgets/profile.vue'; +import wServer from './widgets/server.vue'; +import wBroadcast from './widgets/broadcast.vue'; +import wCalendar from './widgets/calendar.vue'; +import wPhotoStream from './widgets/photo-stream.vue'; +import wSlideshow from './widgets/slideshow.vue'; +import wTips from './widgets/tips.vue'; +import wDonation from './widgets/donation.vue'; +import wNav from './widgets/nav.vue'; +//#endregion + Vue.component('mk-signin', signin); Vue.component('mk-signup', signup); Vue.component('mk-forkit', forkit); @@ -41,3 +56,18 @@ Vue.component('mk-messaging-room', messagingRoom); Vue.component('mk-url-preview', urlPreview); Vue.component('mk-twitter-setting', twitterSetting); Vue.component('mk-file-type-icon', fileTypeIcon); + +//#region widgets +Vue.component('mkw-nav', wNav); +Vue.component('mkw-calendar', wCalendar); +Vue.component('mkw-photo-stream', wPhotoStream); +Vue.component('mkw-slideshow', wSlideshow); +Vue.component('mkw-tips', wTips); +Vue.component('mkw-donation', wDonation); +Vue.component('mkw-broadcast', wBroadcast); +Vue.component('mkw-profile', wProfile); +Vue.component('mkw-server', wServer); +Vue.component('mkw-rss', wRss); +Vue.component('mkw-version', wVersion); +Vue.component('mkw-access-log', wAccessLog); +//#endregion diff --git a/src/web/app/desktop/views/components/widgets/access-log.vue b/src/web/app/common/views/components/widgets/access-log.vue similarity index 61% rename from src/web/app/desktop/views/components/widgets/access-log.vue rename to src/web/app/common/views/components/widgets/access-log.vue index a04da1daa..c810c2d15 100644 --- a/src/web/app/desktop/views/components/widgets/access-log.vue +++ b/src/web/app/common/views/components/widgets/access-log.vue @@ -1,15 +1,16 @@ @@ -65,44 +66,25 @@ export default define({ }); - diff --git a/src/web/app/desktop/views/components/widgets/broadcast.vue b/src/web/app/common/views/components/widgets/broadcast.vue similarity index 96% rename from src/web/app/desktop/views/components/widgets/broadcast.vue rename to src/web/app/common/views/components/widgets/broadcast.vue index e4b7e2532..0bb59caf4 100644 --- a/src/web/app/desktop/views/components/widgets/broadcast.vue +++ b/src/web/app/common/views/components/widgets/broadcast.vue @@ -1,5 +1,9 @@