Skip to content

Commit b660a31

Browse files
committed
Bug fixes
Cancel drag for sorting when selecting time. Increased to 5sec between periodical updates. Strike-through for completed list fixed. Clear Completed items added (will delete all completed items from DB). Removed html input when changed title. Login when hitting enter on password field fixed.
1 parent 4f9eb77 commit b660a31

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dev: prepare
1+
dev: clean prepare
22
cp -r doit/dist backend/dist
33
cd backend && go run . -tlscert server.crt -tlskey server.key -hostport 0.0.0.0:8443
44

backend/db.go

+9
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ func (d *DB) RemoveShareList(shareWith string, listId int, acc *Account) *Accoun
320320
return nil
321321
}
322322

323+
func (d *DB) DeleteCompleted(l *List, acc *Account) {
324+
list := &List{}
325+
d.db.First(&list, l.ID)
326+
327+
if d.HaveAccess(acc.ID, uint(list.ID)) {
328+
d.db.Unscoped().Where("list_id = ?", list.ID).Where("complete = true").Delete(&Item{})
329+
}
330+
}
331+
323332
func (d *DB) DeleteList(l *List, acc *Account) {
324333
list := &List{}
325334
d.db.Preload("Account").First(&list, l.ID)

backend/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ func main() {
354354
}
355355
})
356356

