Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,26 @@ func HandleCategoryApiRequest(
id, err := strconv.ParseInt(request.URL.Query().Get("id"), 10, 64)
noteId := models.NoteId(id)

var categoryString string

category, err := env.Db.GetNoteCategory(noteId)
if err != nil {
return err, http.StatusInternalServerError
if err == models.QueryResultContainedNoRowsError {
// you are trying to a a non set category return the empty string
categoryString = ""

} else {
return err, http.StatusInternalServerError
}
} else {
categoryString = category.String()
}

type categoryObj struct {
Category string `json:"category"`
}

jsonValue, err := json.Marshal(&categoryObj{Category: category.String()})
jsonValue, err := json.Marshal(&categoryObj{Category: categoryString})
if err != nil {
return err, http.StatusInternalServerError
}
Expand Down
2 changes: 1 addition & 1 deletion models/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func DeserializeCategory(input string) (Category, error) {
return Category(i), nil
}
}
return MARGINALIA, CannotDeserializeCategoryStringError
return 0, CannotDeserializeCategoryStringError
}

func (category Category) String() string {
Expand Down
1 change: 0 additions & 1 deletion routers/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func DefineRoutes(env *handlers.Environment) http.Handler {
mux.handleAuthenticatedPage(env, paths.NotesPage, handlers.HandleNotesPageRequest)

// api

mux.handleUnAutheticedRequest(env, paths.UserApi, handlers.HandleUserApiRequest)
mux.handleUnAutheticedRequest(env, paths.SessionApi, handlers.HandleSessionApiRequest)

Expand Down
2 changes: 2 additions & 0 deletions static/js/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

$(function() {
// http://stepansuvorov.com/blog/2014/04/jquery-put-and-delete/
jQuery.each( [ "put", "delete" ], function( i, method ) {
Expand Down
14 changes: 11 additions & 3 deletions static/js/notes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var USERS_BY_ID = {};

const $createAuthor = function(authorId) {
Expand All @@ -6,8 +8,12 @@ const $createAuthor = function(authorId) {
return $('<span>', {text: user.displayName});
};

const $createType = function(type) {
return $('<span>', {text: type});
const $createType = function(noteId) {
let spandId = noteId+"_category";
$.get('/api/category?id='+noteId, function(responseObj) {
$("#"+spandId).text(responseObj.category);
});
return $('<span id="'+spandId+'">', {text: ' - '});
};

const $createCreationTime = function(creationTime) {
Expand All @@ -24,11 +30,13 @@ const $createDivider = function() {

const $createNote = function(noteId, note) {
const $author = $createAuthor(note.authorId);
const $type = $createType(note.type);
const $noteId = $('<span>', {text : noteId})
const $type = $createType(noteId);
const $creationTime = $createCreationTime(note.creationTime);
const $content = $createContent(note.content);

const $header = $('<div>').addClass('note-header')
.append($noteId).append($createDivider())
.append($author).append($createDivider())
.append($type).append($createDivider())
.append($creationTime);
Expand Down