Skip to content

Commit 93bddba

Browse files
authored
Merge pull request #28 from SystemZ/issue-23
Make settings/new project button work
2 parents 6474835 + d687969 commit 93bddba

File tree

3 files changed

+81
-30
lines changed

3 files changed

+81
-30
lines changed

frontend/src/views/Settings.vue

+46-29
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,34 @@
122122
</v-btn>
123123
</v-card-actions>
124124
</v-card>
125-
</v-dialog>
125+
</v-dialog> -->
126126
<v-dialog
127-
v-model="addProject"
128-
width="500"
127+
v-model="showNewProjectDialog"
128+
width="600"
129129
:fullscreen="$vuetify.breakpoint.xsOnly"
130130
>
131131
<v-card>
132132
<v-card-title>
133-
Begin new project
133+
Start new project
134134
</v-card-title>
135135
<v-card-text>
136136
<v-container>
137137
<v-row>
138-
<v-col cols="12" sm="6" md="4">
139-
<v-text-field
140-
label="Project name"
138+
<v-col cols="12">
139+
<v-textarea
140+
auto-grow
141+
rows="1"
141142
required
142-
v-model="newProject"
143+
clearable
144+
counter
145+
maxlength="64"
146+
label="Project name"
147+
prepend-icon="mdi-folder-open"
148+
type="text"
149+
v-model="projectName"
143150
:color="inputPrimary"
144151
>
145-
</v-text-field>
152+
</v-textarea>
146153
</v-col>
147154
</v-row>
148155
</v-container>
@@ -153,20 +160,20 @@
153160
<v-btn
154161
:color="btnSecondary"
155162
text
156-
@click="addProject = false"
163+
@click="showNewProjectDialog = false"
157164
>
158165
Cancel
159166
</v-btn>
160167
<v-btn
161168
:dark="componentDark"
162169
:color="btnPrimary"
163-
@click="saveProject"
170+
@click="addProject"
164171
>
165172
Save
166173
</v-btn>
167174
</v-card-actions>
168175
</v-card>
169-
</v-dialog> -->
176+
</v-dialog>
170177

171178
<v-row>
172179
<v-col>
@@ -267,16 +274,14 @@
267274
<v-tab-item>
268275
<v-card flat>
269276
<v-card-text>
270-
<!-- if disabled then element cannot be dark -->
271-
<!-- :dark="componentDark" -->
272-
<!-- @click="showProjectDialog" -->
273277
<v-btn
274278
block
275279
class="mb-4"
276-
disabled
280+
:dark="componentDark"
277281
:color="btnPrimary"
282+
@click="showNewProjectDialog = true"
278283
>
279-
Add project
284+
Create new project
280285
</v-btn>
281286
<v-data-table
282287
:headers="projectHeaders"
@@ -311,14 +316,16 @@ export default {
311316
name: 'settings',
312317
data () {
313318
return {
319+
// pushing new info
314320
showNewAccountDialog: false,
315321
username: '',
316322
password: '',
317323
email: '',
318324
// addDevice: false,
319325
// newDevice: '',
320-
// addProject: false,
321-
// newProject: '',
326+
showNewProjectDialog: false,
327+
projectName: '',
328+
// getting table info
322329
tableLoading: true,
323330
accounts: [],
324331
accountHeaders: [
@@ -366,23 +373,13 @@ export default {
366373
// showDeviceDialog () {
367374
// this.addDevice = true
368375
// },
369-
// showProjectDialog () {
370-
// this.addProject = true
371-
// },
372376
// saveDevice () {
373377
// if (this.newDevice !== '') {
374378
// this.devices.push({'name': this.newDevice})
375379
// this.newDevice = ''
376380
// }
377381
// this.addDevice = false
378382
// },
379-
// saveProject () {
380-
// if (this.newProject !== '') {
381-
// this.projects.push({'title': this.newProject})
382-
// this.newProject = ''
383-
// }
384-
// this.addProject = false
385-
// },
386383
authConfig () {
387384
return {headers: {Authorization: 'Bearer ' + localStorage.getItem(this.lsToken)}}
388385
},
@@ -463,6 +460,26 @@ export default {
463460
}
464461
})
465462
},
463+
addProject () {
464+
axios.post(this.apiUrl + '/api/v1/project', {
465+
'name': this.projectName
466+
}, this.authConfig())
467+
.then((res) => {
468+
//clear form
469+
this.projectName = ''
470+
//close dialog
471+
this.showNewProjectDialog = false
472+
//get project list
473+
this.getProjects()
474+
})
475+
.catch((err) => {
476+
if (err.response.status === 401) {
477+
this.$root.$emit('sessionExpired')
478+
} else {
479+
console.log('something wrong')
480+
}
481+
})
482+
},
466483
}
467484
}
468485
</script>

internal/server/api_projects.go

+34-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package server
22

33
import (
44
"encoding/json"
5-
"github.com/systemz/hometab/internal/model"
65
"net/http"
6+
7+
"github.com/systemz/hometab/internal/model"
78
)
89

910
func ApiProjectList(w http.ResponseWriter, r *http.Request) {
@@ -42,3 +43,35 @@ func ApiProjectList(w http.ResponseWriter, r *http.Request) {
4243
w.Write(res)
4344

4445
}
46+
47+
type ApiNewProjectRequest struct {
48+
Name string `json:"name"`
49+
GroupId uint `json:"groupId"`
50+
}
51+
52+
func ApiNewProject(w http.ResponseWriter, r *http.Request) {
53+
// check auth
54+
ok, _ := CheckApiAuth(w, r)
55+
if !ok {
56+
w.WriteHeader(http.StatusUnauthorized)
57+
return
58+
}
59+
60+
// FIXME validate
61+
decoder := json.NewDecoder(r.Body)
62+
var newProject ApiNewProjectRequest
63+
decoder.Decode(&newProject)
64+
65+
// reject if project name is empty
66+
if len(newProject.Name) < 1 {
67+
w.WriteHeader(http.StatusBadRequest)
68+
return
69+
}
70+
71+
// create project, default group ID is 0
72+
model.CreateProject(newProject.Name, 0)
73+
74+
// all ok, return project
75+
w.WriteHeader(http.StatusOK)
76+
w.Write([]byte{})
77+
}

internal/server/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func StartWebInterface() {
7474
r.HandleFunc("/api/v1/user", ApiUserList).Methods("GET")
7575
r.HandleFunc("/api/v1/user", ApiNewUser).Methods("POST")
7676
r.HandleFunc("/api/v1/project", ApiProjectList).Methods("GET")
77+
r.HandleFunc("/api/v1/project", ApiNewProject).Methods("POST")
7778
r.HandleFunc("/api/v1/project/{id}/task", ApiTaskList).Methods("GET")
7879
r.HandleFunc("/api/v1/project/{id}/task", ApiTaskCreate).Methods("POST")
7980
r.HandleFunc("/api/v1/project/{id}/task", ApiTaskEdit).Methods("PUT")

0 commit comments

Comments
 (0)