first commit
way too late.
This commit is contained in:
commit
d4f7dc57fc
53 files changed
+3518
No files matched your search
@@ -0,0 +1,28 @@
|
||||
define ["app", "angularAMD"], (app, angularAMD) ->
|
||||
app.controller "ApispecCtrl", ($scope) ->
|
||||
$scope.methods =
|
||||
get: "GET"
|
||||
post: "POST"
|
||||
|
||||
angularAMD.directive "wabMethod", () ->
|
||||
directive =
|
||||
restrict: 'E',
|
||||
scope:
|
||||
method: '@'
|
||||
link: (scope, element) ->
|
||||
scope.methods =
|
||||
get: "GET"
|
||||
put: "PUT"
|
||||
delete: "DELETE"
|
||||
post: "POST"
|
||||
|
||||
template: '<code style="width:5em; display: block; text-align: center;">{{ methods[method] }}</code>'
|
||||
return directive
|
||||
|
||||
angularAMD.directive "wabApi", () ->
|
||||
directive =
|
||||
restrict: 'E',
|
||||
scope:
|
||||
endpoint: '@'
|
||||
template: '<a>/api{{ endpoint }}</a>'
|
||||
return directive
|
||||
@@ -0,0 +1,30 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "DoormanCtrl", ["$scope", "$http","$routeParams","$location", ($scope, $http, $routeParams, $location) ->
|
||||
$scope.doorman = {values: []}
|
||||
$scope.apiurl = "/api/doormen/#{$routeParams.id}"
|
||||
$http.get($scope.apiurl).then((res) ->
|
||||
$scope.doorman = res.data
|
||||
).catch((res) ->
|
||||
if res.status == 404
|
||||
$location.path("/doormen/error/#{res.status}/#{$routeParams.id}")
|
||||
)
|
||||
|
||||
$scope.deleteDoorman = () ->
|
||||
console.log("not yet implemented")
|
||||
|
||||
$scope.validate = ()->
|
||||
ret = 0
|
||||
for val in $scope.doorman.values
|
||||
ret += val.probability
|
||||
return Math.abs(ret - 1.0) < 0.000001
|
||||
|
||||
$scope.updateDoorman = () ->
|
||||
if !$scope.validate()
|
||||
return
|
||||
$http.put($scope.apiurl, $scope.doorman).then((ret)->
|
||||
console.log "update"
|
||||
).catch((res) ->
|
||||
d = 9
|
||||
)
|
||||
]
|
||||
return
|
||||
@@ -0,0 +1,6 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "DoormanErrorCtrl", ["$scope","$routeParams", ($scope, $routeParams) ->
|
||||
$scope.id = $routeParams.id
|
||||
$scope.error = Number($routeParams.error)
|
||||
]
|
||||
return
|
||||
@@ -0,0 +1,9 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "DoormenCtrl",[ "$scope", "$http", ($scope, $http) ->
|
||||
$scope.doormen = []
|
||||
$http.get("/api/doormen").then (res) ->
|
||||
$scope.doormen = res.data.doormen
|
||||
return
|
||||
]
|
||||
|
||||
return
|
||||
@@ -0,0 +1,6 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "HomeCtrl", ($scope) ->
|
||||
$scope.message = "message from home ctrl"
|
||||
return
|
||||
|
||||
return
|
||||
@@ -0,0 +1,57 @@
|
||||
epsilon = 0.0001
|
||||
|
||||
define ["app"], (app) ->
|
||||
app.controller "NewDoormanCtrl", ["$scope", "$http", "$location", ($scope, $http, $location) ->
|
||||
$scope.error = ""
|
||||
$scope.value = {}
|
||||
$scope.payload =
|
||||
name: ""
|
||||
values: []
|
||||
|
||||
$scope.isValidValue = () ->
|
||||
return $scope.value.name and $scope.value.probability
|
||||
|
||||
$scope.addNewValue = () ->
|
||||
if !$scope.isValidValue()
|
||||
return
|
||||
$scope.payload.values.push($scope.value)
|
||||
$scope.value = {name: "", probability: 0}
|
||||
|
||||
$scope.removeValue = (idx) ->
|
||||
$scope.payload.values.splice(idx, 1);
|
||||
|
||||
$scope.getProbabilityRemaining = () ->
|
||||
ret = 0
|
||||
for v in $scope.payload.values
|
||||
ret += v.probability
|
||||
return 1 - ret
|
||||
|
||||
$scope.redirectToDoorman = (doormanLocation) ->
|
||||
$http.get(doormanLocation).then (res) ->
|
||||
id = res.data.id
|
||||
return $location.url("/doormen/#{id}")
|
||||
|
||||
$scope.createDoorman = () ->
|
||||
if not $scope.isDoormanValid()
|
||||
return
|
||||
$http.post("/api/doormen", $scope.payload).
|
||||
then((res, s) ->
|
||||
$scope.redirectToDoorman(res.headers("location"))
|
||||
).catch((res) ->
|
||||
$scope.error = res.data
|
||||
)
|
||||
|
||||
$scope.isDoormanValid = () ->
|
||||
if not $scope.payload.name
|
||||
return false
|
||||
if $scope.payload.values.length < 2
|
||||
return false
|
||||
if Math.abs($scope.getProbabilityRemaining()) > epsilon
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
return
|
||||
]
|
||||
|
||||
return
|
||||
@@ -0,0 +1,6 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "sideBarCtrl", ($scope) ->
|
||||
$scope.message = "Message from MyCtrl1"
|
||||
return
|
||||
|
||||
return
|
||||
Reference in new issue
Block a user