sum7/warehost-frontend
sum7
/
warehost-frontend
Archived
1
0
Fork 0

system: invite add and list

This commit is contained in:
Martin Geno 2016-08-23 22:57:35 +02:00
parent 238c5311e3
commit bba52f1b0c
5 changed files with 81 additions and 22 deletions

View File

@ -1,14 +1,27 @@
.container .container
h1 Invites h1 Invites
a.btn.btn-default a.btn.btn-default(ng-click="isAdding=true")
span.glyphicon.glyphicon-plus span.glyphicon.glyphicon-plus
form(ng-submit="add()",name="addform",ng-if="isAdding")
.form-group
label(for="username") Username
input.form-control(id="username",name="username",ng-model="obj.username",ng-minlength="3")
.form-group(ng-class="{'has-error': (error.fields.indexOf('newpassword') >= 0 || !addform.newPassword.$valid)}")
label(for="newPassword") New Password
input.form-control(id="newPassword",type="password",name="newPassword",ng-model="obj.password",ng-minlength="3")
.form-group(ng-class="{'has-error': (obj.password != obj.repeatPassword && addform.repeatPassword.$dirty)}")
label(for="repeatPassword") Again Password
input.form-control(id="repeatPassword",type="password",name="repeatPassword",ng-model="obj.repeatPassword")
button.btn.btn-primary(type="submit")
span.glyphicon.glyphicon-floppy-disk
| Save
table.table.table-bordered(ng-table="tableParams") table.table.table-bordered(ng-table="tableParams")
tr(ng-hide='group.$hideRows',ng-repeat="item in $data") tr(ng-hide='group.$hideRows',ng-repeat="item in $data")
td(data-title="'#'") {{item.invited.ID}} td(data-title="'#'") {{item.invited.ID}}
td(data-title="'Hostname'", filter="{'invited.username': 'text'}") td(data-title="'Hostname'", filter="{'invited.username': 'text'}")
span(ng-if="!item.isEditing") {{item.invited.username}} span(ng-if="!item.isEditing") {{item.invited.username}}
h4(ng-if="item.isEditing") Username: {{item.invited.username}} h4(ng-if="item.isEditing") Username: {{item.invited.username}}
form(ng-submit="submit(item)",name="myform",ng-if="item.isEditing") form(ng-submit="submit(obj)",name="myform",ng-if="item.isEditing")
.form-group(ng-class="{'has-error': (error.fields.indexOf('newpassword') >= 0 || !myform.newPassword.$valid)}") .form-group(ng-class="{'has-error': (error.fields.indexOf('newpassword') >= 0 || !myform.newPassword.$valid)}")
label(for="newPassword") New Password label(for="newPassword") New Password
input.form-control(id="newPassword",type="password",name="newPassword",ng-model="obj.newPassword",ng-minlength="3") input.form-control(id="newPassword",type="password",name="newPassword",ng-model="obj.newPassword",ng-minlength="3")

View File

@ -7,10 +7,36 @@ angular.module('warehost')
total: 0, total: 0,
count: config.table.count count: config.table.count
}, { dataset: [] }); }, { dataset: [] });
$scope.list = {};
alert.set({}); alert.set({});
$http.get(config.api+'/invite').then(function(res){ $scope.list = {};
session.set(res); function resetObj(){
$scope.tableParams.settings({dataset: angular.copy(res.data.data),total: (res.data.data).length}); $scope.obj = {};
}); var username = session.get().login.username;
if(username.indexOf('@')<0){
$scope.obj.username = username+'@';
}
}
function load(){
$http.get(config.api+'/invite').then(function(res){
session.set(res);
$scope.tableParams.settings({dataset: angular.copy(res.data.data),total: (res.data.data).length});
});
}
resetObj();
load();
$scope.submit = function(a){
console.log(a);
};
$scope.add = function(){
$http.post(config.api+'/invite',$scope.obj).then(function(res){
session.set(res);
alert.set(res);
if(res.data.data){
load();
resetObj();
$scope.isAdding = false;
}
});
};
}); });

View File

