-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1199dd2
commit 1b9b187
Showing
21 changed files
with
329 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var queries = require('./sentence.queries.js'); | ||
|
||
module.exports = function(options){ | ||
options = options || {}; | ||
options.skip = parseInt(options.skip) || 0; | ||
options.take = parseInt(options.take) || 50; | ||
return gladys.utils.sql(queries.get, [options.take, options.skip]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var queries = require('./sentence.queries.js'); | ||
|
||
module.exports = function(){ | ||
return gladys.utils.sql(queries.getLabels, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var Promise = require('bluebird'); | ||
|
||
module.exports = function update(sentence){ | ||
var id = sentence.id; | ||
return Sentence.update({id}, sentence) | ||
.then(function(sentence){ | ||
if(sentence.length === 0){ | ||
return Promise.reject(new Error('NotFound')); | ||
} else { | ||
return Promise.resolve(sentence[0]); | ||
} | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Gladys Project | ||
* http://gladysproject.com | ||
* Software under licence Creative Commons 3.0 France | ||
* http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ | ||
* You may not use this software for commercial purposes. | ||
* @author :: Pierre-Gilles Leymarie | ||
*/ | ||
|
||
|
||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('gladys') | ||
.controller('SentenceCtrl', SentenceCtrl); | ||
|
||
SentenceCtrl.$inject = ['sentenceService', '$scope', 'notificationService']; | ||
|
||
function SentenceCtrl(sentenceService, $scope, notificationService) { | ||
/* jshint validthis: true */ | ||
var vm = this; | ||
vm.sentences = []; | ||
vm.labels = []; | ||
vm.change = change; | ||
vm.reject = reject; | ||
vm.approve = approve; | ||
vm.loadMore = loadMore; | ||
vm.get = get; | ||
vm.remoteIsBusy = false; | ||
vm.noMoreSentences = false; | ||
vm.startValue = 0; | ||
vm.nbElementToGet = 50; | ||
// helpers | ||
vm.eq = (a, b) => a === b; | ||
vm.neq = (a, b) => a != b; | ||
|
||
activate(); | ||
|
||
function activate() { | ||
return getLabels() | ||
.then(loadMore()); | ||
} | ||
|
||
function change(sentence) { | ||
sentence.status = "approved"; | ||
return sentenceService.update(sentence) | ||
} | ||
function reject(id) { | ||
return sentenceService.reject(id) | ||
.then( ({ data }) => vm.sentences[vm.sentences.findIndex(sentence => sentence.id === data.id)] = data) | ||
} | ||
function approve(id) { | ||
return sentenceService.approve(id) | ||
.then( ({ data }) => vm.sentences[vm.sentences.findIndex(sentence => sentence.id === data.id)] = data) | ||
} | ||
function getLabels() { | ||
return sentenceService.getLabels().then(data => vm.labels = data.data); | ||
} | ||
function loadMore(){ | ||
if(!vm.remoteIsBusy && !vm.noMoreSentences){ | ||
return get(vm.startValue+vm.nbElementToGet, vm.startValue) | ||
.then(() => vm.startValue += vm.nbElementToGet) | ||
} | ||
else { | ||
Promise.resolve() | ||
} | ||
} | ||
function get(take, skip) { | ||
vm.remoteIsBusy = true; | ||
return sentenceService.get(take, skip) | ||
.then(function(data){ | ||
if(data.data.length === 0){ | ||
vm.noMoreSentences = true; | ||
} | ||
vm.sentences = vm.sentences.concat(data.data); | ||
vm.remoteIsBusy = false; | ||
}); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Gladys Project | ||
* http://gladysproject.com | ||
* Software under licence Creative Commons 3.0 France | ||
* http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ | ||
* You may not use this software for commercial purposes. | ||
* @author :: Pierre-Gilles Leymarie | ||
*/ | ||
|
||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('gladys') | ||
.factory('sentenceService', sentenceService); | ||
|
||
sentenceService.$inject = ['$http']; | ||
|
||
function sentenceService($http) { | ||
|
||
var service = { | ||
get: get, | ||
update: update, | ||
reject: reject, | ||
approve: approve, | ||
getLabels: getLabels | ||
}; | ||
|
||
return service; | ||
|
||
// all about sentences | ||
|
||
function get(take, skip) { | ||
return $http({method: 'GET', url: '/sentence', params: {take: take, skip: skip}}); | ||
} | ||
|
||
function update(sentence){ | ||
return $http({method: 'PATCH', url: '/sentence/' + sentence.id, data: sentence}); | ||
} | ||
|
||
function reject(id){ | ||
return $http({method: 'PATCH', url: '/sentence/' + id, data: { status: 'rejected' } }); | ||
} | ||
|
||
function approve(id){ | ||
return $http({method: 'PATCH', url: '/sentence/' + id, data: { status: 'approved' } }); | ||
} | ||
|
||
function getLabels() { | ||
return $http({method: 'GET', url: '/sentence/label' }); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var should = require('should'); | ||
var validateSentenceParam = require('../../validator/sentenceValidator'); | ||
|
||
describe('sentence', function() { | ||
|
||
describe('get', function() { | ||
|
||
it('should return the first sentence', function (done) { | ||
|
||
|
||
gladys.sentence.get({take: 1, skip: 0}) | ||
.then(function(result){ | ||
validateSentenceParam(result); | ||
result.length.should.not.equal(0); | ||
done(); | ||
}).catch(done); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = validate; | ||
|
||
var should = require('should'); | ||
|
||
function validate(sentence) { | ||
if(sentence instanceof Array) { | ||
sentence.forEach(validateSentence); | ||
} else { | ||
validateSentence(sentence); | ||
} | ||
} | ||
|
||
function validateSentence(sentence) { | ||
sentence.should.be.instanceOf(Object); | ||
sentence.should.have.property('uuid'); | ||
sentence.should.have.property('text'); | ||
sentence.should.have.property('label'); | ||
sentence.should.have.property('service'); | ||
sentence.should.have.property('language'); | ||
sentence.should.have.property('status'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.