Bug 46 fixedgit status
[osm/UI.git] / skyquake / plugins / config / src / dashboard / configStore.js
1 /*
2 * STANDARD_RIFT_IO_COPYRIGHT
3 */
4 import AccountActions from './configActions.js';
5 import AccountSource from './configSource.js';
6
7 let tempData = {
8 "rw-launchpad:resource-orchestrator": {
9 "name": "test",
10 "account-type": "openmano",
11 "openmano": {
12 "port": 9090,
13 "tenant-id": "d2581f60-4f28-11e6-9732-fa163e4bfd3e",
14 "host": "10.0.55.39"
15 }
16 }
17 }
18
19 var rw = require('utils/rw.js');
20 var altImage = rw.getSearchParams(window.location).alt_image;
21
22 let Params = {
23 //Config Agent
24 ConfigAgent: {
25
26 }
27 }
28
29
30
31 let AccountMeta = {
32 'account-types': ['openmano', 'rift-ro'],
33 'rift-ro' : [],
34 'openmano' : [{
35 label: "Host",
36 ref: 'host'
37 }, {
38 label: "Port",
39 ref: 'port'
40 }, {
41 label: "Tenant ID",
42 ref: 'tenant-id'
43 }],
44 imageByType: {
45 "openmano": altImage || require("../../images/openmano.png"),
46 "rift-ro": require("../../images/riftio.png")
47
48 },
49 labelByType: {
50 "openmano": "OpenStack",
51 "rift-ro": "Cloudsim"
52 }
53 }
54
55 export default class AccountStore {
56 constructor() {
57 this.account = {};
58 this.accountType = 'openmano';
59 this.refreshingAll = false;
60 this.sdnOptions = [];
61 this.AccountMeta = AccountMeta;
62 this.bindActions(AccountActions(this.alt));
63 this.registerAsync(AccountSource);
64 this.exportPublicMethods({
65 getROAccount: this.getROAccount,
66 handleParamChange: this.handleParamChange,
67 handleNameChange: this.handleNameChange,
68 handleAccountTypeChange: this.handleAccountTypeChange,
69 updateAccount: this.updateAccount,
70 getImage: this.getImage
71 })
72 }
73 setAccountTemplate = (AccountType) => {
74 let state = {};
75 let account = {
76 name: '',
77 'account-type': AccountType || 'rift-ro',
78 };
79 account[AccountType || 'rift-ro'] = {};
80 state.account = account;
81 state.accountType = AccountType;
82 if (AccountType == this.initialAccountType) {
83 state.account = this.initialAccount;
84 }
85 this.setState(state)
86 }
87 updateAccount = (account) => {
88 this.setState({account:account})
89 }
90 getROAccount = () => {
91 let data = tempData["rw-launchpad:resource-orchestrator"]
92 this.setState({
93 account: data
94 })
95 }
96 handleNameChange = (event) => {
97 var account = this.account;
98 account.name = event.target.value;
99 this.setState(
100 {
101 account:account
102 }
103 );
104 }
105 handleAccountTypeChange = (event) => {
106 var accountType = event.target.value;
107 this.setAccountTemplate(accountType);
108 }
109 handleParamChange(node, event) {
110 return function(event) {
111 var account = this.state.account;
112 account[account['account-type']][node.ref] = event.target.value;
113 this.updateAccount(account);
114 }.bind(this);
115 }
116 getImage = (type) => {
117 return AccountMeta.imageByType[type];
118 }
119 getResourceOrchestratorSuccess = (data) => {
120 this.alt.actions.global.hideScreenLoader.defer();
121 if(!data) {
122 this.setAccountTemplate(false)
123 } else {
124 this.setState({
125 initialAccount: data,
126 initialAccountType: data['account-type'],
127 account: data,
128 accountType: data['account-type'] || 'rift-ro'
129 });
130 }
131 }
132 updateResourceOrchestratorSuccess = (data) => {
133 this.alt.actions.global.showNotification.defer({type:'success', msg: 'Resource Orchestrator has been succesfully updated'});
134 }
135 }