so mamy things...
This commit is contained in:
1 parent
f7a8d416c1
commit
78d50d9a6d
24 files changed
+516
-173
No files matched your search
@@ -25,8 +25,8 @@ define ["app", "angularAMD"], (app, angularAMD) ->
|
||||
|
||||
angularAMD.directive "wabApi", () ->
|
||||
directive =
|
||||
restrict: 'E',
|
||||
scope:
|
||||
endpoint: '@'
|
||||
template: '<a>/api{{ endpoint }}</a>'
|
||||
restrict: 'E',
|
||||
scope:
|
||||
endpoint: '@'
|
||||
template: '<a>/api{{ endpoint }}</a>'
|
||||
return directive
|
||||
@@ -1,6 +1,8 @@
|
||||
define ["app", "lodash"], (app, _) ->
|
||||
define ["app", "lodash", "directives/ratinput"], (app, _, ratinput) ->
|
||||
|
||||
app.controller "DoormanCtrl", ["$scope", "$http","$routeParams","$location", ($scope, $http, $routeParams, $location) ->
|
||||
$scope.doorman = {values: []}
|
||||
$scope.somevalue = "2/6"
|
||||
$scope.apiurl = "/api/doormen/#{$routeParams.id}"
|
||||
$scope.user = localStorage.getItem("email")
|
||||
|
||||
@@ -20,10 +22,18 @@ define ["app", "lodash"], (app, _) ->
|
||||
$scope.initEmails = () ->
|
||||
[$scope.leftEmailColumns, $scope.rightEmailColumns] = _.chunk($scope.doorman.emails, 2)
|
||||
|
||||
$scope.rationalToFloat = (rat) ->
|
||||
if _.contains(rat, "/")
|
||||
num = Number(rat.substr(0, rat.indexOf("/")))
|
||||
denum = Number(rat.substr(rat.indexOf("/") + 1))
|
||||
return num / denum
|
||||
Number(rat)
|
||||
|
||||
|
||||
$scope.validate = ()->
|
||||
ret = 0
|
||||
for val in $scope.doorman.values
|
||||
ret += val.probability
|
||||
ret += $scope.rationalToFloat(val.probability)
|
||||
return Math.abs(ret - 1.0) < 0.000001
|
||||
|
||||
$scope.addNewAuthorEmail = () ->
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
define ["app"], (app) ->
|
||||
app.controller "HomeCtrl", ($scope) ->
|
||||
$scope.message = "message from home ctrl"
|
||||
$scope.loggedEmail = localStorage.getItem("email")
|
||||
app.controller "HomeCtrl", ['$scope', '$rootScope', ($scope, $rootScope) ->
|
||||
$scope.init = () ->
|
||||
$scope.loggedEmail = localStorage.getItem("email")
|
||||
|
||||
$scope.login = () ->
|
||||
if $scope.email
|
||||
localStorage.setItem("email", $scope.email)
|
||||
$scope.loggedEmail = $scope.email
|
||||
$scope.email = ""
|
||||
$scope.$emit("login")
|
||||
|
||||
return
|
||||
$scope.init()
|
||||
$rootScope.$on('logout', $scope.init)
|
||||
]
|
||||
@@ -1,10 +1,10 @@
|
||||
epsilon = 0.0001
|
||||
|
||||
define ["app", "../filters"], (app, filters) ->
|
||||
app.controller "NewDoormanCtrl", ["$scope", "$http", "$location", ($scope, $http, $location) ->
|
||||
define ["app", "lodash", "../filters", "directives/ratinput"], (app, _, filters, ratinput) ->
|
||||
app.controller "NewDoormanCtrl", ["$scope", "$http", "$location", "rationals", ($scope, $http, $location, rationals) ->
|
||||
$scope.error = ""
|
||||
$scope.user = localStorage.getItem("email")
|
||||
$scope.value = {probability: 0, name: ""}
|
||||
$scope.value = {probability: "1", name: ""}
|
||||
$scope.payload =
|
||||
name: ""
|
||||
values: []
|
||||
@@ -17,27 +17,34 @@ define ["app", "../filters"], (app, filters) ->
|
||||
if !$scope.isValidValue()
|
||||
return
|
||||
$scope.payload.values.push($scope.value)
|
||||
$scope.value = {name: "", probability: 0}
|
||||
$scope.value =
|
||||
name: ""
|
||||
probability: $scope.getProbabilityRemaining()
|
||||
|
||||
$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
|
||||
sum = rationals.sum(_.pluck($scope.payload.values, "probability")...)
|
||||
return rationals.minus("1", sum)
|
||||
|
||||
|
||||
$scope.redirectToDoorman = (doormanLocation) ->
|
||||
$http.get(doormanLocation).then (res) ->
|
||||
id = res.data.id
|
||||
return $location.url("/doormen/#{id}")
|
||||
|
||||
$scope.getPayload = () ->
|
||||
payload = _.cloneDeep($scope.payload)
|
||||
for value in payload.values
|
||||
value.probability = value.probability
|
||||
return payload
|
||||
|
||||
$scope.createDoorman = () ->
|
||||
if not $scope.isDoormanValid()
|
||||
return
|
||||
params = {params: {user: $scope.user}}
|
||||
$http.post("/api/doormen", $scope.payload, params).
|
||||
$http.post("/api/doormen", $scope.getPayload(), params).
|
||||
then((res, s) ->
|
||||
$scope.redirectToDoorman(res.headers("location"))
|
||||
).catch((res) ->
|
||||
@@ -49,9 +56,8 @@ define ["app", "../filters"], (app, filters) ->
|
||||
return false
|
||||
if $scope.payload.values.length < 2
|
||||
return false
|
||||
if Math.abs($scope.getProbabilityRemaining()) > epsilon
|
||||
return false
|
||||
return true
|
||||
rationals.equal($scope.getProbabilityRemaining(), "0" )
|
||||
|
||||
|
||||
$scope.addEmail = () ->
|
||||
if not $scope.newEmail
|
||||
@@ -64,6 +70,10 @@ define ["app", "../filters"], (app, filters) ->
|
||||
return
|
||||
$scope.payload.emails.splice(idx, 1);
|
||||
|
||||
$scope.getSum = () ->
|
||||
probs = _.pluck($scope.payload.values, "probability")
|
||||
return rationals.pp(rationals.sum(probs...))
|
||||
|
||||
|
||||
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user