@@ -7,7 +7,6 @@ import "./HomePage.css";
77import ServiceTable from "./ServiceTable" ;
88import NavBar from "./NavBar" ;
99import { Loader , Modal , Form } from "semantic-ui-react" ;
10- import $ from "jquery" ;
1110
1211class HomePage extends React . Component {
1312 constructor ( props ) {
@@ -16,9 +15,23 @@ class HomePage extends React.Component {
1615 this . state = {
1716 selectedService : "azure" ,
1817 user : "" ,
19- showModal : false
18+ showModal : false ,
19+ showSideBar : true ,
20+ selectedDashboardService : "" ,
21+ virtualMachine : {
22+ resourceGroupName : "" ,
23+ vmName : "" ,
24+ location : ""
25+ }
2026 } ;
27+
28+ this . handleChange = this . handleChange . bind ( this ) ;
29+ this . handleServiceCreate = this . handleServiceCreate . bind ( this ) ;
30+ this . changeSelectedDashboardService = this . changeSelectedDashboardService . bind (
31+ this
32+ ) ;
2133 }
34+
2235 openModal ( ) {
2336 this . setState ( { showModal : true } ) ;
2437 }
@@ -48,11 +61,53 @@ class HomePage extends React.Component {
4861 } ) ;
4962 }
5063
64+ handleServiceCreate ( event ) {
65+ event . preventDefault ( ) ;
66+ const { virtualMachine } = this . state ;
67+ this . props . dispatch ( userActions . createVM ( virtualMachine ) ) ;
68+ this . setState ( { showModal : false } ) ;
69+ }
70+
71+ handleChange ( event ) {
72+ const { name, value } = event . target ;
73+ const { virtualMachine } = this . state ;
74+ this . setState ( {
75+ virtualMachine : {
76+ ...virtualMachine ,
77+ [ name ] : value
78+ }
79+ } ) ;
80+ }
81+
82+ handleDeleteService ( name ) {
83+ this . props . dispatch ( userActions . delete ( name ) ) ;
84+ }
85+
86+ handleShowSideBar ( ) {
87+ this . setState ( {
88+ showSideBar : ! this . state . showSideBar
89+ } ) ;
90+ }
91+
92+ changeSelectedDashboardService ( serviceName ) {
93+ this . setState ( {
94+ selectedDashboardService : serviceName
95+ } ) ;
96+ }
97+
5198 render ( ) {
52- const { selectedService, showModal } = this . state ;
99+ const {
100+ selectedService,
101+ showModal,
102+ virtualMachine,
103+ showSideBar
104+ } = this . state ;
53105 return (
54106 < div >
55- < NavBar handleCreateModal = { ( ) => this . handleCreateModal ( ) } />
107+ < NavBar
108+ handleCreateModal = { ( ) => this . handleCreateModal ( ) }
109+ handleShowSideBar = { ( ) => this . handleShowSideBar ( ) }
110+ />
56111 < div style = { { margin : 20 } } >
57112 < Modal open = { showModal } id = "test" >
58113 < i class = "close icon" onClick = { ( ) => this . closeModal ( ) } />
@@ -67,26 +122,75 @@ class HomePage extends React.Component {
67122 < Form >
68123 < Form . Input
69124 fluid
125+ name = "resourceGroupName"
70126 label = "Resource group"
71127 placeholder = "Resource group"
128+ onChange = { this . handleChange }
72129 />
73130 < Form . Input
74131 fluid
132+ name = "vmName"
75133 label = "Virtual machine name"
76134 placeholder = "Virtual machine name"
135+ onChange = { this . handleChange }
136+ />
137+ < Form . Input
138+ fluid
139+ name = "location"
140+ label = "Region"
141+ placeholder = "Region"
142+ onChange = { this . handleChange }
77143 />
78- < Form . Input fluid label = "Region" placeholder = "Region" />
79144 </ Form >
80145 </ div >
81146 </ div >
82147 < div class = "actions" >
83- < div class = "ui positive right labeled icon button" >
148+ < div
149+ class = "ui positive right labeled icon button"
150+ onClick = { this . handleServiceCreate }
151+ >
84152 Create Service
85153 < i class = "checkmark icon" />
86154 </ div >
87155 </ div >
88156 </ Modal >
89157
158+ { showSideBar && (
159+ < div
160+ class = "ui sidebar vertical left menu overlay visible"
161+ display = "none"
162+ >
163+ < div class = "ui accordion" >
164+ < a class = "item" >
165+ < b > Home</ b >
166+ </ a >
167+ < a
168+ class = "item"
169+ onClick = { ( ) =>
170+ this . changeSelectedDashboardService ( "virtualMachines" )
171+ }
172+ >
173+ Virtual Machines
174+ </ a >
175+ < a
176+ class = "item"
177+ onClick = { ( ) =>
178+ this . changeSelectedDashboardService ( "virtualNetworks" )
179+ }
180+ >
181+ Virtual Networks
182+ </ a >
183+ < a
184+ class = "item"
185+ onClick = { ( ) =>
186+ this . changeSelectedDashboardService ( "loadBalancers" )
187+ }
188+ >
189+ Load Balancers
190+ </ a >
191+ </ div >
192+ </ div >
193+ ) }
90194 < div class = "ui center aligned page grid" />
91195 < div class = "ui center aligned page grid" style = { { marginTop : 50 } } >
92196 < div
@@ -163,7 +267,10 @@ class HomePage extends React.Component {
163267 </ Loader >
164268 ) }
165269 { ! this . props . users . loading && (
166- < ServiceTable service = { this . props . users . items } />
270+ < ServiceTable
271+ service = { this . props . users . items }
272+ handleDeleteService = { name => this . handleDeleteService ( name ) }
273+ />
167274 ) }
168275 </ div >
169276 </ div >
0 commit comments