Skip to content

Commit

Permalink
Merge pull request #19 from DigitPaint/features/CTRLOL-358-edit-table
Browse files Browse the repository at this point in the history
Features/ctrlol 358 edit table
  • Loading branch information
stolman-digitpaint authored Apr 19, 2022
2 parents 7271f94 + 028b60e commit 9774bbc
Show file tree
Hide file tree
Showing 52 changed files with 6,109 additions and 1,246 deletions.
190 changes: 107 additions & 83 deletions lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1326,71 +1326,93 @@ any ['get', 'post'] => '/settings/audit/?' => require_role audit => sub {
};

get '/table/?' => require_login sub {

template 'tables' => {
page => 'table',
instances => [rset('Instance')->all],
breadcrumbs => [Crumb( '/table' => 'tables' )],
page => 'table',
instances => [ rset('Instance')->all ],
instance_layouts => var('instances')->all,
instances_object => var('instances'),
groups => GADS::Groups->new(schema => schema)->all,
permission_inputs => GADS::Type::Permissions->permission_inputs,
};
};

any ['get', 'post'] => '/table/:id' => require_role superadmin => sub {
any ['get', 'post'] => '/table/:id/permissions' => require_role superadmin => sub {

my $id = param 'id';
my $user = logged_in_user;
my $layout_edit = $id && var('instances')->layout($id);
my $id = param 'id';
my $layout = $id && var('instances')->layout($id);

$id && !$layout
and error __x "Instance ID {id} not found", id => $id;

if (param 'submit')
{
$layout->set_groups([body_parameters->get_all('permissions')]);

if (process(sub {$layout->write}))
{
return forwardHome(
{ success => 'The table permissions have been updated successfully' }, 'table' );
}
}

template 'table_permissions' => {
page => 'table_permissions',
detail_header => 1,
layout_obj => $layout,
groups => GADS::Groups->new(schema => schema)->all,
}
};

any ['get', 'post'] => '/table/:id/edit' => require_role superadmin => sub {

$id && !$layout_edit
my $id = param 'id';
my $user = logged_in_user;
my $layout = $id && var('instances')->layout($id);

$id && !$layout
and error __x"Instance ID {id} not found", id => $id;

if (param('submit') || param('delete'))
if (param 'submit')
{
if (param 'submit')
if (!$layout)
{
if (!$layout_edit)
{
$layout_edit = GADS::Layout->new(
user => $user,
schema => schema,
config => config,
);
}
$layout_edit->name(param 'name');
$layout_edit->name_short(param 'name_short');
$layout_edit->hide_in_selector(param 'hide_in_selector');
$layout_edit->sort_layout_id(param('sort_layout_id') || undef);
$layout_edit->sort_type(param('sort_type') || undef);
$layout_edit->view_limit_id(param('view_limit_id') || undef);
$layout_edit->set_groups([body_parameters->get_all('permissions')]);
$layout_edit->set_alert_columns([body_parameters->get_all('alert_column')]);

if (process(sub {$layout_edit->write}))
{
# Switch user to new table
my $msg = param('id') ? 'The table has been updated successfully' : 'Your new table has been created successfully';
return forwardHome(
{ success => $msg }, 'table' );
}
$layout = GADS::Layout->new(
user => $user,
schema => schema,
config => config,
);
}
$layout->name(param 'name');
$layout->name_short(param 'name_short');
$layout->hide_in_selector(param 'hide_in_selector');
$layout->sort_layout_id(param('sort_layout_id') || undef);
$layout->sort_type(param('sort_type') || undef);
$layout->view_limit_id(param('view_limit_id') || undef);
$layout->set_alert_columns([body_parameters->get_all('alert_column')]);

if (param 'delete')
if (process(sub {$layout->write}))
{
if (process(sub {$layout_edit->delete}))
{
return forwardHome(
{ success => "The table has been deleted successfully" }, 'table' );
}
# Switch user to new table
my $msg = param('id') ? 'The table has been updated successfully' : 'Your new table has been created successfully';
return forwardHome(
{ success => $msg }, 'table' );
}
}

my $table_name = $id ? $layout_edit->name : 'new table';
my $table_id = $id ? $layout_edit->instance_id : 0;
if (param 'delete')
{
if (process(sub {$layout->delete}))
{
return forwardHome(
{ success => "The table has been deleted successfully" }, 'table' );
}
}

template 'table' => {
page => $id ? 'this_table' : 'table/0',
layout_edit => $layout_edit,
groups => GADS::Groups->new(schema => schema)->all,
breadcrumbs => [Crumb( '/table' => 'tables' ) => Crumb( "/table/$table_id" => $table_name )],
page => 'table_edit',
content_block_custom_classes => 'content-block--footer',
detail_header => 1,
layout_obj => $layout
}
};

Expand Down Expand Up @@ -3208,11 +3230,7 @@ prefix '/:layout_name' => sub {
};

any ['get', 'post'] => '/topic/:id' => require_login sub {

my $layout = var('layout') or pass;

my $user = logged_in_user;

my $layout = var('layout') or pass;
my $instance_id = $layout->instance_id;

forwardHome({ danger => "You do not have permission to manage topics"}, '')
Expand All @@ -3234,7 +3252,7 @@ prefix '/:layout_name' => sub {
$topic->name(param 'name');
$topic->description(param 'description');
$topic->click_to_edit(param 'click_to_edit');
$topic->initial_state(param 'initial_state');
$topic->initial_state(param('initial_state') || 'collapsed');
$topic->prevent_edit_topic_id(param('prevent_edit_topic_id') || undef);

if (process(sub {$topic->update_or_insert}))
Expand All @@ -3245,7 +3263,7 @@ prefix '/:layout_name' => sub {
}
}

if (param 'delete_topic')
if (param 'delete')
{
if (process(sub {$topic->delete}))
{
Expand All @@ -3254,32 +3272,33 @@ prefix '/:layout_name' => sub {
}
}

my $topic_name = $id ? $topic->name : 'new topic';
my $topic_id = $id ? $topic->id : 0;
my $base_url = request->base;
my $tableIdentifier = $layout->identifier;

template 'topic' => {
topic => $topic,
topics => [schema->resultset('Topic')->search({ instance_id => $instance_id })->all],
breadcrumbs => [Crumb($layout) => Crumb( $layout, '/topics' => 'topics' ) => Crumb( $layout, "/topic/$topic_id" => $topic_name )],
page => !$id ? 'topic/0' : 'topics',
}
page => !$id ? 'topic_add' : 'topic_edit',
content_block_custom_classes => 'content-block--footer',
detail_header => 1,
header_back_url => "${base_url}${tableIdentifier}/topics",
layout_obj => $layout,
topic => $topic,
topics => [schema->resultset('Topic')->search({ instance_id => $instance_id })->all],
};
};

get '/topics/?' => require_login sub {

my $layout = var('layout') or pass;

my $user = logged_in_user;

my $instance_id = $layout->instance_id;

forwardHome({ danger => "You do not have permission to manage topics"}, '')
unless $layout->user_can("layout");

template 'topics' => {
layout => $layout,
topics => [schema->resultset('Topic')->search({ instance_id => $instance_id })->all],
breadcrumbs => [Crumb($layout) => Crumb( $layout, '/topics' => 'topics' )],
page => 'topics',
page => 'topics',
content_block_custom_classes => 'content-block--footer',
detail_header => 1,
layout_obj => $layout,
topics => [schema->resultset('Topic')->search({ instance_id => $instance_id })->all],
};
};

Expand Down Expand Up @@ -3380,14 +3399,13 @@ prefix '/:layout_name' => sub {
any ['get', 'post'] => '/layout/?:id?' => require_login sub {

my $layout = var('layout') or pass;

my $user = logged_in_user;
my $user = logged_in_user;

forwardHome({ danger => "You do not have permission to manage fields"}, '')
unless $layout->user_can("layout");

my $params = {
page => defined param('id') && !param('id') ? 'layout/0' : 'layout',
page => defined param('id') && !param('id') ? 'layout' : 'layouts',
};

if (defined param('id'))
Expand All @@ -3397,7 +3415,6 @@ prefix '/:layout_name' => sub {
$params->{instances_object} = var('instances'); # For autocur. Don't conflict with other instances var
}

my $breadcrumbs = [Crumb($layout) => Crumb( $layout, '/layout' => 'fields' )];
if (param('id') || param('submit') || param('update_perms'))
{

Expand All @@ -3419,7 +3436,7 @@ prefix '/:layout_name' => sub {
);
}

if (param 'delete')
if (my $delete_id = param 'delete')
{
# Provide plenty of logging in case of repercussions of deletion
my $colname = $column->name;
Expand Down Expand Up @@ -3528,18 +3545,24 @@ prefix '/:layout_name' => sub {
}
}
$params->{column} = $column;
push @$breadcrumbs, Crumb( $layout, "/layout/".$column->id => 'edit field "'.$column->name.'"' );
}
elsif (defined param('id'))
{
$params->{column} = 0; # New
push @$breadcrumbs, Crumb( $layout, "/layout/0" => 'new field' );
}
$params->{groups} = GADS::Groups->new(schema => schema);
$params->{permissions} = [GADS::Type::Permissions->all];
$params->{permission_mapping} = GADS::Type::Permissions->permission_mapping;
$params->{permission_inputs} = GADS::Type::Permissions->permission_inputs;
$params->{topics} = [schema->resultset('Topic')->search({ instance_id => $layout->instance_id })->all];

my $base_url = request->base;
my $tableIdentifier = $layout->identifier;

$params->{groups} = GADS::Groups->new(schema => schema);
$params->{permissions} = [GADS::Type::Permissions->all];
$params->{permission_mapping} = GADS::Type::Permissions->permission_mapping;
$params->{permission_inputs} = GADS::Type::Permissions->permission_inputs;
$params->{topics} = [schema->resultset('Topic')->search({ instance_id => $layout->instance_id })->all];
$params->{content_block_custom_classes} = 'content-block--footer';
$params->{detail_header} = 1;
$params->{header_back_url} = "${base_url}${tableIdentifier}/layout";
$params->{layout_obj} = $layout;

if (param 'saveposition')
{
Expand All @@ -3551,8 +3574,9 @@ prefix '/:layout_name' => sub {
}
}

$params->{breadcrumbs} = $breadcrumbs;
template 'layout' => $params;
my $page = defined param('id') ? 'layout' : 'layouts';

template $page => $params;
};

any ['get', 'post'] => '/approval/?:id?' => require_login sub {
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ sub _post_add_user_account
my $update_user;
if ($id)
{
$update_user = schema->resultset('User')->active->find($id)
$update_user = schema->resultset('User')->find($id)
or error __x"User id {id} not found", id => $id;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/GADS/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ sub update_user
account_request_notes => $params{account_request_notes},
};

if(defined $params{account_request}) {
$values->{account_request} = $params{account_request};
}

foreach my $field ($site->user_fields)
{
next if !exists $params{$field->{name}};
Expand Down Expand Up @@ -1052,4 +1056,3 @@ sub export_hash
}

1;

830 changes: 827 additions & 3 deletions public/css/external.css

Large diffs are not rendered by default.

366 changes: 363 additions & 3 deletions public/css/general.css

Large diffs are not rendered by default.

Binary file added public/images/sprite-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
470 changes: 431 additions & 39 deletions public/js/site.js

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions views/admin/default_welcome_email.tt
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,28 @@
%]
</div>
</div>
[%-
back_url = url.page _ "/user_overview/";
[%
INCLUDE navigation/button_bar.tt
row_class="row"
back_url=back_url
submit_name="update"
submit_value="update"
submit_label="Save";
-%]
row_class = "row"
columns = [{
class = "col-sm-auto mb-3 mb-sm-0",
buttons = [{
type = "link",
class = "btn btn-cancel",
target = url.page _ "/user_overview/",
label = "Back"
}]
}, {
class = "col-sm-auto",
buttons = [{
type = "button",
name = "update",
value = "update",
class = "btn btn-default",
label = "Save"
}]
}];
%]
</fieldset>
</form>
</div>
Expand Down
30 changes: 21 additions & 9 deletions views/admin/user_editable_personal_details.tt
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,28 @@
</fieldset>
</div>
</div>

[%-
back_url = url.page _ "/user_overview/";
[%
INCLUDE navigation/button_bar.tt
row_class="row"
back_url=back_url
submit_name="update"
submit_value="update"
submit_label="Save";
-%]
row_class = "row"
columns = [{
class = "col-sm-auto mb-3 mb-sm-0",
buttons = [{
type = "link",
class = "btn btn-cancel",
target = url.page _ "/user_overview/",
label = "Back"
}]
}, {
class = "col-sm-auto",
buttons = [{
type = "button",
name = "update",
value = "update",
class = "btn btn-default",
label = "Save"
}]
}];
%]
</form>
</div>
</div>
Loading

0 comments on commit 9774bbc

Please sign in to comment.