blob: 892056855f1c5f878c2d363b2a98be445899e05a [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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 */
miriamed411d152018-01-02 15:35:55 +020016import {tabsMapping, actionTypes} from './OnboardConstants.js';
17import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
18import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
19import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
20import {catalogItemStatuses} from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
21import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
22import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030023
24const OnboardActionHelper = {
25 resetOnboardStore(dispatch) {
26 dispatch({
27 type: actionTypes.RESET_ONBOARD_STORE
28 });
29 },
30 changeActiveTab(dispatch, activeTab) {
31 this.clearSearchValue(dispatch);
32 dispatch({
33 type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB,
34 activeTab
35 });
36 },
37 changeSearchValue(dispatch, searchValue) {
38 dispatch({
39 type: actionTypes.CHANGE_SEARCH_VALUE,
40 searchValue
41 });
42 },
43 clearSearchValue(dispatch) {
44 dispatch({
45 type: actionTypes.CHANGE_SEARCH_VALUE,
46 searchValue: ''
47 });
miriamed411d152018-01-02 15:35:55 +020048 },
49
50 loadVLMScreen(dispatch, {id: licenseModelId, name}, users, tab) {
51 if (tab === tabsMapping.WORKSPACE) {
52 VersionsPageActionHelper.fetchVersions(dispatch, {itemId: licenseModelId, itemType: itemTypes.LICENSE_MODEL}).then(({results})=> {
53 results = results.filter((version) => version.status === catalogItemStatuses.DRAFT);
54 if (results.length !== 1) {
55 ScreensHelper.loadScreen(dispatch, {
56 screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL,
57 props: {licenseModelId, licenseModel: {name}, usersList: users}
58 });
59 }
60 else {
61 PermissionsActionHelper.fetchItemUsers(dispatch, {itemId: licenseModelId, allUsers: users}).then(() =>
62 ScreensHelper.loadLandingScreen(dispatch, {screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version: results[0]}})
63 );
64 }
65 });
66 }
67 if (tab === tabsMapping.CATALOG) {
68 ScreensHelper.loadScreen(dispatch, {
69 screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL,
70 props: {licenseModelId, licenseModel: {name}, usersList: users}
71 });
72 }
73 },
74 loadVSPScreen(dispatch, softwareProduct, users, tab) {
75 let {id: softwareProductId, vendorId: licenseModelId, licensingVersion, name} = softwareProduct;
76 if (tab === tabsMapping.WORKSPACE) {
77 VersionsPageActionHelper.fetchVersions(dispatch,{itemId: softwareProductId, itemType: itemTypes.SOFTWARE_PRODUCT}).then(({results})=> {
78 results = results.filter((version) => version.status === catalogItemStatuses.DRAFT);
79 if (results.length !== 1) {
80 ScreensHelper.loadScreen(dispatch, {
81 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
82 props: {
83 softwareProductId,
84 softwareProduct: {name, vendorId: licenseModelId, licensingVersion},
85 usersList: users
86 }
87 });
88 }
89 else {
90 PermissionsActionHelper.fetchItemUsers(dispatch, {itemId: softwareProductId, allUsers: users}).then(() =>
91 ScreensHelper.loadLandingScreen(dispatch, {screenType: screenTypes.SOFTWARE_PRODUCT, props: {softwareProductId, licenseModelId, version: results[0]}})
92 );
93 }
94 });
95 }
96 if (tab === tabsMapping.CATALOG) {
97 ScreensHelper.loadScreen(dispatch, {
98 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
99 props: {
100 softwareProductId,
101 softwareProduct: {name, vendorId: licenseModelId, licensingVersion},
102 usersList: users
103 }
104 });
105 }
AviZi280f8012017-06-09 02:39:56 +0300106 }
107};
108
109export default OnboardActionHelper;