@ -2,7 +2,7 @@
angular.module('config', []) angular.module('config', [])
.factory('config', function() { .factory('config', function() {
return { return {
api: 'http://[::1]:8080', api: 'https://apiv2.warehost.de',
table: { table: {
count: 25 count: 25
} }

View File

@ -1,7 +1,7 @@
{ {
"ADDRESS":"http://[::1]:8080", "ADDRESS":"http://[::1]:8080",
"testdata":{ "testdata":{
"username":"genofire", "username":"root",
"password":"fire35911" "password":"root"
} }
} }

View File

@ -18,6 +18,26 @@ describe('API',->
) )
) )
describe('invite',-> describe('invite',->
describe('add',->
it('-> validate',(done)->
lib.login((j)->
invite = {
username: 'test',
password:'test'
}
request({method: 'POST',uri:config.ADDRESS+"/invite",jar:j,json:invite},(err,res,body)->
expect(err).to.be.null
expect(res.statusCode).to.be.equal(200)
if(typeof body == "string")
body = JSON.parse(body)
expect(body.error).to.be.undefined
expect(body.data).to.be.true
expect(body.session.login).to.not.be.null
done()
)
)
)
)
describe('list',-> describe('list',->
it('-> validate',(done)-> it('-> validate',(done)->
lib.login((j)-> lib.login((j)->
@ -26,9 +46,9 @@ describe('API',->
expect(res.statusCode).to.be.equal(200) expect(res.statusCode).to.be.equal(200)
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
console.log(body.data) expect(body.error).to.be.undefined
expect(body.error).to.be.null expect(body.data).to.be.a("array")
expect(body.session.login).to.be.undefined expect(body.session.login).to.not.be.null
done() done()
) )
) )
@ -76,7 +96,7 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.data).to.be.true expect(body.data).to.be.true
expect(body.error).to.be.null expect(body.error).to.be.undefined
expect(body.session.login.active).to.be.true expect(body.session.login.active).to.be.true
done() done()
) )
@ -103,8 +123,8 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.data).to.be.true expect(body.data).to.be.true
expect(body.error).to.be.null expect(body.error).to.be.undefined
expect(body.session.login).to.be.null expect(body.session.login).to.be.undefined
done() done()
) )
) )
@ -123,7 +143,7 @@ describe('API',->
expect(body.data).to.be.false expect(body.data).to.be.false
expect(body.error.msg).to.not.be.null expect(body.error.msg).to.not.be.null
expect(body.error.fields).to.include('session') expect(body.error.fields).to.include('session')
expect(body.session.login).to.be.null expect(body.session.login).to.be.undefined
done() done()
) )
) )
@ -158,7 +178,7 @@ describe('API',->
expect(body.data).to.be.false expect(body.data).to.be.false
expect(body.error.msg).to.not.be.null expect(body.error.msg).to.not.be.null
expect(body.error.fields).to.include('newpassword') expect(body.error.fields).to.include('newpassword')
expect(body.session.login).to.not.be.null expect(body.session.login).to.not.be.undefined
done() done()
) )
) )
@ -174,7 +194,7 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.data).to.be.true expect(body.data).to.be.true
expect(body.error).to.be.null expect(body.error).to.be.undefined
request({method: 'POST',uri: config.ADDRESS+"/password",json:{ request({method: 'POST',uri: config.ADDRESS+"/password",json:{
currentpassword: config.testdata.password+"f", currentpassword: config.testdata.password+"f",
newpassword: config.testdata.password, newpassword: config.testdata.password,
@ -196,7 +216,7 @@ describe('API',->
expect(body.data).to.be.false expect(body.data).to.be.false
expect(body.error.msg).to.not.be.null expect(body.error.msg).to.not.be.null
expect(body.error.fields).to.include('session') expect(body.error.fields).to.include('session')
expect(body.session.login).to.be.null expect(body.session.login).to.be.undefined
done() done()
) )
) )
@ -208,8 +228,8 @@ describe('API',->
if(typeof body == "string") if(typeof body == "string")
body = JSON.parse(body) body = JSON.parse(body)
expect(body.data).to.be.true expect(body.data).to.be.true
expect(body.error).to.be.null expect(body.error).to.be.undefined
expect(body.session.login).to.be.null expect(body.session.login).to.be.undefined
done() done()
) )
) )