added a download button and a file save service. Is now able to download tags for a tagged page.

This commit is contained in:
Nils Norman Haukås 2016-03-18 19:57:54 +01:00
parent 417e840d13
commit 5bd4b2e2c6
5 changed files with 51 additions and 3 deletions

View file

@ -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

View file

@ -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")

View file

@ -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) {

View file

@ -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",

View 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();
}
}
}