blob: e81c06812cd4de03943fee0ce0c4b319f870fa88 [file] [log] [blame]
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03001/*
2 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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 *
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03008 * http://www.apache.org/licenses/LICENSE-2.0
talig8e9c0652017-12-20 14:30:43 +02009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030012 * 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.
talig8e9c0652017-12-20 14:30:43 +020015 */
16
17import i18n from 'nfvo-utils/i18n/i18n.js';
18import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020019import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
20import { actionsEnum as vcActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
talig8e9c0652017-12-20 14:30:43 +020021
22import Configuration from 'sdc-app/config/Configuration.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
talig8e9c0652017-12-20 14:30:43 +020024import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
talig8e9c0652017-12-20 14:30:43 +020026
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027import { actionTypes } from './RevisionsConstants.js';
talig8e9c0652017-12-20 14:30:43 +020028
29function baseUrl(itemId, version) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`;
talig8e9c0652017-12-20 14:30:43 +020032}
33
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020034function fetchRevisions(itemId, version) {
35 let fetchUrl = `${baseUrl(itemId, version)}/revisions`;
36 return RestAPIUtil.fetch(fetchUrl);
talig8e9c0652017-12-20 14:30:43 +020037}
38
39function revertToRevision(itemId, version, revisionId) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 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);
talig8e9c0652017-12-20 14:30:43 +020048}
49
50const RevisionaActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020051 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,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020057 title: i18n('Revert'),
58 modalComponentProps: {
59 itemId: itemId,
60 version: version,
61 itemType
62 }
63 }
64 });
65 });
66 },
talig8e9c0652017-12-20 14:30:43 +020067
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 closeRevisionsView(dispatch) {
69 dispatch({
70 type: modalActionTypes.GLOBAL_MODAL_CLOSE
71 });
72 },
talig8e9c0652017-12-20 14:30:43 +020073
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020074 fetchRevisions(dispatch, { itemId, version }) {
75 return fetchRevisions(itemId, version).then(response => {
76 dispatch({
77 type: actionTypes.ITEM_REVISIONS_LOADED,
78 response: response
79 });
80 });
81 },
talig8e9c0652017-12-20 14:30:43 +020082
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020083 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 }
91 });
92 } else {
93 ScreensHelper.loadScreen(dispatch, {
94 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
95 screenType: screenTypes.SOFTWARE_PRODUCT,
96 props: { softwareProductId: itemId, version }
97 });
98 }
99 });
100 }
talig8e9c0652017-12-20 14:30:43 +0200101};
102
103export default RevisionaActionHelper;