added doormen ownership

This commit is contained in:
didier amyot committed 2015-06-14 23:21:42 -04:00
1 parent f0628e4682
commit f7a8d416c1
27 files changed
+489 -126

No files matched your search

+3 -1
View File
@@ -20,6 +20,8 @@
"requirejs-text": "~2.0.10",
"html5-boilerplate": "~4.3.0",
"angularAMD": "~0.2.1",
"angular-foundation": "~0.5.1"
"angular-foundation": "~0.5.1",
"lodash": "~3.9.3",
"font-awesome": "~4.3.0"
}
}
+4 -2
View File
@@ -34,9 +34,11 @@ define [
templateUrl: "partials/doorman.html"
controller: "DoormanCtrl"
controllerUrl: "controllers/doormanCtrl"
)).otherwise redirectTo: "/"
)).otherwise({redirectTo: "/"})
document.getElementsByTagName("body")[0].style.visibility = ""
return
serverspec
angularAMD.bootstrap(app)
+5 -1
View File
@@ -1,8 +1,12 @@
define ["app", "angularAMD"], (app, angularAMD) ->
app.controller "ApispecCtrl", ($scope) ->
app.controller "ApispecCtrl",['$scope', '$http', ($scope, $http) ->
$http.get("/api/documentation").then (res)->
$scope.endpoints = res.data.endpoints
$scope.methods =
get: "GET"
post: "POST"
]
angularAMD.directive "wabMethod", () ->
directive =
+33 -3
View File
@@ -1,9 +1,14 @@
define ["app"], (app) ->
define ["app", "lodash"], (app, _) ->
app.controller "DoormanCtrl", ["$scope", "$http","$routeParams","$location", ($scope, $http, $routeParams, $location) ->
$scope.doorman = {values: []}
$scope.apiurl = "/api/doormen/#{$routeParams.id}"
$scope.user = localStorage.getItem("email")
$http.get($scope.apiurl).then((res) ->
$scope.doorman = res.data
$scope.isAdmin = _.contains($scope.doorman.emails, $scope.user)
$scope.initEmails()
).catch((res) ->
if res.status == 404
$location.path("/doormen/error/#{res.status}/#{$routeParams.id}")
@@ -12,19 +17,44 @@ define ["app"], (app) ->
$scope.deleteDoorman = () ->
console.log("not yet implemented")
$scope.initEmails = () ->
[$scope.leftEmailColumns, $scope.rightEmailColumns] = _.chunk($scope.doorman.emails, 2)
$scope.validate = ()->
ret = 0
for val in $scope.doorman.values
ret += val.probability
return Math.abs(ret - 1.0) < 0.000001
$scope.addNewAuthorEmail = () ->
if not $scope.canAddNewEmail()
return
$scope.doorman.emails.push($scope.newEmail)
$scope.updateDoorman()
$scope.newEmail = ""
$scope.initEmails()
$scope.removeEmail = (email) ->
$scope.doorman.emails = _.reject($scope.doorman.emails , (email_) -> email_ == email)
$scope.initEmails()
$scope.updateDoorman()
$scope.canAddNewEmail = ()->
if !$scope.newEmail or $scope.newEmail.length < 5
return false
not _.contains($scope.doorman.emails, $scope.newEmail)
$scope.updateDoorman = () ->
if !$scope.validate()
return
$http.put($scope.apiurl, $scope.doorman).then((ret)->
params = {params: {user: $scope.user}}
$http.put($scope.apiurl, $scope.doorman, params).then((ret)->
console.log "update"
).catch((res) ->
d = 9
$scope.error =
message: res.data
status : res.status
)
]
return
+6 -1
View File
@@ -1,6 +1,11 @@
define ["app"], (app) ->
app.controller "HomeCtrl", ($scope) ->
$scope.message = "message from home ctrl"
return
$scope.loggedEmail = localStorage.getItem("email")
$scope.login = () ->
if $scope.email
localStorage.setItem("email", $scope.email)
$scope.loggedEmail = $scope.email
$scope.email = ""
return
@@ -1,15 +1,17 @@
epsilon = 0.0001
define ["app"], (app) ->
app.controller "NewDoormanCtrl", ["$scope", "$http", "$location", ($scope, $http, $location) ->
define ["app", "../filters"], (app, filters) ->
app.controller "NewDoormanCtrl", ["$scope", "$http", "$location", ($scope, $http, $location) ->
$scope.error = ""
$scope.value = {}
$scope.user = localStorage.getItem("email")
$scope.value = {probability: 0, name: ""}
$scope.payload =
name: ""
values: []
emails: [$scope.user]
$scope.isValidValue = () ->
return $scope.value.name and $scope.value.probability
return $scope.value.name
$scope.addNewValue = () ->
if !$scope.isValidValue()
@@ -34,7 +36,8 @@ define ["app"], (app) ->
$scope.createDoorman = () ->
if not $scope.isDoormanValid()
return
$http.post("/api/doormen", $scope.payload).
params = {params: {user: $scope.user}}
$http.post("/api/doormen", $scope.payload, params).
then((res, s) ->
$scope.redirectToDoorman(res.headers("location"))
).catch((res) ->
@@ -50,6 +53,18 @@ define ["app"], (app) ->
return false
return true
$scope.addEmail = () ->
if not $scope.newEmail
return
$scope.payload.emails.push($scope.newEmail)
$scope.newEmail = ""
$scope.removeEmail = (idx) ->
if $scope.payload.emails[idx] == $scope.user
return
$scope.payload.emails.splice(idx, 1);
return
]
+7
View File
@@ -0,0 +1,7 @@
define ['angularAMD', 'app'], (angular, app) ->
app.filter 'reverse', ->
(items) ->
if !Array.isArray(items)
return false
items.slice().reverse()
return
+1
View File
@@ -7,6 +7,7 @@ require.config
"angular-route": "/bower_components/angular-route/angular-route.min"
"angularAMD" : "/bower_components/angularAMD/angularAMD.min"
"foundation" : "/bower_components/angular-foundation/mm-foundation-tpls"
"lodash" : "/bower_components/lodash/lodash.min"
# Add angular modules that does not support AMD out of the box, put it in a shim
+2 -1
View File
@@ -4,10 +4,11 @@
<head>
<title>doorman</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
<script data-main="/js/main" src="/bower_components/requirejs/require.js"></script>
</head>
<body>
<body style="visibility:hidden;">
<top-bar>
+1
View File
@@ -6,6 +6,7 @@
"gulp-coffee": "~2.2.0",
"gulp-sass": "^1.2.4",
"gulp-task-listing": "~0.3.0",
"gulp-util": "^3.0.3",
"node-sass": "~1.2.3"
},
"devDependencies": {
+7 -40
View File
@@ -8,52 +8,19 @@
<div class="row wab-apispect">
<table class="columns large-12">
<thead>
<tr>
<tr >
<th >api endpoint</th>
<th>method</th>
<th >description</th>
</tr>
</thead>
<tbody>
<tr>
<td><wab-api endpoint="/server"></wab-api></td>
<td><wab-method method="get"></wab-method></td>
<td>Get the server specification</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen"></wab-api></td>
<td><wab-method method="get"></wab-method></td>
<td>Get the list of all the public doormen.</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen"></wab-api></td>
<td><wab-method method="post"></wab-method></td>
<td>Create a new doorman.</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen/:id"></wab-api></td>
<td><wab-method method="get"></wab-method></td>
<td>Get the doorman</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen/:id"></wab-api></td>
<td><wab-method method="put"></wab-method></td>
<td>Update the doorman with new probabilities</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen/:id"></wab-api></td>
<td><wab-method method="delete"></wab-method></td>
<td>Delete the doorman</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen/:id/status"></wab-api></td>
<td><wab-method method="get"></wab-method></td>
<td>Return the state of the doormen as expected by the client</td>
</tr>
<tr>
<td><wab-api endpoint="/doormen/:id/result?data=<base64>"></wab-api></td>
<td><wab-method method="get"></wab-method></td>
<td>Return the state of the doormen as expected by the client</td>
<tr ng-repeat="endpoint in endpoints">
<td><wab-api endpoint="{{ endpoint.pattern }}"></wab-api></td>
<td>
<code style="width:5em; display: block; text-align: center;">{{ endpoint.method }}</code>
</td>
<td >{{ endpoint.description }}</td>
</tr>
</tbody>
+57 -15
View File
@@ -12,31 +12,73 @@
</div>
<div class="row" ng-repeat="value in doorman.values">
<div class="columns large-9 small-10">
<div class="columns large-8 small-10">
<label >name<input type="text" placeholder="value name" ng-value="value.name" disabled></label>
</div>
<div class="columns large-3 small-2">
<label >probability<input type="number" placeholder="value probability" ng-model="value.probability" min="0" max="1" step="0.01"></label>
<div class="columns large-4 small-2">
<label >
probability
<input type="number"
placeholder="value probability"
ng-model="value.probability"
ng-disabled="!isAdmin"
min="0"
max="1"
step="0.01"></label>
</div>
</div>
<!-- <div class="row">
<div class="columns large-12 small-12">
<h3>try it!</h3>
</div>
</div>
<div class="row">
<textarea class="large-offset-1 small-offset-1 large-10 small-10 columns">
</textarea>
<div class="large-4 columns">
<ul>
<li ng-repeat="email in leftEmailColumns">
<span ng-bind="email"></span>
<i class="fa fa-times right"
ng-click="removeEmail(email)"
style="cursor: pointer;"
ng-show="doorman.emails.length > 1 && isAdmin && email != user"
></i>
</li>
</ul>
</div>
<div class="large-4 columns">
<ul>
<li ng-repeat="email in rightEmailColumns">
<span ng-bind="email"></span>
<i class="fa fa-times right"></i>
</li>
</ul>
</div>
<div class="large-4 columns">
<div>
<label>
new admin
<div class="row collapse">
<div class="columns large-10">
<input type="text" ng-model="newEmail"/>
</div>
<div class="columns large-2">
<a class="button postfix" ng-click="addNewAuthorEmail()" ng-class=" canAddNewEmail() ? '' : 'disabled' " >+</a>
</div>
</div>
</label>
</div>
</div>
</div>
<div class="row">
<div class="large-offset-1 small-offset-1 large-10 small-10 columns">
<a href="#" class="button tiny">try</a>
<div class="row" ng-show="error">
<div class="columns large-12">
<code style="width:100%; height:100%; display:block; margin-bottom: 1em;">
<b>{{ error.status }}</b><br>&nbsp; {{ error.message }}
</code>
</div>
</div> -->
</div>
<div class="row">
<div class="row" ng-show="isAdmin">
<div class="large-12 small-12 columns">
<ul class="button-group">
<li><a ng-click="updateDoorman()" class="small button" ng-class="{disabled: !validate()}">Update</a></li>
+19 -1
View File
@@ -4,8 +4,26 @@
</div>
</div>
<div class="row">
<fieldset>
<legend>Login</legend>
<div class="large-12 columns">
<div class="row collapse">
<div class="small-10 columns">
<input type="text" placeholder="email" ng-model="email">
</div>
<div class="small-2 columns">
<a class="button postfix" ng-click="login()">Login!</a>
</div>
</div>
</div>
</fieldset>
</div>
<div class="row" ng-show="loggedEmail">
<div class="large-12 columns">
{{ message }}
You are currently logged in as <code ng-bind="loggedEmail"></code>
</div>
</div>
+54 -19
View File
@@ -11,30 +11,65 @@
</div>
</div>
<div class="row" ng-repeat="value in payload.values">
<div class="columns large-8">
<label >value<input type="text" placeholder="value name" ng-model="value.name"></label>
</div>
<div class="columns large-3">
<label >probability<input type="number" placeholder="value probability" ng-model="value.probability" min="0" max="1" step="0.01"></label>
</div>
<div class="columns large-1">
<br>
<a class="button round tiny" ng-click="removeValue( $index )">-</a>
<div class="row">
<div class="columns large-12">
<fieldset>
<legend>doorman state</legend>
<div class="row">
<div class="columns large-8">
<label >name<input type="text" placeholder="value name" ng-model="value.name"></label>
</div>
<div class="columns large-3">
<label >probability<input type="number" placeholder="value probability" ng-model="value.probability" min="0" max="1" step="0.01"></label>
</div>
<div class="columns large-1">
<br>
<a class="button round tiny" ng-class="{disabled: !isValidValue()}" ng-click="addNewValue()">+</a>
</div>
</div>
<div class="row" ng-repeat="value in payload.values | reverse">
<div class="columns large-8">
<label >value<input type="text" placeholder="value name" ng-model="value.name"></label>
</div>
<div class="columns large-3">
<label >probability<input type="number" placeholder="value probability" ng-model="value.probability" min="0" max="1" step="0.01"></label>
</div>
<div class="columns large-1">
<br>
<a class="button round tiny" ng-click="removeValue( payload.values.length - $index - 1 )">-</a>
</div>
</div>
</fieldset>
</div>
</div>
<div class="row">
<div class="columns large-8">
<label >name<input type="text" placeholder="value name" ng-model="value.name"></label>
</div>
<div class="columns large-3">
<label >probability<input type="number" placeholder="value probability" ng-model="value.probability" min="0" max="1" step="0.01"></label>
</div>
<div class="columns large-12">
<fieldset>
<legend>administrator</legend>
<div class="columns large-1">
<br>
<a class="button round tiny" ng-class="{disabled: !isValidValue()}" ng-click="addNewValue()">+</a>
<div class="row">
<div class="columns large-11">
<label>admin email <input type="text" placeholder="wild cards are allow here" ng-model="newEmail"></label>
</div>
<div class="columns large-1">
<br><a class="button round tiny" ng-click="addEmail()" ng-class="{disabled: !newEmail}">+</a>
</div>
</div>
<div class="row" ng-repeat="email in payload.emails | reverse">
<div class="columns large-11">
<label>admin email <input type="text" ng-disabled="email==user" placeholder="wild cards are allow here" ng-model="email"></label>
</div>
<div class="columns large-1">
<br><a class="button round tiny" ng-click="removeEmail(payload.emails.length - $index -1)" ng-disabled="email==user? 'disabled' : ''">-</a>
</div>
</div>
</fieldset>
</div>
</div>
+8 -1
View File
@@ -1,5 +1,12 @@
@import "settings";
@import url(http://fonts.googleapis.com/css?family=Orbitron:400,900,500,700);
// @import url(http://fonts.googleapis.com/css?family=Orbitron:400,900,500,700);
@font-face {
font-family: 'Orbitron';
font-style: normal;
font-weight: 400;
src: local('Orbitron-Light'), local('Orbitron-Regular'), url(/scss/font/orbitron/HmnHiRzvcnQr8CjBje6GQvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2'), url(/scss/font/orbitron/94ug0rEgQO_WuI_xKJMFc_esZW2xOQ-xsNqO47m55DA.woff) format('woff');
}
h1, h2{
font-family: 'Orbitron', sans-serif;