From 7a5acdaec1ede3973231dfe8f2f47de6107787d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Norman=20Hauk=C3=A5s?= Date: Sat, 24 Oct 2015 00:39:49 +0200 Subject: [PATCH] added ts file for keeping interfaces in. Angular is now able to get and display synsets. --- Gulpfile.js | 4 +- src/index.interfaces.ts | 26 ++++++++++++ src/index.ts | 1 + src/menu/menu.controller.ts | 61 ++++++++++++++++++++-------- src/menu/menu.tpl.html | 2 +- src/services/data.service.ts | 28 +++++++++---- src/services/selectedWord.service.ts | 47 +++++++++++---------- 7 files changed, 121 insertions(+), 48 deletions(-) create mode 100644 src/index.interfaces.ts diff --git a/Gulpfile.js b/Gulpfile.js index 4b584eb..5b0ad33 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -9,7 +9,9 @@ var ts = require('gulp-typescript'); var merge = require('merge2'); var concat = require('gulp-concat'); -var tsProject = ts.createProject('tsconfig.json'); +var tsProject = ts.createProject('tsconfig.json', { + sortOutput : true +}); gulp.task('scripts', function() { var tsResult = gulp.src('src/*.ts') diff --git a/src/index.interfaces.ts b/src/index.interfaces.ts new file mode 100644 index 0000000..c76a300 --- /dev/null +++ b/src/index.interfaces.ts @@ -0,0 +1,26 @@ +/// + +module tagIt { + + export interface synsetJson { + config: Object, + data: { + senses: string[] + } + } + + export interface tagItAngularScope extends angular.IScope { + vm : Object; + } + + export interface ISense { + explanation: string, + rank: number, + related: string, + senseid: string, + source: string, + word: string + } + +} + diff --git a/src/index.ts b/src/index.ts index f08bd45..a60e2b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,5 +21,6 @@ module tagIt { if(callback) callback(); }); } + } diff --git a/src/menu/menu.controller.ts b/src/menu/menu.controller.ts index df982f3..09e951b 100644 --- a/src/menu/menu.controller.ts +++ b/src/menu/menu.controller.ts @@ -1,33 +1,62 @@ +/// + module tagIt { 'use strict'; - interface IMenuScope extends angular.IScope { - startData: Object[]; - testWord: String; - } - export class MenuCtrl { - testWord = "It's working"; - selectedWord = "No word yet"; + selectedWord = ""; + senses : Object[]; + dataService : DataService; + selectedWordService : SelectedWordService; + $log : ng.ILogService; + $scope: ng.IScope; - static $inject = ["$scope", "$log", "DataService", "SelectedWordService"]; - constructor($scope: any, $log: angular.ILogService, + static $inject = [ + "$scope", + "$log", + "DataService", + "SelectedWordService" + ]; + + constructor ($scope: tagItAngularScope, $log: angular.ILogService, DataService: DataService, SelectedWordService: SelectedWordService) { $scope.vm = this; - SelectedWordService.controllerToNotify = this.onWordSelected; - window.setTimeout(function() { - $log.debug('should be new version of jquery'); - $log.debug(jQuery.fn); - }, 2000); + this.$log = $log; + this.$scope = $scope; + this.dataService = DataService; + this.selectedWordService = SelectedWordService; + // Wire up clicklistener + this.selectedWordService.wireUpListener(this.onWordSelected, + this.onWordDeSelected); } - onWordSelected (newWord : string) { + onWordSelected = (newWord : string) => { this.selectedWord = newWord; + this.dataService.callServer(newWord) + .then((synsets : Object) => { + this.$log.debug(synsets); + this.senses = this.dataService.processSynsets( synsets); + }); } - remove() { + onWordDeSelected = () => { + this.$log.debug("onWordDeSelected"); + this.selectedWord = ""; + this.senses = []; + this.$scope.$apply(); + } + + selectWord (sense : ISense) { + this.dataService.storeTaggingInformation({ + mail: "mail@nilsnh.no", + sentence: "whole sentence", + senseid: sense.senseid, + }); + } + + removeMenu() { $('.tagit-body').children().unwrap(); $('.tagit-menu').remove(); } diff --git a/src/menu/menu.tpl.html b/src/menu/menu.tpl.html index e680550..8f6ccce 100644 --- a/src/menu/menu.tpl.html +++ b/src/menu/menu.tpl.html @@ -18,7 +18,7 @@
    -
  • +
  • {{sense.word}} {{sense.explanation}}
diff --git a/src/services/data.service.ts b/src/services/data.service.ts index f974ce3..353745f 100644 --- a/src/services/data.service.ts +++ b/src/services/data.service.ts @@ -1,27 +1,37 @@ 'use strict'; module tagIt { + export class DataService { $http : ng.IHttpService; - serverUrl = 'http://lexitags.dyndns.org/server/lexitags2/Semtags?data='; - static $inject = ["$http", "$log"]; + private serverUrl = 'http://lexitags.dyndns.org/server/lexitags2/Semtags?data='; + static $inject = ["$http", "$log"]; constructor($http: ng.IHttpService, $log: ng.ILogService) { this.$http = $http; } - createQuery (word: string) { - return '{"word":"QUERYTOREPLACE"}' - .replace(/QUERYTOREPLACE/, word); - } - callServer (word: string) { if (!word) { return; }; - return this.$http - .get(this.serverUrl + this.createQuery(word)); + return this.$http.get(this.serverUrl + this.createQuery(word)); + } + + processSynsets (synsets: synsetJson) : string[] { + return synsets.data.senses; + } + + // save tagging information + // Params: email, tagging, sentence + storeTaggingInformation (tag : Object) { + + } + + private createQuery (word: string) { + return '{"word":"QUERYTOREPLACE"}' + .replace(/QUERYTOREPLACE/, word); } } } diff --git a/src/services/selectedWord.service.ts b/src/services/selectedWord.service.ts index a62ff70..7029c5f 100644 --- a/src/services/selectedWord.service.ts +++ b/src/services/selectedWord.service.ts @@ -7,17 +7,36 @@ module tagIt { */ export class SelectedWordService { - currentlySelectedWord: string; - controllerToNotify : (selectedWord : string) => void; $log : ng.ILogService; static $inject = ["$log"]; constructor($log: ng.ILogService) { this.$log = $log; - this.init(); } - processSelection () { + wireUpListener (callbackOnSelectFunc : (result : Object) => void, + callbackOnDeSelectFunc : () => void) { + var that = this; + document.addEventListener('click', (evt : any) => { + if (!document.hasFocus()) { + return true; + } + var selectedWord = that.findSelection(); + if(selectedWord) { + callbackOnSelectFunc(joinLongWords(selectedWord)); + } else { + callbackOnDeSelectFunc(); + } + // clicks should propagate upwards to other things + // evt.stopPropagation(); + // evt.preventDefault(); + }, false); + function joinLongWords (possiblyLongWord: string) { + return possiblyLongWord.replace(" ","_"); + } + } + + private findSelection () { var focused : any = document.activeElement; var selectedText : string; if (focused) { @@ -32,25 +51,11 @@ module tagIt { var selectedText = sel.toString(); } if (selectedText) { - this.currentlySelectedWord = selectedText; this.$log.debug('text that was selected: ' + selectedText); - if(this.controllerToNotify) { - this.controllerToNotify(selectedText); - } + return selectedText; + } else { + return; } } - - init () { - var that = this; - document.addEventListener('click', function (evt) { - if (!document.hasFocus()) { - return true; - } - that.processSelection(); - // clicks should propagate upwards to other things - // evt.stopPropagation(); - // evt.preventDefault(); - }, false); - } } }