From bba52f1b0c1ad9ccdd4bd64ca1b30961cca4c1f3 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Tue, 23 Aug 2016 22:57:35 +0200 Subject: [PATCH] system: invite add and list --- public/app/invites.jade | 17 ++++++++++++-- public/app/invites.js | 36 +++++++++++++++++++++++++----- public/components/config.js | 2 +- tests/config.json | 4 ++-- tests/index.coffee | 44 +++++++++++++++++++++++++++---------- 5 files changed, 81 insertions(+), 22 deletions(-) diff --git a/public/app/invites.jade b/public/app/invites.jade index 1dba27b..8bfb963 100644 --- a/public/app/invites.jade +++ b/public/app/invites.jade @@ -1,14 +1,27 @@ .container h1 Invites - a.btn.btn-default + a.btn.btn-default(ng-click="isAdding=true") 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") tr(ng-hide='group.$hideRows',ng-repeat="item in $data") td(data-title="'#'") {{item.invited.ID}} td(data-title="'Hostname'", filter="{'invited.username': 'text'}") span(ng-if="!item.isEditing") {{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)}") label(for="newPassword") New Password input.form-control(id="newPassword",type="password",name="newPassword",ng-model="obj.newPassword",ng-minlength="3") diff --git a/public/app/invites.js b/public/app/invites.js index 671102a..62b57ad 100644 --- a/public/app/invites.js +++ b/public/app/invites.js @@ -7,10 +7,36 @@ angular.module('warehost') total: 0, count: config.table.count }, { dataset: [] }); - $scope.list = {}; alert.set({}); - $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}); - }); + $scope.list = {}; + function resetObj(){ + $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; + } + }); + }; }); diff --git a/public/components/config.js b/public/components/config.js index 582a254..181cfdc 100644 --- a/public/components/config.js +++ b/public/components/config.js @@ -2,7 +2,7 @@ angular.module('config', []) .factory('config', function() { return { - api: 'http://[::1]:8080', + api: 'https://apiv2.warehost.de', table: { count: 25 } diff --git a/tests/config.json b/tests/config.json index 15e0cab..9ad6245 100644 --- a/tests/config.json +++ b/tests/config.json @@ -1,7 +1,7 @@ { "ADDRESS":"http://[::1]:8080", "testdata":{ - "username":"genofire", - "password":"fire35911" + "username":"root", + "password":"root" } } diff --git a/tests/index.coffee b/tests/index.coffee index 9741319..3de635e 100644 --- a/tests/index.coffee +++ b/tests/index.coffee @@ -18,6 +18,26 @@ describe('API',-> ) ) 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',-> it('-> validate',(done)-> lib.login((j)-> @@ -26,9 +46,9 @@ describe('API',-> expect(res.statusCode).to.be.equal(200) if(typeof body == "string") body = JSON.parse(body) - console.log(body.data) - expect(body.error).to.be.null - expect(body.session.login).to.be.undefined + expect(body.error).to.be.undefined + expect(body.data).to.be.a("array") + expect(body.session.login).to.not.be.null done() ) ) @@ -76,7 +96,7 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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 done() ) @@ -103,8 +123,8 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) expect(body.data).to.be.true - expect(body.error).to.be.null - expect(body.session.login).to.be.null + expect(body.error).to.be.undefined + expect(body.session.login).to.be.undefined done() ) ) @@ -123,7 +143,7 @@ describe('API',-> expect(body.data).to.be.false expect(body.error.msg).to.not.be.null expect(body.error.fields).to.include('session') - expect(body.session.login).to.be.null + expect(body.session.login).to.be.undefined done() ) ) @@ -158,7 +178,7 @@ describe('API',-> expect(body.data).to.be.false expect(body.error.msg).to.not.be.null expect(body.error.fields).to.include('newpassword') - expect(body.session.login).to.not.be.null + expect(body.session.login).to.not.be.undefined done() ) ) @@ -174,7 +194,7 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) 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:{ currentpassword: config.testdata.password+"f", newpassword: config.testdata.password, @@ -196,7 +216,7 @@ describe('API',-> expect(body.data).to.be.false expect(body.error.msg).to.not.be.null expect(body.error.fields).to.include('session') - expect(body.session.login).to.be.null + expect(body.session.login).to.be.undefined done() ) ) @@ -208,8 +228,8 @@ describe('API',-> if(typeof body == "string") body = JSON.parse(body) expect(body.data).to.be.true - expect(body.error).to.be.null - expect(body.session.login).to.be.null + expect(body.error).to.be.undefined + expect(body.session.login).to.be.undefined done() ) )