The team at Google working on the Google Glass Quick Start projects have accepted the rest of my code changes and merged all of my remaining pull requests into the other four projects! The button to delete individual timeline items is now available in the projects for all currently available languages:
Merge Request Accepted for Google Glass Starter Project!
An update on my Google Glass post from this morning:
I submitted a pull request to include my code into the Go Quick Start Project and they merged it into Google’s master branch!
So if you download the Go version of the project now, it will include this code. I have submitted similar pull requests for the Python, Java, PHP, and .NET versions as well and am awaiting acceptance for those.
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!