added options for downloading only for current page or for all pages in that domain. Fixed a bug where loading the menu would try to load all tags for the domain and not just the page-specific tags. Fixed by adding filter. Also added option for deleting tags for the current page that is viewed.
This commit is contained in:
parent
9676be1e3d
commit
d5f5aba1aa
7 changed files with 83 additions and 44 deletions
|
@ -31,7 +31,11 @@
|
|||
|
||||
<h2>Tag you're it</h2>
|
||||
|
||||
<p><a href ng-click="vm.downloadTags()">Download tags</a></p>
|
||||
<p>Menu:
|
||||
<a href ng-click="vm.downloadTagsForPage()">Download tags (current page)</a> |
|
||||
<a href ng-click="vm.downloadAllTagsForDomain()">Download all tags (domain)</a> |
|
||||
<a href ng-click="vm.removeTagsFromLocalStorage()">Delete tags from current page</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Mark one or two words on the page to the right. And we'll supply you with possible definitions. Select a definition and the
|
||||
|
|
|
@ -35,5 +35,6 @@ module tagIt {
|
|||
wordThatWasTagged: string;
|
||||
serializedSelectionRange: string;
|
||||
deserializedRange?: Range;
|
||||
urlOfPageThatWasTagged: string;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ module tagIt {
|
|||
});
|
||||
|
||||
// Reload existing tags
|
||||
var tagsToLoad = this.tagStorageService.loadTags();
|
||||
var tagsToLoad = this.tagStorageService.loadTagsForCurrentPage();
|
||||
|
||||
this.$log.debug('these tags were found in storage');
|
||||
this.$log.debug(tagsToLoad);
|
||||
|
@ -58,11 +58,13 @@ module tagIt {
|
|||
//initialize and save the new tag
|
||||
var senseTag = this.webPageService.initializeNewTag(sense);
|
||||
this.tagStorageService.saveTag(senseTag);
|
||||
this.backendService.sendTaggedDataToServer(senseTag);
|
||||
|
||||
// deactivate backendService for now.
|
||||
// this.backendService.sendTaggedDataToServer(senseTag);
|
||||
|
||||
//re-add tags, with new tag. Clear menu options.
|
||||
this.webPageService.readdTagsToPage(
|
||||
this.tagStorageService.loadTags()
|
||||
this.tagStorageService.loadTagsForCurrentPage()
|
||||
);
|
||||
this.clearMenuVariables();
|
||||
});
|
||||
|
@ -71,13 +73,31 @@ module tagIt {
|
|||
/**
|
||||
* Enables a clickable button to download tags as a json file.
|
||||
*/
|
||||
downloadTags() {
|
||||
downloadTagsForPage() {
|
||||
if (typeof chrome === 'undefined') {
|
||||
this.$log.debug('Did not find chrome facilities. Can\'t download.')
|
||||
return; //do nothing
|
||||
}
|
||||
var tags : ISenseTag[] = this.tagStorageService.loadTags();
|
||||
this.fileService.saveFile(tags);
|
||||
this.fileService.saveFile(this.tagStorageService.loadTagsForCurrentPage());
|
||||
}
|
||||
|
||||
downloadAllTagsForDomain() {
|
||||
if (typeof chrome === 'undefined') {
|
||||
this.$log.debug('Did not find chrome facilities. Can\'t download.')
|
||||
return; //do nothing
|
||||
}
|
||||
this.fileService.saveFile(this.tagStorageService.loadAllTagsInLocalStorage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables clickable link for removing tags.
|
||||
*/
|
||||
removeTagsFromLocalStorage() {
|
||||
if (confirm('Really delete tags from the current page?')) {
|
||||
this.webPageService.removeAllTagsFromPage(() => {
|
||||
this.tagStorageService.deleteTagsFromCurrentPage()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onWordSelectedEvent = (newWord: string) => {
|
||||
|
@ -93,7 +113,7 @@ module tagIt {
|
|||
this.backendService.callServer(newWord)
|
||||
.then((synsets: any) => {
|
||||
this.$log.debug(synsets);
|
||||
this.senses = synsets.data.senses;;
|
||||
this.senses = synsets.data.senses;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -112,10 +132,5 @@ module tagIt {
|
|||
this.senses = [];
|
||||
}
|
||||
|
||||
deleteTags() {
|
||||
this.tagStorageService.deleteTags();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Tag you're it",
|
||||
"description": "A browser tool for tagging words with exact definitions.",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
"16": "icon16.png",
|
||||
|
|
|
@ -5,25 +5,30 @@
|
|||
//Responsible for saving.
|
||||
module tagIt {
|
||||
|
||||
export class FileService {
|
||||
export class FileService {
|
||||
|
||||
$log: ng.ILogService;
|
||||
$log: ng.ILogService;
|
||||
|
||||
/* @ngInject */
|
||||
constructor($log: ng.ILogService) {
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
saveFile(content: ISenseTag[]) {
|
||||
var json = JSON.stringify(content, null, 2);
|
||||
var blob = new Blob([json], { type: "application/json" });
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = <any>document.createElement('a');
|
||||
var date = new Date();
|
||||
a.download = `
|
||||
tags downloaded for ${window.location.hostname}
|
||||
time of download ${date.toLocaleString()}
|
||||
.json`
|
||||
.replace('\n', '')
|
||||
a.href = url;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url); //Explicitly release obj from memory.
|
||||
}
|
||||
|
||||
/* @ngInject */
|
||||
constructor($log: ng.ILogService) {
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
saveFile(content: ISenseTag[]) {
|
||||
var json = JSON.stringify(content, null, 2);
|
||||
var blob = new Blob([json], { type: "application/json" });
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = <any> document.createElement('a');
|
||||
var date = new Date();
|
||||
a.download = `tags downloaded for ${window.location.hostname} time of download ${date.toLocaleString()}.json`;
|
||||
a.href = url;
|
||||
a.click();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ module tagIt {
|
|||
|
||||
$http: ng.IHttpService;
|
||||
$log: ng.ILogService;
|
||||
$localStorage: any;
|
||||
$localStorage: { tagStorage: ISenseTag[] };
|
||||
|
||||
/* @ngInject */
|
||||
constructor($http: ng.IHttpService, $log: ng.ILogService,
|
||||
|
@ -18,11 +18,11 @@ module tagIt {
|
|||
this.$http = $http;
|
||||
this.$log = $log;
|
||||
this.$localStorage = $localStorage;
|
||||
|
||||
|
||||
if (window.location.href.indexOf("tagitreset") !== -1) {
|
||||
this.deleteTags(); // reset tag storage
|
||||
this.$log.debug("Resetting tags for this page");
|
||||
}
|
||||
this.deleteTagsFromCurrentPage(); // reset tag storage
|
||||
this.$log.debug("Resetting tags for this page");
|
||||
}
|
||||
|
||||
if (!this.$localStorage.tagStorage) {
|
||||
this.$localStorage.tagStorage = [];
|
||||
|
@ -42,9 +42,11 @@ module tagIt {
|
|||
this.$localStorage.tagStorage = newList;
|
||||
}
|
||||
|
||||
deleteTags() {
|
||||
this.$log.debug('deleting all tags from localstorage');
|
||||
delete this.$localStorage.tagStorage;
|
||||
deleteTagsFromCurrentPage() {
|
||||
this.$log.debug('deleting tags');
|
||||
this.$localStorage.tagStorage =
|
||||
this.$localStorage.tagStorage.filter(
|
||||
(tag: ISenseTag) => tag.urlOfPageThatWasTagged !== window.location.href)
|
||||
}
|
||||
|
||||
saveTag(tagToSave: ISenseTag) {
|
||||
|
@ -53,9 +55,20 @@ module tagIt {
|
|||
this.$localStorage.tagStorage.push(tagToSave);
|
||||
}
|
||||
|
||||
loadTags() {
|
||||
this.$log.debug('loadTags');
|
||||
return this.$localStorage.tagStorage;
|
||||
loadTagsForCurrentPage(): ISenseTag[] {
|
||||
this.$log.debug('loadTagsForCurrentPage');
|
||||
return this.$localStorage.tagStorage
|
||||
.filter((tag: ISenseTag) =>
|
||||
tag.urlOfPageThatWasTagged === window.location.href
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all tags in localstorage (for the current domain).
|
||||
*/
|
||||
loadAllTagsInLocalStorage() {
|
||||
this.$log.debug('loadAllTagsInLocalStorage');
|
||||
return this.$localStorage.tagStorage
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ module tagIt {
|
|||
wordThatWasTagged: selection.toString(),
|
||||
iframeIndex: getIframeIndex(this.listOfFramesWithContent, iframeOfInterest),
|
||||
context: parentElement.textContent,
|
||||
serializedSelectionRange: serializedRange
|
||||
serializedSelectionRange: serializedRange,
|
||||
urlOfPageThatWasTagged: window.location.href
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue