ocp_registry 0.0.1.alpha → 0.0.5.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/lib/ocp_registry.rb +1 -0
  2. data/lib/ocp_registry/api_controller.rb +106 -16
  3. data/lib/ocp_registry/application_manager.rb +185 -23
  4. data/lib/ocp_registry/cloud_manager/mock/mock.rb +7 -13
  5. data/lib/ocp_registry/common.rb +3 -1
  6. data/lib/ocp_registry/config.rb +5 -1
  7. data/lib/ocp_registry/db/002_create_settings_table.rb +13 -0
  8. data/lib/ocp_registry/db/003_alter_comments_column_in_applications_table.rb +13 -0
  9. data/lib/ocp_registry/db/004_add_from_field_for_settings.rb +13 -0
  10. data/lib/ocp_registry/mail_client.rb +2 -2
  11. data/lib/ocp_registry/models.rb +2 -1
  12. data/lib/ocp_registry/models/registry_application.rb +19 -0
  13. data/lib/ocp_registry/models/registry_setting.rb +7 -0
  14. data/lib/ocp_registry/version.rb +1 -1
  15. data/mail_template/approve_admin.erb +3 -2
  16. data/mail_template/approve_user.erb +3 -4
  17. data/mail_template/cancel_admin.erb +13 -0
  18. data/mail_template/cancel_user.erb +13 -0
  19. data/mail_template/modify.erb +25 -0
  20. data/mail_template/refuse_admin.erb +4 -3
  21. data/mail_template/refuse_user.erb +4 -4
  22. data/mail_template/request_admin.erb +3 -2
  23. data/mail_template/request_user.erb +3 -3
  24. data/public/comment_dialog.css +11 -0
  25. data/public/common.css +34 -71
  26. data/public/head_message.css +11 -0
  27. data/public/images/portrait_admin.png +0 -0
  28. data/public/images/portrait_applicant.png +0 -0
  29. data/public/{jquery-1.10.2.min.js → jquery/jquery-1.10.2.min.js} +0 -0
  30. data/public/{jquery-1.10.2.min.map → jquery/jquery-1.10.2.min.map} +0 -0
  31. data/public/{jquery.json-2.4.min.js → json/jquery.json-2.4.min.js} +0 -0
  32. data/public/page_specific.css +15 -0
  33. data/public/post.css +37 -0
  34. data/public/qTIp/jquery.qtip.min.css +2 -0
  35. data/public/qTIp/jquery.qtip.min.js +3 -0
  36. data/public/tenant_opt_dialog.css +3 -0
  37. data/public/tenant_options.css +18 -0
  38. data/public/util.js +14 -0
  39. data/spec/spec_common.rb +25 -0
  40. data/spec/unit/config_spec.rb +117 -0
  41. data/views/admin_review.erb +306 -0
  42. data/views/applicant_review.erb +223 -0
  43. data/views/apply.erb +84 -133
  44. data/views/base.erb +56 -6
  45. data/views/comment_list.erb +12 -0
  46. data/views/inform_comment_dialog.erb +10 -0
  47. data/views/post.erb +28 -0
  48. data/views/reject_comment_dialog.erb +10 -0
  49. data/views/tenant_options.erb +244 -0
  50. data/views/view.erb +44 -7
  51. metadata +35 -8
  52. data/views/review.erb +0 -141
  53. data/views/show.erb +0 -96
