added a download button and a file save service. Is now able to download tags for a tagged page.
This commit is contained in:
parent
417e840d13
commit
5bd4b2e2c6
5 changed files with 51 additions and 3 deletions
|
@ -30,6 +30,8 @@
|
|||
<div ng-controller="MenuCtrl">
|
||||
|
||||
<h2>Tag you're it</h2>
|
||||
|
||||
<p><a href ng-click="vm.downloadTags()">Download tags</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
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
/// <reference path="services/backend.service.ts" />
|
||||
/// <reference path="services/webpage.service.ts" />
|
||||
/// <reference path="services/tagStorage.service.ts" />
|
||||
/// <reference path="services/file.service.ts" />
|
||||
|
||||
module tagIt {
|
||||
|
||||
|
@ -16,6 +17,7 @@ module tagIt {
|
|||
.service('BackendService', BackendService)
|
||||
.service('WebPageService', WebPageService)
|
||||
.service('TagStorageService', TagStorageService)
|
||||
.service('FileService', FileService)
|
||||
.controller('MenuCtrl', MenuCtrl);
|
||||
|
||||
var iframe = <HTMLIFrameElement>document.getElementById("tagit-iframe")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
module tagIt {
|
||||
'use strict';
|
||||
|
||||
|
||||
export class MenuCtrl {
|
||||
|
||||
selectedWord = "";
|
||||
|
@ -10,6 +10,7 @@ module tagIt {
|
|||
backendService: BackendService;
|
||||
webPageService: WebPageService;
|
||||
tagStorageService: TagStorageService;
|
||||
fileService: FileService;
|
||||
$log: ng.ILogService;
|
||||
$scope: ng.IScope;
|
||||
|
||||
|
@ -17,13 +18,15 @@ module tagIt {
|
|||
constructor($scope: IVMScope, $log: angular.ILogService,
|
||||
BackendService: BackendService,
|
||||
WebPageService: WebPageService,
|
||||
TagStorageService: TagStorageService) {
|
||||
TagStorageService: TagStorageService,
|
||||
FileService: FileService) {
|
||||
$scope.vm = this;
|
||||
this.$log = $log;
|
||||
this.$scope = $scope;
|
||||
this.backendService = BackendService;
|
||||
this.webPageService = WebPageService;
|
||||
this.tagStorageService = TagStorageService;
|
||||
this.fileService = FileService;
|
||||
|
||||
this.$scope.$on('wordWasSelected', (event, selectedWord) => {
|
||||
this.$log.debug(`Menucontroller received wordWasSelected event for: ${selectedWord}`);
|
||||
|
@ -64,6 +67,18 @@ module tagIt {
|
|||
this.clearMenuVariables();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a clickable button to download tags as a json file.
|
||||
*/
|
||||
downloadTags() {
|
||||
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);
|
||||
}
|
||||
|
||||
onWordSelectedEvent = (newWord: string) => {
|
||||
if (countWords(newWord) > 2) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Tag you're it",
|
||||
"description": "A browser tool for tagging words with exact definitions.",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
"16": "icon16.png",
|
||||
|
|
29
src/services/file.service.ts
Normal file
29
src/services/file.service.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
/// <reference path="../index.interfaces.ts" />
|
||||
|
||||
'use strict';
|
||||
|
||||
//Responsible for saving.
|
||||
module tagIt {
|
||||
|
||||
export class FileService {
|
||||
|
||||
$log: ng.ILogService;
|
||||
|
||||
/* @ngInject */
|
||||
constructor($log: ng.ILogService) {
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
saveFile(content: ISenseTag[]) {
|
||||
var json = JSON.stringify(content);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue