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

+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
]