@@ -0,0 +1,223 @@
1
+ <%
2
+ #Expected Passed-in Parameters Below
3
+ data=data
4
+
5
+ #Calculate Useful Variables
6
+ first_version=(nil == data[:registry_settings][1])
7
+
8
+ tenant_info=data
9
+ quotas_origin=Yajl::load(data[:registry_settings][0][:settings])
10
+ quotas_prev= first_version ? nil : (Yajl::load(data[:registry_settings][1][:settings]))
11
+
12
+ message="Admin proposed some modifications on your request. You may ACCEPT or MODIFY it."
13
+
14
+ who='applicant'
15
+ review=true
16
+
17
+ comment_list=get_comment_list_from_data(data)
18
+ %>
19
+
20
+ <div class="top-spacer"></div>
21
+
22
+ <div class="head-message box">
23
+ <%=message%>
24
+ </div>
25
+
26
+ <div id="tenant-opt-dialog" class="dialog tenant-opt-dialog">
27
+ <legend>Edit Your Request</legend>
28
+
29
+ <%=erb :tenant_options, :locals => {
30
+ :who=>who,
31
+ :review=>review,
32
+ :tenant_info=>tenant_info,
33
+ :quotas_origin=>quotas_origin,
34
+ :quotas_prev=>quotas_prev
35
+ } %>
36
+
37
+ <div class="action">
38
+ <button class="hidden inform btn btn-success to-right">Inform Admin</button>
39
+ <div class="hidden"><p>Since you have changed the request, you have to inform admin for his/her agreement. </p></div>
40
+
41
+ <button class="accept btn btn-success to-right">Accept</button>
42
+
43
+ <img class="hidden loading to-right" src="/images/loading.gif" alt="" />
44
+ <button class="hidden cancel btn to-left">Cancel</button>
45
+
46
+ <div class="clear-float"></div>
47
+ </div>
48
+
49
+ </div>
50
+
51
+ <%=erb :comment_list, :locals => {:comment_list=>comment_list} %>
52
+
53
+ <%=erb :inform_comment_dialog%>
54
+
55
+ <script type="text/javascript">
56
+
57
+ var id='<%=data[:id]%>';
58
+ var who='<%=who%>';
59
+
60
+ $(document).ready(init);
61
+
62
+ function init(){
63
+ initInformBtnTooltip();
64
+ initAcceptAction();
65
+ initInformAction();
66
+ initChangeCancelAction();
67
+ initInformDialogConfirmAction();
68
+ initInformDialogCancelAction();
69
+ initChangeQuotasEvent();
70
+ }
71
+
72
+ function initInformBtnTooltip(){
73
+ var $btn=$('#tenant-opt-dialog .action button.inform');
74
+ $btn.qtip({
75
+ content: {
76
+ text: $btn.next('div')
77
+ },
78
+ show: {
79
+ effect: function() {
80
+ $btn.fadeTo(200, 1);
81
+ }
82
+ },
83
+ hide: {
84
+ effect: function() {
85
+ $btn.fadeTo(200, 0);
86
+ }
87
+ }
88
+ });
89
+ }
90
+
91
+ function initAcceptAction(){
92
+ $('#tenant-opt-dialog .action button.accept').click(function(){
93
+ $.noty.closeAll();
94
+
95
+ $('#tenant-opt-dialog .action button.accept').text("Loading ...");
96
+ $('#tenant-opt-dialog .action button').attr('disabled', 'true');
97
+ $('#tenant-opt-dialog .action img.loading').show();
98
+
99
+ var url='/v1/applications/'+id+'/settings';
100
+ var data={
101
+ from: who
102
+ };
103
+ data=$.toJSON(data);
104
+
105
+ $.post(url, data, 'json').done(function(data){
106
+ setTimeout(function(){
107
+ data = $.parseJSON(data);
108
+
109
+ if(data.status&&data.status=='error'){
110
+ noty({text: 'Failed to Submit: '+(data.message?data.message:'Unknown Error'), type:'error'});
111
+
112
+ $('#tenant-opt-dialog .action img.loading').hide();
113
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
114
+ $('#tenant-opt-dialog .action button.accept').text('Accept');
115
+
116
+ }else{
117
+ noty({text: 'Successfully Submitted Your Decision [ACCEPT] ! You May CLOSE the Window Now.', type:'success'});
118
+
119
+ $('#tenant-opt-dialog .action img.loading').hide();
120
+ $('#tenant-opt-dialog .action button.accept').text("Complete");
121
+ $('#tenant-opt-dialog .action button.back').removeAttr('disabled').show();
122
+ }
123
+
124
+ }, 2000);
125
+ }).fail(function(){
126
+ setTimeout(function(){
127
+ noty({text: 'Failed to Submit: Server Error. You May Retry Later.', type:'error'});
128
+
129
+ $('#tenant-opt-dialog .action img.loading').hide();
130
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
131
+ $('#tenant-opt-dialog .action button.accept').text('Accept');
132
+ }, 2000);
133
+
134
+ });//end of fail()
135
+
136
+ });//end of click()
137
+ }
138
+
139
+ function initChangeQuotasEvent(){
140
+ tenantOpts.onChange=function(){
141
+ $.noty.closeAll();
142
+ noty({text: "The Request Has Been Changed. You Need to 'Inform Admin' for His/Her Agreement."});
143
+
144
+ $('#tenant-opt-dialog .action button').hide();
145
+ $('#tenant-opt-dialog .action button.cancel').show();
146
+ $('#tenant-opt-dialog .action button.inform').show();
147
+ };
148
+
149
+ tenantOpts.onRestore=function(){
150
+ $('#tenant-opt-dialog .action button').hide();
151
+ $('#tenant-opt-dialog .action button.accept').show();
152
+ };
153
+ }
154
+
155
+ function initInformAction(){
156
+ $('#tenant-opt-dialog .action button.inform').click(function(){
157
+ $('#tenant-opt-dialog .action button').attr('disabled', 'true');
158
+ $('#inform-dialog').modal();
159
+ });
160
+ }
161
+
162
+ function initChangeCancelAction(){
163
+ $('#tenant-opt-dialog .action button.cancel').click(function(){
164
+ tenantOpts.restore();
165
+ });
166
+ }
167
+
168
+ function initInformDialogConfirmAction(){
169
+ $('#inform-dialog .action button.confirm').click(function(){
170
+ $.noty.closeAll();
171
+ $('#inform-dialog').modal('hide');
172
+
173
+ $('#tenant-opt-dialog .action button.inform').text("Loading ...");
174
+ $('#tenant-opt-dialog .action button').attr('disabled', 'true');
175
+ $('#tenant-opt-dialog .action img.loading').show();
176
+
177
+ var url='/v1/applications/'+id+'/settings';
178
+ var data={
179
+ from: who,
180
+ comments: $('#inform-dialog textarea[name=comment]').val(),
181
+ settings: tenantOpts.getQuotasNow()
182
+ };
183
+ data=$.toJSON(data);
184
+
185
+ $.post(url, data, 'json').done(function(data){
186
+ setTimeout(function(){
187
+ data = $.parseJSON(data);
188
+ if(data.status&&data.status=='error'){
189
+ noty({text: 'Failed to Submit: '+(data.message?data.message:'Unknown Error'), type:'error'});
190
+
191
+ $('#tenant-opt-dialog .action img.loading').hide();
192
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
193
+ $('#tenant-opt-dialog .action button.inform').text('Inform Admin');
194
+
195
+ }else{
196
+ noty({text: 'Successfully Submitted Your New Request! You May CLOSE the Window Now.', type:'success'});
197
+
198
+ $('#tenant-opt-dialog .action img.loading').hide();
199
+ $('#tenant-opt-dialog .action button.inform').text("Complete");
200
+ }
201
+
202
+ }, 2000);
203
+ }).fail(function(){
204
+ setTimeout(function(){
205
+ noty({text: 'Failed to Submit: Server Error. You May Retry Later.', type:'error'});
206
+
207
+ $('#tenant-opt-dialog .action img.loading').hide();
208
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
209
+ $('#tenant-opt-dialog .action button.inform').text('Inform Admin');
210
+ }, 2000);
211
+
212
+ });//end of fail()
213
+ });//end of click();
214
+ }
215
+
216
+ function initInformDialogCancelAction(){
217
+ $('#inform-dialog .action button.cancel').click(function(){
218
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
219
+ $('#inform-dialog').modal('hide');
220
+ });
221
+ }
222
+
223
+ </script>
@@ -1,134 +1,85 @@
1
-
2
- <div class="bordered optDialog">
3
- <legend>Create Project</legend>
4
-
5
- <%=erb :show, :locals => {:data=>data, :readonly=>false} %>
6
-
7
- <div class="optAction" id="optAction">
8
- <button id="optSubmit" type="button" class="btn btn-primary toRight"
9
- data-loading-text="Loading ..."
10
- data-complete-text="Completed!">
11
- Submit</button>
12
- <img class="loadingIcon toRight" id="optActionLoadingIcon" src="/images/loading.gif" alt="" />
13
- <div class="clear"></div>
14
- </div>
15
-
16
- </div>
17
-
18
-
19
- <script type="text/javascript">
20
-
21
- (function(){
22
-
23
- $(document).ready(init);
24
-
25
- function init(){
26
- initOptSubmit();
27
- }
28
-
29
- function initOptSubmit(){
30
- $('#optSubmit').click(function(){
31
- $.noty.closeAll();
32
-
33
- //check the data corrections
34
- var ret=checkTenantFields();
35
- if(!ret.ret){
36
- var fieldNamesStr="";
37
- $.each(ret.fields, function(i, v){
38
- if(i>=ret.fields.length-1){
39
- fieldNamesStr+=v;
40
- }else{
41
- fieldNamesStr+=v+" and ";
42
- }
43
- });
44
-
45
- noty({text: "Field "+fieldNamesStr+" "+((ret.fields.length>1)?"are":"is")+" invalid.", type: 'error'});
46
- return;
47
- }
48
-
49
- //do the submission
50
- submitBtnToLoading();
51
- var data=generateTenantRequest();
52
-
53
- $.post('/v1/applications', data, 'json').done(function(data){
54
- data = $.evalJSON(data);
55
- if(data.status&&data.status=='error'){
56
- //server returned error
57
- noty({text: 'Failed to Submit Your Request: '+(data.message?data.message:'Unknown Error'), type:'error'});
58
- submitBtnToReady();
59
- }else{
60
- noty({text: 'Successfully Submitted Your Request! You Can Close This Window Now.', type:'success'});
61
- submitBtnToComplete();
62
- }
63
- }).fail(function(){
64
- noty({text: 'Failed to Submit Your Request: Connection Error. You May Retry Later.', type:'error'});
65
- submitBtnToReady();
66
- });
67
-
68
- });
69
- }
70
-
71
- function submitBtnToLoading(){
72
- $('#optSubmit').button('loading');
73
- $('#optSubmit').attr('disabled', 'true');
74
- $('#optActionLoadingIcon').show();
75
- }
76
-
77
- function submitBtnToReady(){
78
- $('#optSubmit').button('reset');
79
- $('#optSubmit').removeAttr('disabled');
80
- $('#optActionLoadingIcon').hide();
81
- }
82
-
83
- function submitBtnToComplete(){
84
- //$('#optSubmit').button('complete'); //BUG here: I don't use this. Because this will cause the button to be enabled. I want it to keep disabled.
85
- $('#optSubmit').text("Completed");
86
- $('#optSubmit').attr('disabled', 'true');
87
- $('#optActionLoadingIcon').hide();
88
- }
89
-
90
- function checkTenantFields(){
91
- var project=$('#tenantInfo input[name=project]').val();
92
- var email=$('#tenantInfo input[name=email]').val();
93
-
94
- var result={ret:true, fields:[]};
95
-
96
- if(!project||project.length<=0){
97
- result.ret=false;
98
- result.fields.push("project");
99
- }
100
- if(!email||email.length<=0){
101
- result.ret=false;
102
- result.fields.push("email");
103
- }
104
-
105
- return result;
106
- }
107
-
108
- function generateTenantRequest(){
109
- var data={
110
- project : $('#tenantInfo input[name=project]').val(),
111
- description : $('#tenantInfo input[name=description]').val(),
112
- email : $('#tenantInfo input[name=email]').val(),
113
- settings :
114
- {
115
- metadata_items : $('#quota input[name=metadata_items]').val(),
116
- cores : $('#quota input[name=cores]').val(),
117
- instances : $('#quota input[name=instances]').val(),
118
- injected_files : $('#quota input[name=injected_files]').val(),
119
- injected_file_content_bytes : $('#quota input[name=injected_file_content_bytes]').val(),
120
- volumes : $('#quota input[name=volumes]').val(),
121
- gigabytes : $('#quota input[name=gigabytes]').val(),
122
- ram : $('#quota input[name=ram]').val(),
123
- floating_ips : $('#quota input[name=floating_ips]').val(),
124
- fixed_ips : $('#quota input[name=floating_ips]').val(),
125
- security_groups : $('#quota input[name=security_groups]').val(),
126
- security_group_rules : $('#quota input[name=security_group_rules]').val()
127
- }
128
- };
129
- return $.toJSON( data );
130
- }
131
-
132
- })();
133
-
1
+ <%
2
+ #Expected Passed-in Parameters Below
3
+ data=data
4
+
5
+ #Calculate Useful Variables
6
+ tenant_info=data
7
+ quotas_origin=Yajl::load(data[:registry_settings][0][:settings])
8
+
9
+ who='applicant'
10
+ %>
11
+
12
+ <div class="top-spacer"></div>
13
+
14
+ <div id="tenant-opt-dialog" class="dialog tenant-opt-dialog">
15
+ <legend>Create Project</legend>
16
+
17
+ <%=erb :tenant_options, :locals => {
18
+ :who=>who,
19
+ :review=>false,
20
+ :tenant_info=>tenant_info,
21
+ :quotas_origin=>quotas_origin,
22
+ :quotas_prev=>nil
23
+ } %>
24
+
25
+ <div class="action">
26
+ <button class="accept btn btn-success to-right">Submit</button>
27
+ <img class="hidden loading to-right" src="/images/loading.gif" alt="" />
28
+ <div class="clear-float"></div>
29
+ </div>
30
+
31
+ </div>
32
+
33
+ <script type="text/javascript">
34
+
35
+ $(document).ready(init);
36
+
37
+ function init(){
38
+ initAcceptAction();
39
+ }
40
+
41
+ function initAcceptAction(){
42
+ $('#tenant-opt-dialog .action button.accept').click(function(){
43
+ $.noty.closeAll();
44
+
45
+ $('#tenant-opt-dialog .action button.accept').text("Loading ...");
46
+ $('#tenant-opt-dialog .action button').attr('disabled', 'true');
47
+ $('#tenant-opt-dialog .action img.loading').show();
48
+
49
+ var url='/v1/applications';
50
+ data=$.toJSON(tenantOpts.getData());
51
+
52
+ $.post(url, data, 'json').done(function(data){
53
+ setTimeout(function(){
54
+ data = $.parseJSON(data);
55
+
56
+ if(data.status&&data.status=='error'){
57
+ noty({text: 'Failed to Submit: '+(data.message?data.message:'Unknown Error'), type:'error'});
58
+
59
+ $('#tenant-opt-dialog .action img.loading').hide();
60
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
61
+ $('#tenant-opt-dialog .action button.accept').text('Submit');
62
+
63
+ }else{
64
+ noty({text: 'Successfully Submitted Your Request! You May CLOSE the Window Now.', type:'success'});
65
+
66
+ $('#tenant-opt-dialog .action img.loading').hide();
67
+ $('#tenant-opt-dialog .action button.accept').text("Complete");
68
+ }
69
+
70
+ }, 2000);
71
+ }).fail(function(){
72
+ setTimeout(function(){
73
+ noty({text: 'Failed to Submit: Server Error. You May Retry Later.', type:'error'});
74
+
75
+ $('#tenant-opt-dialog .action img.loading').hide();
76
+ $('#tenant-opt-dialog .action button').removeAttr('disabled');
77
+ $('#tenant-opt-dialog .action button.accept').text('Submit');
78
+ }, 2000);
79
+
80
+ });//end of fail()
81
+
82
+ });//end of click()
83
+ }
84
+
134
85
  </script>