357+
api.POST("/deletecompleted", func(c *gin.Context) {
358+
if acc, ok := c.Get("account"); ok {
359+
list := List{}
360+
if c.BindJSON(&list) == nil {
361+
db.DeleteCompleted(&list, acc.(*Account))
362+
c.JSON(http.StatusOK, "")
363+
} else {
364+
c.JSON(http.StatusBadRequest, "")
365+
}
366+
} else {
367+
c.JSON(http.StatusUnauthorized, "")
368+
}
369+
})
370+
357371
api.POST("/deletelist", func(c *gin.Context) {
358372
if acc, ok := c.Get("account"); ok {
359373
list := List{}

frontend/src/App.vue

+6
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ body {
6161
color: #fff;
6262
font-size: 1.3rem;
6363
}
64+
#app .vdatetime-overlay {
65+
z-index: 1000;
66+
}
67+
#app .vdatetime-popup {
68+
z-index: 1001;
69+
}
6470
</style>

frontend/src/components/ToDoList.vue

+33-10
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<div class="pass-icon">
9393
<i class="fas fa-key"></i>
9494
</div>
95-
<form>
95+
<form @submit.prevent>
9696
<input v-on:keyup.enter="login()" type="password" placeholder="Password" v-model="password">
9797
</form>
9898
</div>
@@ -114,8 +114,8 @@
114114
<span class="list-menu-item" @click="selectList(item)">{{ item.Name }}<span v-if="item.ID == account.Favorite" class="fa fa-star fav-size"> </span></span>
115115
</a>
116116
</div>
117-
<md-button class="md-default md-raised" @click="logout()">Logout</md-button>
118117
<span style="font-size: 0.8rem;">Logged in as <span style="font-size: 0.8rem; color: #fff;">{{ account.User }}</span></span>
118+
<md-button class="md-default md-raised" @click="logout()">Logout</md-button>
119119
</Slide>
120120
<div v-if="nolists">
121121
<md-button class="md-primary md-raised" @click="newListActive = true">Create your first list</md-button>
@@ -164,8 +164,8 @@
164164
</div>
165165
<div>
166166
</div>
167-
<div class="todo-list list-list">
168-
<SlickList @sort-start="sortStart($event)" helperClass="drag-helper" :transitionDuration="0" :lockToContainerEdges="true" :pressDelay="350" @input="sortEnd" lockAxis="y" v-model="todoList">
167+
<div class="todo-list list-list" id="todolist">
168+
<SlickList :shouldCancelStart="cancelSort" @sort-start="sortStart($event)" helperClass="drag-helper" :transitionDuration="0" :lockToContainerEdges="true" :pressDelay="350" @input="sortEnd" lockAxis="y" v-model="todoList">
169169
<SlickItem v-on:dblclick.native="changeTitle(item)" :style="{height: item.itemSize+'px'}" :index="index" class="item" :class="{'show': item.show}" v-for="(item, index) in todoList" :key="item.ID">
170170
<div class="item-checkbox">
171171
<i v-if="!item.Complete" class="fas fa-square" @click="completeItem(item)"></i>
@@ -207,7 +207,7 @@
207207
<div class="show-completed" v-if="completedToDoList.length > 0">
208208
<div class="button" @click="showCompletedList = !showCompletedList">
209209
<span v-if="!showCompletedList">show</span><span v-else>hide</span>
210-
completed to-do's
210+
completed ({{ completedToDoList.length }})
211211
</div>
212212
</div>
213213
<div class="todo-list complete-list" v-if="showCompletedList">
@@ -246,6 +246,7 @@
246246
<md-button class="md-accent md-raised" @click="clearTime(item);">Clear</md-button>
247247
</div>
248248
</div>
249+
<md-button class="md-accent md-raised" @click="clearCompleted();">Clear Completed</md-button>
249250
</div>
250251
<div v-if="activelist != undefined && activelist != ''">
251252
<md-dialog-confirm
@@ -336,7 +337,7 @@ export default {
336337
if(that.loggedIn) {
337338
that.periodcalUpdate();
338339
}
339-
}, 2000);
340+
}, 5000);
340341
}
341342
} else {
342343
// Check if admin has been created.
@@ -519,7 +520,6 @@ export default {
519520
if (that.activelist.Share == null) {
520521
that.activelist.Share = [];
521522
}
522-
console.log(userData);
523523
if (userData != "") {
524524
that.activelist.Share.push(userData);
525525
}
@@ -528,6 +528,21 @@ export default {
528528
error: that.handleError
529529
});
530530
},
531+
// Clear completed items for list
532+
clearCompleted() {
533+
var that = this;
534+
$.ajax({
535+
type: "POST",
536+
url: "/api/deletecompleted",
537+
data: JSON.stringify(this.activelist),
538+
beforeSend: that.setHeader,
539+
success: function() {
540+
that.selectList(that.activelist);
541+
that.showCompletedList = false;
542+
},
543+
error: that.handleError
544+
});
545+
},
531546
// Delete the current list
532547
deleteList() {
533548
var that = this;
@@ -683,8 +698,16 @@ export default {
683698
});
684699
this.newListName = "";
685700
},
701+
// Dont allow dragging while having date selector up
702+
cancelSort() {
703+
if ($(".vdatetime-popup").length != 0) {
704+
return true;
705+
}
706+
return false;
707+
},
686708
// Sorting event for moving an item in the list
687709
sortStart() {
710+
// Do not trigger drag if we have date selector up
688711
let newCanvas = document.querySelector('.drag-helper')
689712
var text = newCanvas.innerText;
690713
newCanvas.innerHTML = "<div style="+
@@ -767,12 +790,12 @@ export default {
767790
$('#inp_'+item.ID).keyup(function(e){
768791
// Cancel
769792
if (e.keyCode == 27) {
770-
$('#'+item.ID).html(item.Title);
793+
$('#'+item.ID).text(item.Title);
771794
}
772795
// Save
773796
if(e.keyCode == 13) {
774797
item.Title = $('#inp_'+item.ID).val();
775-
$('#'+item.ID).html(item.Title);
798+
$('#'+item.ID).text(item.Title);
776799
that.saveItem(item);
777800
}
778801
});
@@ -1118,7 +1141,7 @@ export default {
11181141
&::before {
11191142
content: '';
11201143
position: absolute;
1121-
top: 30px;
1144+
top: 20px;
11221145
width: calc(100% - 120px);
11231146
margin: 0 40px;
11241147
border-bottom: 2px solid #555;

0 commit comments

Comments
 (0)