From 5bd4b2e2c60b67005b15c007ebe5f49da29173bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Norman=20Hauk=C3=A5s?= Date: Fri, 18 Mar 2016 19:57:54 +0100 Subject: [PATCH] added a download button and a file save service. Is now able to download tags for a tagged page. --- src/index-angular-app.html | 2 ++ src/index.ts | 2 ++ src/menu/menu.controller.ts | 19 +++++++++++++++++-- src/plugin-specific/manifest.json | 2 +- src/services/file.service.ts | 29 +++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/services/file.service.ts diff --git a/src/index-angular-app.html b/src/index-angular-app.html index 630dd99..8257d7c 100644 --- a/src/index-angular-app.html +++ b/src/index-angular-app.html @@ -30,6 +30,8 @@

Tag you're it

+ +

Download tags

Mark one or two words on the page to the right. And we'll supply you with possible definitions. Select a definition and the diff --git a/src/index.ts b/src/index.ts index 3c10495..ed03214 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ /// /// /// +/// 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 = document.getElementById("tagit-iframe") diff --git a/src/menu/menu.controller.ts b/src/menu/menu.controller.ts index b9ef67e..0377443 100644 --- a/src/menu/menu.controller.ts +++ b/src/menu/menu.controller.ts @@ -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) { diff --git a/src/plugin-specific/manifest.json b/src/plugin-specific/manifest.json index 7c7b6e9..e57d77c 100644 --- a/src/plugin-specific/manifest.json +++ b/src/plugin-specific/manifest.json @@ -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", diff --git a/src/services/file.service.ts b/src/services/file.service.ts new file mode 100644 index 0000000..ac4cac0 --- /dev/null +++ b/src/services/file.service.ts @@ -0,0 +1,29 @@ +/// + +'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 = 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(); + } + + } +} \ No newline at end of file