blob: 4fd9082b5b12d4d49e26f8b58d06686450c2cecd [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17import i18n from 'nfvo-utils/i18n/i18n.js';
18import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
19import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
20import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
21
22import Configuration from 'sdc-app/config/Configuration.js';
23import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
24import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
25import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
26
27import {actionTypes} from './RevisionsConstants.js';
28
29function baseUrl(itemId, version) {
30 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`;
32}
33
34function fetchRevisions(itemId, version){
35 let fetchUrl = `${baseUrl(itemId, version)}/revisions`;
36 return RestAPIUtil.fetch(fetchUrl);
37}
38
39function revertToRevision(itemId, version, revisionId) {
40 let putUrl = `${baseUrl(itemId, version)}/actions`;
41 let requestBody = {
42 action: vcActionsEnum.REVERT,
43 revisionRequest: {
44 revisionId: revisionId
45 }
46 };
47 return RestAPIUtil.put(putUrl, requestBody);
48}
49
50const RevisionaActionHelper = {
51 openRevisionsView(dispatch, {itemId, version, itemType}) {
52 this.fetchRevisions(dispatch, {itemId, version}).then(() => {
53 dispatch({
54 type: modalActionTypes.GLOBAL_MODAL_SHOW,
55 data: {
56 modalComponentName: modalContentMapper.REVISIONS_LIST,
57 modalClassName: 'manage-revisions-modal',
58 title: i18n('Revert'),
59 modalComponentProps: {
60 itemId: itemId,
61 version: version,
62 itemType
63 }
64 }
65 });
66 });
67 },
68
69 closeRevisionsView(dispatch) {
70 dispatch({
71 type: modalActionTypes.GLOBAL_MODAL_CLOSE
72 });
73 },
74
75
76 fetchRevisions(dispatch, {itemId, version}) {
77 return fetchRevisions(itemId, version).then((response) => {
78 dispatch({
79 type: actionTypes.ITEM_REVISIONS_LOADED,
80 response: response
81 });
82 });
83 },
84
85 revertToRevision(dispatch, {itemId, version, revisionId, itemType}) {
86 return revertToRevision(itemId, version, revisionId).then(() => {
87 this.closeRevisionsView(dispatch);
88 if (itemType === screenTypes.LICENSE_MODEL) {
89 ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, screenType: screenTypes.LICENSE_MODEL,
90 props: {licenseModelId: itemId, version}});
91 } else {
92 ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
93 props: {softwareProductId: itemId, version}});
94 }
95 });
96
97 }
98};
99
100export default RevisionaActionHelper;