@@ -1,24 +1,74 @@
1
+ <%
2
+ #==== Common Util Libraries ====
3
+
4
+ def get_comment_list_from_data(data)
5
+ comment_list=Array.new;
6
+
7
+ data[:registry_settings].each do |d|
8
+ if (nil==d[:comments]) then
9
+ next
10
+ end
11
+
12
+ comment_list.push({
13
+ #Here a little odd, when the setting is from USER, the comments of the setting is from admin
14
+ :who => d[:from] == "USER" ? 'admin' : 'applicant',
15
+ :text => d[:comments],
16
+ :date => d[:updated_at],
17
+ :highlight => false
18
+ });
19
+ end
20
+
21
+ if(data[:registry_settings][1] && data[:registry_settings][1][:comments]) then
22
+ #if the latest comment does exist, highlight it
23
+ comment_list[0][:highlight]=true
24
+ end
25
+
26
+ return comment_list
27
+ end
28
+
29
+ %>
30
+
1
31
  <!DOCTYPE html>
2
32
  <html>
3
33
  <head>
4
34
  <title></title>
5
35
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <!-- Bootstrap -->
36
+
37
+ <!-- libraries -->
38
+ <script src="/jquery/jquery-1.10.2.min.js"></script>
39
+
7
40
  <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
8
- <link rel="stylesheet" type="text/css" href="/common.css">
9
- <script src="/jquery-1.10.2.min.js"></script>
10
41
  <script src="/bootstrap/js/bootstrap.min.js"></script>
