-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwplanet.eliom
98 lines (80 loc) · 2.46 KB
/
wplanet.eliom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(** This module defines every Planet-related widgets *)
{shared{
open Eliom_lib
open Eliom_content.Html5
}}
open Skeleton
open Auth
open EvePI_db
open Utility
open F
let icon ?(a=[]) ?name typ =
let name = Option.to_list (Option.map a_title name) in
D.i ~a:((a_class [typ;"planet"]) :: (a_draggable true) :: name @ a) []
(** {3 Delete a planet} *)
let delete_service =
Eliom_service.App.post_coservice'
~post_params:Eliom_parameter.(int64 "planet") ()
let delete_link planet =
Raw.a ~a:[
a_title "Delete this planet" ;
a_class ["link"] ;
a_onclick {{
fun _ -> Eliom_client.exit_to
~service:%delete_service () (%planet)
}}]
[Bootstrap.icon ~white:true "remove"]
let _ =
Wrap.action_register
~service:delete_service
(fun user () planet ->
(* Only the user himself can delete his planets *)
lwt is_user = QPlanet.is_attached planet user.id in
if is_user then
QPlanet.delete planet
else
Lwt.return ()
)
(** {3 Change the project of a planet} *)
let change_project_service =
Eliom_service.App.post_coservice'
~post_params:Eliom_parameter.(int64 "planet" ** int64 "project") ()
let change_project_link planet (project_id,project_name) =
Raw.a ~a:[
a_class ["link"] ;
a_onclick {{
fun _ -> Eliom_client.exit_to
~service:%change_project_service () (%planet,%project_id)
}}]
[pcdata project_name]
let _ =
Wrap.action_register
~service:change_project_service
(fun user () (planet,project) ->
(* Only the user himself can change the project of his planets *)
lwt is_user = QPlanet.is_attached planet user.id in
if is_user then
QPlanet.update_project planet project
else
Lwt.return ()
)
(** {3 Change the production of a planet} *)
let specialize_service =
Eliom_service.App.post_coservice'
~post_params:Eliom_parameter.(int64 "planet" ** int64 "product") ()
let specialize (user,planet,product) =
(* Only the admin of the project can specialize a planet *)
(* FIXME may be desirable to do a single request with a join here *)
lwt planet_info = QPlanet.get_info planet in
let project = Sql.getn planet_info#project in
lwt is_admin = Option.map_lwt (fun p -> QAdmin.verify p user) project in
if is_admin = Some true then
QPlanet.update_product planet product
else
Lwt.return ()
let _ =
Wrap.unit_register
~service:specialize_service
(fun user () (planet,product) ->
specialize (user.id,planet,product)
)