diff --git a/handlers/handlers.go b/handlers/handlers.go index 5f62e1e..3228cdc 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -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 } diff --git a/models/category.go b/models/category.go index e5e8102..021d1f5 100644 --- a/models/category.go +++ b/models/category.go @@ -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 { diff --git a/routers/routers.go b/routers/routers.go index 96733ae..80db00d 100644 --- a/routers/routers.go +++ b/routers/routers.go @@ -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) diff --git a/static/js/base.js b/static/js/base.js index 2143555..2cd073f 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -1,3 +1,5 @@ +"use strict"; + $(function() { // http://stepansuvorov.com/blog/2014/04/jquery-put-and-delete/ jQuery.each( [ "put", "delete" ], function( i, method ) { diff --git a/static/js/notes.js b/static/js/notes.js index f3d1d38..b4d59c4 100644 --- a/static/js/notes.js +++ b/static/js/notes.js @@ -1,3 +1,5 @@ +"use strict"; + var USERS_BY_ID = {}; const $createAuthor = function(authorId) { @@ -6,8 +8,12 @@ const $createAuthor = function(authorId) { return $('', {text: user.displayName}); }; -const $createType = function(type) { - return $('', {text: type}); +const $createType = function(noteId) { + let spandId = noteId+"_category"; + $.get('/api/category?id='+noteId, function(responseObj) { + $("#"+spandId).text(responseObj.category); + }); + return $('', {text: ' - '}); }; const $createCreationTime = function(creationTime) { @@ -24,11 +30,13 @@ const $createDivider = function() { const $createNote = function(noteId, note) { const $author = $createAuthor(note.authorId); - const $type = $createType(note.type); + const $noteId = $('', {text : noteId}) + const $type = $createType(noteId); const $creationTime = $createCreationTime(note.creationTime); const $content = $createContent(note.content); const $header = $('
').addClass('note-header') + .append($noteId).append($createDivider()) .append($author).append($createDivider()) .append($type).append($createDivider()) .append($creationTime);