Deleting Google Glass Timeline Items Using the Go Quick Start Project

(Note: This has been merged into the main project!)

A Google Glass user interacts with Glassware using timeline items, also known as cards. Currently the Quick Start Projects do not include a method for manually deleting these items, but the Mirror API does provide a way to do this.

I am developing Glassware using the Go (AKA golang) version of the Quick Start Project.

In the index.html file, I added a button using this block of code:

<form action="/" method="post">
<input name="itemId" type="hidden" value="{{ $item.Id }}" />
<input name="operation" type="hidden" value="deleteTimelineItem" />
<button class="btn" type="submit">Delete Item</button>
</form>

To this block:

          {{ range $item.Attachments }}
            {{ if HasPrefix .ContentType "image" }}
            <img src="/attachmentproxy?attachment={{ .Id }}&timelineItem={{ $item.Id }}" width="150" />
            {{ else }}
            <a href="/attachmentproxy?attachment={{ .Id }}&timelineItem={{ $item.Id }}">Download</a>
            {{ end }}
          {{ end }}
        
      
      {{ end }}
    
    <div style="clear:both;"></div>

Resulting in this block:

          {{ range $item.Attachments }}
            {{ if HasPrefix .ContentType "image" }}
            <img src="/attachmentproxy?attachment={{ .Id }}&timelineItem={{ $item.Id }}" width="150" />
            {{ else }}
            <a href="/attachmentproxy?attachment={{ .Id }}&timelineItem={{ $item.Id }}">Download</a>
            {{ end }}
          {{ end }}
        </li>
        <li>
           <form action="/" method="post">
              <input type="hidden" name="itemId" value="{{ $item.Id }}" />
              <input type="hidden" name="operation" value="deleteTimelineItem" />
              <button class="btn" type="submit">Delete Item</button>
           </form>
        </li>
      </ul>
      {{ end }}
    </div>
    <div style="clear:both;"></div>
  </div>

Secondly, add this method to the main.go file:

// deleteTimelineItem deletes a timeline item.
func deleteTimelineItem(r *http.Request, svc *mirror.Service) string {
        itemId := r.FormValue("itemId")
		err := svc.Timeline.Delete(itemId).Do()
        if err != nil {
                return fmt.Sprintf("An error occurred: %vn", err)
        }
        return "A timeline item has been deleted."
}

Lastly, add the last line to the block defining the operations variable in main.go, adding the deleteTimelineItem method:

// Map of operations to functions.
var operations = map[string]func(*http.Request, *mirror.Service) string{
	"insertSubscription":   insertSubscription,
	"deleteSubscription":   deleteSubscription,
	"insertItem":           insertItem,
	"insertItemWithAction": insertItemWithAction,
	"insertItemAllUsers":   insertItemAllUsers,
	"insertContact":        insertContact,
	"deleteContact":        deleteContact,
	"deleteTimelineItem":   deleteTimelineItem,
}

Save the files and redeploy your project to AppEngine. Once your reload your application in the browser, a button will appear underneath each timeline item that will delete it!

2 Replies to “Deleting Google Glass Timeline Items Using the Go Quick Start Project”

Leave a Reply