added notifications
This commit is contained in:
parent
a6cc40e7d2
commit
70a43528d0
2
db/db.go
2
db/db.go
|
@ -62,7 +62,7 @@ func GetTasks(status string) types.Context {
|
|||
return context
|
||||
}
|
||||
|
||||
//GetTaskByID function gets the tasks from the ID passed to the function
|
||||
//GetTaskByID function gets the tasks from the ID passed to the function, used to populate EditTask
|
||||
func GetTaskByID(id int) types.Context {
|
||||
var tasks []types.Task
|
||||
var task types.Task
|
||||
|
|
|
@ -44,8 +44,31 @@ textarea {
|
|||
border-radius: 35px;
|
||||
box-shadow:0 0 4px #111;
|
||||
padding-top:10px !important;
|
||||
}
|
||||
|
||||
.notification{
|
||||
width: -moz-fit-content;
|
||||
position: fixed;
|
||||
right: 10px;
|
||||
max-width: 400px;
|
||||
padding: 12px;
|
||||
background-color: #FFF;
|
||||
box-shadow: 1px 0px 9px 0px rgba(252, 103, 22, 0.4);
|
||||
border: 1px solid #DEB3A8;
|
||||
border-radius: 10px;
|
||||
z-index: 1100;
|
||||
max-height: 90px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.notification-close{
|
||||
background-color: #2037B3;
|
||||
border-radius: 40px;
|
||||
border:none;
|
||||
color: #FFF;
|
||||
align-content: center;
|
||||
position: fixed;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
/*--------------------------------------
|
||||
|
|
|
@ -18,21 +18,16 @@ $(document).ready(function(){
|
|||
// alert();
|
||||
// });
|
||||
|
||||
$('#addNote').click(function(){
|
||||
$('#addNoteModal').modal('show');
|
||||
});
|
||||
|
||||
$('.floating-action-icon-add').click(function(){
|
||||
$('#addNoteModal').modal('show');
|
||||
});
|
||||
|
||||
//$(document).on("click", '.note-close',closeDelete); //when you delete a note, the x on the top right corner
|
||||
|
||||
$(document).on('click','.open-note', openNote); //when you want to open a note in full screen, the second icon on the bottom right corner from the right
|
||||
|
||||
//$(document).on('click','.hashtag', hashTag); //function to handle search by hashtag *TODO*
|
||||
|
||||
//$('#addNoteModalSaveBtn').click(addNoteToDOM); //Adds note to the DOM
|
||||
if ($('#message').html()==''){
|
||||
$('.notification').addClass('hidden');
|
||||
} else {
|
||||
$('.notification').fadeOut(9000);
|
||||
}
|
||||
$('.notification-close').click(function(){$('.notification').fadeOut("slow")})
|
||||
|
||||
/*$( document ).keypress(
|
||||
function(event){
|
||||
|
@ -47,44 +42,3 @@ $(document).ready(function(){
|
|||
);*/
|
||||
|
||||
});
|
||||
|
||||
function addNoteToDOM(){
|
||||
var title = $('#add-note-title').val();
|
||||
var content = $('#add-note-content').val();
|
||||
if (title!="" || content!=""){
|
||||
var note=$('<div class="col-md-4 col-sm-4 "><div class="panel note-sm"><div class="panel-heading" >'+title +'<button class="close note-close" > ×</button></div><hr style="margin:0 0 3px;"><div class="panel-body">'+content+' </div></div></div>');
|
||||
$('.col-md-12.row').prepend(note);
|
||||
$('#addNoteModal').modal('hide');
|
||||
$('#add-note-title').val("");
|
||||
$('#add-note-content').val("");
|
||||
}
|
||||
else{
|
||||
alert("Empty note can't be saved!");
|
||||
}
|
||||
}
|
||||
|
||||
function closeDelete(){
|
||||
var note = $(this).parent().parent().parent();
|
||||
note.fadeOut('slow');
|
||||
note.remove();
|
||||
|
||||
}
|
||||
|
||||
function openNote(){
|
||||
var element = $(this);
|
||||
var cont=element.parent().parent().siblings().contents().toArray();
|
||||
var note_body =cont[2].data;
|
||||
console.log(note_body);
|
||||
var note_title = cont[0].data;
|
||||
console.log(note_title);
|
||||
|
||||
|
||||
var ONmodal = $('#openNoteModal');
|
||||
ONmodal.find('.modal-title').text(note_title);
|
||||
ONmodal.find('.modal-body').text(note_body);
|
||||
ONmodal.modal('show');
|
||||
}
|
||||
|
||||
function hashTag(){
|
||||
alert($(this).html());
|
||||
}
|
||||
|
|
|
@ -13,4 +13,5 @@ type Context struct {
|
|||
Tasks []Task
|
||||
Navigation string
|
||||
Search string
|
||||
Message string
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ var completedTemplate *template.Template
|
|||
var editTemplate *template.Template
|
||||
var searchTemplate *template.Template
|
||||
var templates *template.Template
|
||||
var message string //message will store the message to be shown as notification
|
||||
var err error
|
||||
|
||||
//PopulateTemplates is used to parse all templates present in
|
||||
|
@ -38,6 +39,7 @@ func PopulateTemplates() {
|
|||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
templates, err = template.ParseFiles(allFiles...)
|
||||
if err != nil {
|
||||
|
@ -58,7 +60,14 @@ func PopulateTemplates() {
|
|||
func ShowAllTasksFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
context := db.GetTasks("pending") //true when you want non deleted notes
|
||||
if message != "" {
|
||||
context.Message = message
|
||||
}
|
||||
homeTemplate.Execute(w, context)
|
||||
message = ""
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +75,14 @@ func ShowAllTasksFunc(w http.ResponseWriter, r *http.Request) {
|
|||
func ShowTrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
context := db.GetTasks("deleted") //false when you want deleted notes
|
||||
if message != "" {
|
||||
context.Message = message
|
||||
message = ""
|
||||
}
|
||||
deletedTemplate.Execute(w, context)
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +94,7 @@ func SearchTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
context := db.SearchTask(query)
|
||||
searchTemplate.Execute(w, context)
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
|
||||
|
@ -91,11 +108,13 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
content := r.Form.Get("content")
|
||||
truth := db.AddTask(title, content)
|
||||
if truth != nil {
|
||||
fmt.Println(err)
|
||||
message = "Error adding task"
|
||||
} else {
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
message = "Task added"
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +125,7 @@ func ShowCompleteTasksFunc(w http.ResponseWriter, r *http.Request) {
|
|||
context := db.GetTasks("completed") //false when you want finished notes
|
||||
completedTemplate.Execute(w, context)
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +141,7 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
editTemplate.Execute(w, task)
|
||||
}
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
@ -132,18 +153,21 @@ func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
err := db.CompleteTask(id)
|
||||
err = db.CompleteTask(id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
message = "Complete task failed"
|
||||
} else {
|
||||
message = "Task marked complete"
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
//DeleteTaskFunc is used to
|
||||
//DeleteTaskFunc is used to delete a task, trash = move to recycle bin, delete = permanent delete
|
||||
func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
id := r.URL.Path[len("/delete/"):]
|
||||
|
@ -157,17 +181,20 @@ func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
err = db.DeleteTask(id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
message = "Error deleting task"
|
||||
} else {
|
||||
message = "Task deleted"
|
||||
}
|
||||
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
//TrashTaskFunc is used to populate the "/trash/" URL
|
||||
//TrashTaskFunc is used to populate the trash tasks
|
||||
func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
id, err := strconv.Atoi(r.URL.Path[len("/trash/"):])
|
||||
|
@ -176,12 +203,15 @@ func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
err = db.TrashTask(id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
message = "Error trashing task"
|
||||
} else {
|
||||
message = "Task trashed"
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
} else {
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/trash", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,10 +222,16 @@ func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
db.RestoreTask(id)
|
||||
err = db.RestoreTask(id)
|
||||
if err != nil {
|
||||
message = "Restore failed"
|
||||
} else {
|
||||
message = "Task restored"
|
||||
}
|
||||
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
||||
}
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
@ -212,10 +248,14 @@ func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
|
|||
content := r.Form.Get("content")
|
||||
err = db.UpdateTask(id, title, content)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
message = "Error updating task"
|
||||
} else {
|
||||
message = "Task updated"
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue