From 6991ed4fbc5cbb20c565ca5c5f489d6382b64e0a Mon Sep 17 00:00:00 2001 From: webdevstar Date: Mon, 15 Oct 2018 14:05:59 +0800 Subject: [PATCH] upload --- .../modules/apps/account/actionTypes.js | 17 +++ .../client/modules/apps/account/actions.js | 125 ++++++++++++++++++ .../client/modules/apps/account/reducer.js | 35 +++++ 3 files changed, 177 insertions(+) create mode 100755 src/admin/client/modules/apps/account/actionTypes.js create mode 100755 src/admin/client/modules/apps/account/actions.js create mode 100755 src/admin/client/modules/apps/account/reducer.js diff --git a/src/admin/client/modules/apps/account/actionTypes.js b/src/admin/client/modules/apps/account/actionTypes.js new file mode 100755 index 0000000..165fd59 --- /dev/null +++ b/src/admin/client/modules/apps/account/actionTypes.js @@ -0,0 +1,17 @@ +export const ACCOUNT_REQUEST = 'ACCOUNT_REQUEST'; +export const ACCOUNT_RECEIVE = 'ACCOUNT_RECEIVE'; + +export const SERVICES_REQUEST = 'SERVICES_REQUEST'; +export const SERVICES_RECEIVE = 'SERVICES_RECEIVE'; + +export const SERVICE_REQUEST = 'SERVICE_REQUEST'; +export const SERVICE_RECEIVE = 'SERVICE_RECEIVE'; + +export const SERVICE_ENABLE_REQUEST = 'SERVICE_ENABLE_REQUEST'; +export const SERVICE_ENABLE_RECEIVE = 'SERVICE_ENABLE_RECEIVE'; + +export const SERVICE_SETTINGS_REQUEST = 'SERVICE_SETTINGS_REQUEST'; +export const SERVICE_SETTINGS_RECEIVE = 'SERVICE_SETTINGS_RECEIVE'; + +export const SERVICE_LOGS_REQUEST = 'SERVICE_LOGS_REQUEST'; +export const SERVICE_LOGS_RECEIVE = 'SERVICE_LOGS_RECEIVE'; diff --git a/src/admin/client/modules/apps/account/actions.js b/src/admin/client/modules/apps/account/actions.js new file mode 100755 index 0000000..73f9d27 --- /dev/null +++ b/src/admin/client/modules/apps/account/actions.js @@ -0,0 +1,125 @@ +import * as t from './actionTypes'; +import api from 'lib/api'; +import messages from 'lib/text'; + +const receiveAccount = account => ({ + type: t.ACCOUNT_RECEIVE, + account +}); + +const receiveServices = services => ({ + type: t.SERVICES_RECEIVE, + services +}); + +const receiveService = service => ({ + type: t.SERVICE_RECEIVE, + service +}); + +const requestEnableDisableService = () => ({ + type: t.SERVICE_ENABLE_REQUEST +}); + +const receiveEnableDisableService = () => ({ + type: t.SERVICE_ENABLE_RECEIVE +}); + +const requestServiceSettings = () => ({ + type: t.SERVICE_SETTINGS_REQUEST +}); + +const receiveServiceSettings = serviceSettings => ({ + type: t.SERVICE_SETTINGS_RECEIVE, + serviceSettings +}); + +const receiveServiceLogs = serviceLogs => ({ + type: t.SERVICE_LOGS_RECEIVE, + serviceLogs +}); + +export const fetchAccount = () => (dispatch, getState) => { + return api.webstore.account.retrieve().then(({ status, json }) => { + dispatch(receiveAccount(json)); + }); +}; + +export const updateAccount = account => (dispatch, getState) => { + return api.webstore.account.update(account).then(({ status, json }) => { + dispatch(receiveAccount(json)); + }); +}; + +export const updateDeveloperAccount = account => (dispatch, getState) => { + return api.webstore.account + .updateDeveloper(account) + .then(({ status, json }) => { + dispatch(receiveAccount(json)); + }); +}; + +export const fetchServices = () => (dispatch, getState) => { + return api.webstore.services.list().then(({ status, json }) => { + dispatch(receiveServices(json)); + }); +}; + +export const fetchService = serviceId => (dispatch, getState) => { + return api.webstore.services.retrieve(serviceId).then(({ status, json }) => { + const service = json; + dispatch(receiveService(service)); + if (service.enabled) { + dispatch(fetchServiceSettings(serviceId)); + dispatch(fetchServiceLogs(serviceId)); + } + }); +}; + +export const enableService = serviceId => (dispatch, getState) => { + dispatch(requestEnableDisableService()); + return api.webstore.services.enable(serviceId).then(({ status, json }) => { + dispatch(receiveEnableDisableService()); + dispatch(fetchService(serviceId)); + }); +}; + +export const disableService = serviceId => (dispatch, getState) => { + dispatch(requestEnableDisableService()); + return api.webstore.services.disable(serviceId).then(({ status, json }) => { + dispatch(receiveEnableDisableService()); + dispatch(fetchService(serviceId)); + }); +}; + +export const fetchServiceSettings = serviceId => (dispatch, getState) => { + dispatch(requestServiceSettings()); + return api.webstore.services.settings + .retrieve(serviceId) + .then(({ status, json }) => { + const serviceSettings = json; + dispatch(receiveServiceSettings(serviceSettings)); + }) + .catch(error => {}); +}; + +export const updateServiceSettings = (serviceId, settings) => ( + dispatch, + getState +) => { + return api.webstore.services.settings + .update(serviceId, settings) + .then(({ status, json }) => { + dispatch(fetchServiceSettings(serviceId)); + }) + .catch(error => {}); +}; + +export const fetchServiceLogs = serviceId => (dispatch, getState) => { + return api.webstore.services.logs + .list(serviceId) + .then(({ status, json }) => { + dispatch(receiveServiceLogs(json)); + }) + .catch(error => {}); +}; diff --git a/src/admin/client/modules/apps/account/reducer.js b/src/admin/client/modules/apps/account/reducer.js new file mode 100755 index 0000000..f7213f3 --- /dev/null +++ b/src/admin/client/modules/apps/account/reducer.js @@ -0,0 +1,35 @@ +import * as t from './actionTypes'; + +const initialState = { + account: null, + services: [], + service: null, + serviceSettings: null, + serviceLogs: null, + loadingEnableDisableService: false +}; + +export default (state = initialState, action) => { + switch (action.type) { + case t.ACCOUNT_RECEIVE: + return Object.assign({}, state, { account: action.account }); + case t.SERVICES_RECEIVE: + return Object.assign({}, state, { services: action.services }); + case t.SERVICE_RECEIVE: + return Object.assign({}, state, { service: action.service }); + case t.SERVICE_SETTINGS_REQUEST: + return Object.assign({}, state, { serviceSettings: null }); + case t.SERVICE_SETTINGS_RECEIVE: + return Object.assign({}, state, { + serviceSettings: action.serviceSettings + }); + case t.SERVICE_LOGS_RECEIVE: + return Object.assign({}, state, { serviceLogs: action.serviceLogs }); + case t.SERVICE_ENABLE_REQUEST: + return Object.assign({}, state, { loadingEnableDisableService: true }); + case t.SERVICE_ENABLE_RECEIVE: + return Object.assign({}, state, { loadingEnableDisableService: false }); + default: + return state; + } +};