diff options
author | talig <talig@amdocs.com> | 2017-12-20 14:30:43 +0200 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-12-21 11:12:33 +0000 |
commit | 8e9c0653dd6c6862123c9609ae34e1206d86456e (patch) | |
tree | 5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js | |
parent | 785ebcc95de3e064e843bec04ba7a209d854fc7c (diff) |
Add collaboration feature
Issue-ID: SDC-767
Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js')
-rw-r--r-- | openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js new file mode 100644 index 0000000000..574aa0f3fc --- /dev/null +++ b/openecomp-ui/src/sdc-app/onboarding/userNotifications/UserNotificationsActionHelper.js @@ -0,0 +1,123 @@ +import {actionTypes} from './UserNotificationsConstants.js'; +import i18n from 'nfvo-utils/i18n/i18n.js'; +import Configuration from 'sdc-app/config/Configuration.js'; +import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js'; +import WebSocketUtil, {websocketUrl} from 'nfvo-utils/WebSocketUtil.js'; +import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; +import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js'; +import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; +import MergeEditorActionHelper from 'sdc-app/common/merge/MergeEditorActionHelper.js'; +import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; +import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js'; + +function baseUrl() { + const restPrefix = Configuration.get('restPrefix'); + return `${restPrefix}/v1.0/notifications`; +} + +function fetch() { + return RestAPIUtil.fetch(baseUrl()); +} + +function updateNotification(notificationId) { + return RestAPIUtil.put(`${baseUrl()}/${notificationId}`); +} + +function updateLastSeenNotification(notificationId) { + return RestAPIUtil.put(`${baseUrl()}/last-seen/${notificationId}`); +} + +function loadPrevNotifications(lastScanned, endOfPage) { + return RestAPIUtil.fetch(`${baseUrl()}?LAST_DELIVERED_EVENT_ID=${lastScanned}&END_OF_PAGE_EVENT_ID=${endOfPage}`); +} + +const INITIAL_LAST_SCANNED = '00000000-0000-1000-8080-808080808080'; + +const UserNotificationsActionHelper = { + notificationsFirstHandling(dispatch) { + console.log('Websocket Url: ', websocketUrl); + UserNotificationsActionHelper.fetchUserNotificationsList(dispatch).then(({lastScanned}) => { + WebSocketUtil.open(websocketUrl, {lastScanned: lastScanned || INITIAL_LAST_SCANNED}); + }); + }, + + fetchUserNotificationsList(dispatch) { + return fetch().then(result => { + dispatch({ + type: actionTypes.LOAD_NOTIFICATIONS, + result + }); + return Promise.resolve({lastScanned: result.lastScanned}); + }); + }, + + loadPreviousNotifications(dispatch, {lastScanned, endOfPage}) { + loadPrevNotifications(lastScanned, endOfPage).then(result => dispatch({ + type: actionTypes.LOAD_PREV_NOTIFICATIONS, + result + })); + }, + + notifyAboutConflicts(dispatch, {itemId, itemName, version, currentScreen}) { + let {props} = currentScreen; + let currentItemId = props.softwareProductId || props.licenseModelId; + let currentVersion = props.version; + if(currentItemId === itemId && currentVersion.id === version.id) { + MergeEditorActionHelper.analyzeSyncResult(dispatch, {itemId, version}).then(() => ScreensHelper.loadScreen(dispatch, currentScreen)); + } + else { + dispatch({ + type: modalActionTypes.GLOBAL_MODAL_WARNING, + data: { + title: i18n('Conflicts'), + msg: i18n('There are conflicts in {itemName} version {versionName} that you have to resolve', {itemName: itemName.toUpperCase(), versionName: version.versionName}), + cancelButtonText: i18n('OK') + } + }); + } + }, + + syncItem(dispatch, {itemId, itemName, versionId, versionName, currentScreen}) { + let version = {id: versionId, versionName}; + ItemsHelper.fetchVersion({itemId, versionId}).then(response => { + let inMerge = response && response.state && response.state.synchronizationState === SyncStates.MERGE; + if (!inMerge) { + ItemsHelper.performVCAction({itemId, version, action: VersionControllerActionsEnum.SYNC}).then(() => { + return ItemsHelper.fetchVersion({itemId, versionId}).then(response => { + let inMerge = response && response.state && response.state.synchronizationState === SyncStates.MERGE; + if (!inMerge) { + return ScreensHelper.loadScreen(dispatch, currentScreen); + } + else { + return this.notifyAboutConflicts(dispatch, {itemId, itemName, version, currentScreen}); + } + }); + }); + } + else { + this.notifyAboutConflicts(dispatch, {itemId, itemName, version, currentScreen}); + } + }); + }, + + updateNotification(dispatch, {notificationForUpdate}) { + updateNotification(notificationForUpdate.eventId).then(response => { + if(response.status === 'Success' && Object.keys(response.errors).length === 0) { + dispatch({ + type: actionTypes.UPDATE_READ_NOTIFICATION, + notificationForUpdate + }); + } + }); + }, + + updateLastSeenNotification(dispatch, {notificationId}) { + updateLastSeenNotification(notificationId).then(response => { + if (response.status === 'Success' && Object.keys(response.errors).length === 0) { + dispatch({type: actionTypes.RESET_NEW_NOTIFICATIONS}); + } + }); + } +}; + +export default UserNotificationsActionHelper; |