added ts file for keeping interfaces in. Angular is now able to get and display synsets.

This commit is contained in:
Nils Norman Haukås 2015-10-24 00:39:49 +02:00
parent 5b478e94a1
commit 7a5acdaec1
7 changed files with 121 additions and 48 deletions

View file

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

26
src/index.interfaces.ts Normal file
View file

@ -0,0 +1,26 @@
/// <reference path="../typings/tsd.d.ts" />
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
}
}

View file

@ -21,5 +21,6 @@ module tagIt {
if(callback) callback();
});
}
}

View file

@ -1,33 +1,62 @@
/// <reference path="../index.ts" />
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(<synsetJson> 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();
}

View file

@ -18,7 +18,7 @@
<input type="text" ng-model="wordToFilterBy" class="form-control" placeholder="Filter tags" />
<ul id="senses">
<li id="sense.senseid" ng-repeat="sense in senses" class="list-unstyled">
<li id="sense.senseid" ng-repeat="sense in vm.senses" class="list-unstyled">
<strong>{{sense.word}}</strong> {{sense.explanation}}
</li>
</ul>

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}