2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
19 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
20 import { actionsEnum as vcActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
23 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
24 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
25 import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
27 import { actionTypes } from './RevisionsConstants.js';
29 function baseUrl(itemId, version) {
30 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`;
34 function fetchRevisions(itemId, version) {
35 let fetchUrl = `${baseUrl(itemId, version)}/revisions`;
36 return RestAPIUtil.fetch(fetchUrl);
39 function revertToRevision(itemId, version, revisionId) {
40 let putUrl = `${baseUrl(itemId, version)}/actions`;
42 action: vcActionsEnum.REVERT,
44 revisionId: revisionId
47 return RestAPIUtil.put(putUrl, requestBody);
50 const RevisionaActionHelper = {
51 openRevisionsView(dispatch, { itemId, version, itemType }) {
52 this.fetchRevisions(dispatch, { itemId, version }).then(() => {
54 type: modalActionTypes.GLOBAL_MODAL_SHOW,
56 modalComponentName: modalContentMapper.REVISIONS_LIST,
57 title: i18n('Revert'),
58 modalComponentProps: {
68 closeRevisionsView(dispatch) {
70 type: modalActionTypes.GLOBAL_MODAL_CLOSE
74 fetchRevisions(dispatch, { itemId, version }) {
75 return fetchRevisions(itemId, version).then(response => {
77 type: actionTypes.ITEM_REVISIONS_LOADED,
83 revertToRevision(dispatch, { itemId, version, revisionId, itemType }) {
84 return revertToRevision(itemId, version, revisionId).then(() => {
85 this.closeRevisionsView(dispatch);
86 if (itemType === screenTypes.LICENSE_MODEL) {
87 ScreensHelper.loadScreen(dispatch, {
88 screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
89 screenType: screenTypes.LICENSE_MODEL,
90 props: { licenseModelId: itemId, version }
93 ScreensHelper.loadScreen(dispatch, {
94 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
95 screenType: screenTypes.SOFTWARE_PRODUCT,
96 props: { softwareProductId: itemId, version }
103 export default RevisionaActionHelper;