42
+
11
43
  <script type="text/javascript" src="/noty/js/jquery.noty.js"></script>
44
+ <script type="text/javascript" src="/noty/js/themes/default.js"></script>
12
45
  <script type="text/javascript" src="/noty/js/layouts/top.js"></script>
13
46
  <script type="text/javascript" src="/noty/js/layouts/topLeft.js"></script>
14
47
  <script type="text/javascript" src="/noty/js/layouts/topRight.js"></script>
15
48
  <script type="text/javascript" src="/noty/js/layouts/topCenter.js"></script>
16
- <script type="text/javascript" src="/noty/js/themes/default.js"></script>
17
- <script type="text/javascript" src="/jquery.json-2.4.min.js"></script>
49
+
50
+ <script type="text/javascript" src="/qTip/jquery.qtip.min.js"></script>
51
+ <link href="/qTip/jquery.qtip.min.css" rel="stylesheet">
52
+
53
+ <script type="text/javascript" src="/json/jquery.json-2.4.min.js"></script>
54
+
55
+ <!-- mine -->
56
+ <link rel="stylesheet" type="text/css" href="/common.css">
57
+ <script type="text/javascript" src="/util.js"></script>
58
+
59
+ <link rel="stylesheet" type="text/css" href="/tenant_options.css">
60
+ <link rel="stylesheet" type="text/css" href="/post.css">
61
+ <link rel="stylesheet" type="text/css" href="/tenant_opt_dialog.css">
62
+ <link rel="stylesheet" type="text/css" href="/comment_dialog.css">
63
+ <link rel="stylesheet" type="text/css" href="/head_message.css">
64
+
65
+ <link rel="stylesheet" type="text/css" href="/page_specific.css">
66
+
18
67
  </head>
68
+
19
69
  <body>
20
70
  <div class="container">
21
- <%=yield %>
71
+ <%=yield %>
22
72
  </div>
23
73
 
24
74
  </body>