Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
immerda
Immerda Apps
users
Commits
bcccea4d
Commit
bcccea4d
authored
Oct 13, 2020
by
o
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resource creation according to schema
parent
be709b97
Pipeline
#4141
failed with stages
in 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
14 deletions
+29
-14
app/controllers/concerns/api_backend.rb
app/controllers/concerns/api_backend.rb
+4
-0
app/controllers/resources_admin_controller.rb
app/controllers/resources_admin_controller.rb
+11
-10
app/views/resources_admin/show.html.erb
app/views/resources_admin/show.html.erb
+14
-4
No files found.
app/controllers/concerns/api_backend.rb
View file @
bcccea4d
...
...
@@ -340,6 +340,10 @@ module ApiBackend
get
[
'resource'
,
'mine'
]
end
def
resource_schema
(
what
)
get
[
'resource'
,
'schema'
],
{
resource_type:
what
}
end
def
resource_list
(
what
,
deleted
=
false
)
get
[
'resource'
,
'list'
],
{
resource_type:
what
,
deleted:
deleted
}
end
...
...
app/controllers/resources_admin_controller.rb
View file @
bcccea4d
...
...
@@ -4,22 +4,17 @@ class ResourcesAdminController < ApplicationController
def
resource_list
[
'schleuder'
,
'mailman'
]
end
def
resource_default
case
@resource_name
when
'mailman'
'{"listenname": "", "listendomain": "", "mailman_host": ""}'
when
'schleuder'
'{"name": "", "domain": "", "schleuder_host": ""}'
end
end
helper_method
:resource_list
,
:resource_default
helper_method
:resource_list
def
show
@resource_name
=
params
[
'resource_name'
]
if
resource_list
.
include?
@resource_name
begin
@resource_schema
=
api
.
resource_schema
(
@resource_name
)[
'schema'
]
@resources
=
api
.
resource_list
(
@resource_name
)[
'data'
]
@resources
.
sort!
{
|
a
,
b
|
a
[
'uid'
]
<=>
b
[
'uid'
]}
@deleted_resources
=
api
.
resource_list
(
@resource_name
,
true
)[
'deleted'
]
@deleted_resources
.
sort!
{
|
a
,
b
|
a
[
'uid'
]
<=>
b
[
'uid'
]}
rescue
ApiBackend
::
ApiError
flash
[
:danger
]
=
:failed
redirect_to
root_path
...
...
@@ -39,10 +34,16 @@ class ResourcesAdminController < ApplicationController
when
'create'
@resource_name
=
params
[
:resource_name
]
if
resource_list
.
include?
@resource_name
data
=
{}
params
.
each
do
|
name
,
v
|
if
name
=~
/data_(.*)/
data
[
$1
]
=
v
end
end
@res
=
api
.
resource_create
(
@resource_name
,
params
[
:owner
],
JSON
.
parse
(
params
[
:
data
])
)
data
)
end
when
'save'
if
params
[
'add_owner'
].
present?
...
...
app/views/resources_admin/show.html.erb
View file @
bcccea4d
...
...
@@ -4,13 +4,22 @@
<%
end
%>
<hr
/>
<%
if
@resource
s
%>
<%
if
@resource
_name
%>
<h4>
New:
</h4>
<%=
form_tag
do
%>
<%=
hidden_field_tag
'resource_name'
,
@resource_name
%>
<%=
label_tag
'data'
%>
<%=
text_field_tag
'data'
,
resource_default
,
size:
400
%>
<%
@resource_schema
.
each
do
|
n
,
v
|
%>
<%=
label_tag
n
%>
<%=
case
v
when
'text'
text_field_tag
'data_'
+
n
when
Array
select_tag
'data_'
+
n
,
options_for_select
(
v
)
end
%>
<br
/>
<%
end
%>
<%=
label_tag
'owner'
%>
<%=
text_field_tag
'owner'
%>
...
...
@@ -19,6 +28,7 @@
<%
end
%>
<hr
/>
<h4>
Existing:
</h4>
<%
@resources
.
each
do
|
res
|
%>
<%=
form_tag
do
%>
<%=
hidden_field_tag
'uid'
,
res
[
'uid'
]
%>
...
...
@@ -44,7 +54,7 @@
<hr
/>
<%
end
%>
<h
3
>
Deleted:
</h
3
>
<h
4
>
Deleted:
</h
4
>
<%
@deleted_resources
.
each
do
|
res
|
%>
<%=
form_tag
do
%>
<%=
hidden_field_tag
'uid'
,
res
[
'uid'
]
%>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment