set default project and studio at user settings

This commit is contained in:
Milan
2018-10-14 00:05:04 +02:00
parent a949cea7bd
commit eaaea81ed4
7 changed files with 68 additions and 23 deletions

View File

@@ -1020,6 +1020,8 @@ CREATE TABLE `calcms_user_settings` (
`language` varchar(3) DEFAULT 'de',
`period` varchar(16) DEFAULT 'month',
`calendar_fontsize` smallint(5) unsigned DEFAULT '12',
`project_id` INT(10) UNSIGNED NULL,
`studio_id` INT(10) UNSIGNED NULL,
PRIMARY KEY (`id`,`user`) USING BTREE,
KEY `user` (`user`)
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;

View File

@@ -243,3 +243,7 @@ ALTER TABLE `calcms`.`calcms_user_stats`
ADD COLUMN `upload_file` INT(10) UNSIGNED NULL DEFAULT 0 AFTER `delete_series`,
ADD COLUMN `download_file` INT(10) UNSIGNED NULL DEFAULT 0 AFTER `upload_file`;
ALTER TABLE `calcms`.`calcms_user_settings`
ADD COLUMN `project_id` INT(10) UNSIGNED NULL AFTER `calendar_fontsize`,
ADD COLUMN `studio_id` INT(10) UNSIGNED NULL AFTER `project_id`;

View File

@@ -664,6 +664,10 @@ sub get_user_presets {
my $studio_id = $options->{studio_id} || '';
$config->{access}->{write} = 0;
my $user_settings = user_settings::get( $config, { user => $user } );
$project_id = $user_settings->{project_id} if $project_id eq '';
$studio_id = $user_settings->{studio_id} if $studio_id eq '';
#get
my $admin_roles = get_admin_user_roles( $config, { user => $user } );
@@ -688,8 +692,6 @@ sub get_user_presets {
$project_id = $projects->[0]->{project_id};
}
#print STDERR "project:$project_id\n";
#check if studios are assigned to project
my $studios = project::get_studios( $config, { project_id => $project_id } );
$error = "no studio is assigned to project" if scalar @$studios == 0;
@@ -709,7 +711,7 @@ sub get_user_presets {
}
$error = "studio is not assigned to user" if ( $studioFound == 0 );
} else {
$studio_id = $studios->[0]->{id};
$studio_id = $studios->[0]->{id} unless defined $studio_id;
}
} else {
@@ -725,7 +727,7 @@ sub get_user_presets {
}
$error = "studio is not assigned to project" if ( $studioFound == 0 );
} else {
$studio_id = $studios->[0]->{id};
$studio_id = $studios->[0]->{id} unless defined $studio_id;
}
}

View File

@@ -166,9 +166,6 @@ sub get {
$conditions
};
#print $query."\n";
#print Dumper(\@bind_values);
my $entries = db::get( $dbh, $query, \@bind_values );
return $entries->[0] || undef;
}
@@ -178,7 +175,6 @@ sub insert {
my $entry = shift;
return unless ( defined $entry->{user} );
return unless ( defined $entry->{colors} );
my $dbh = db::connect($config);
return db::insert( $dbh, 'calcms_user_settings', $entry );
}
@@ -188,7 +184,6 @@ sub update {
my $entry = shift;
return unless ( defined $entry->{user} );
return unless ( defined $entry->{colors} );
my $dbh = db::connect($config);
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
@@ -200,6 +195,7 @@ sub update {
set $values
where user=?
};
#print STDERR Dumper($query).Dumper(\@bind_values);
db::put( $dbh, $query, \@bind_values );
print "done\n";
}
@@ -219,7 +215,6 @@ sub delete {
};
my $bind_values = [ $entry->{user} ];
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
db::put( $dbh, $query, $bind_values );
}

View File

@@ -7,6 +7,12 @@ msgstr "Einstellungen"
msgid "label_language"
msgstr "Sprache"
msgid "label_studio"
msgstr "Studio"
msgid "label_project"
msgstr "Projekt"
msgid "label_color"
msgstr "Farbe"
@@ -76,3 +82,5 @@ msgstr "Passwort (Wiederholung)"
msgid "password_hint"
msgstr "mindestens 8 Zeichen und (kleine und große Buchstaben, Zahlen und Sonderzeichen)"
msgid "setDefaultProjectStudio"
msgstr "Projekt und Studio als Default setzen"

View File

@@ -7,6 +7,12 @@ msgstr "user settings"
msgid "label_language"
msgstr "language"
msgid "label_studio"
msgstr "Studio"
msgid "label_project"
msgstr "Project"
msgid "label_color"
msgstr "color"
@@ -75,3 +81,6 @@ msgstr "Password (repeat)"
msgid "password_hint"
msgstr "at least 8 characters (small and big characters, numbers and special characters)"
msgid "setDefaultProjectStudio"
msgstr "set project and studio for default"

View File

@@ -56,6 +56,7 @@ our $errors = [];
if ( defined $params->{action} ) {
update_settings( $config, $request ) if ( $params->{action} eq 'save' );
updateDefaultProjectStudio( $config, $request ) if ( $params->{action} eq 'updateDefaultProjectStudio' );
}
$config->{access}->{write} = 0;
show_settings( $config, $request );
@@ -103,17 +104,39 @@ sub show_settings {
$params->{loc} = localization::get( $config, { language => $language, file => 'user_settings' } );
#print STDERR Dumper($params->{loc});
for my $color ( @{ $params->{colors} } ) {
$color->{title} = $params->{loc}->{ $color->{title} };
}
uac::set_template_permissions( $permissions, $params );
#print Dumper($permissions);
template::process( $config, 'print', $params->{template}, $params );
}
#print '<pre>'.Dumper($user_settings);
sub updateDefaultProjectStudio {
my $config = shift;
my $request = shift;
my $params = $request->{params}->{checked};
my $permissions = $request->{permissions};
my $user = $params->{presets}->{user};
my $settings = {
user => $user,
project_id => $params->{project_id},
studio_id => $params->{studio_id},
};
my $results = user_settings::get( $config, { user => $user } );
if ( defined $results ) {
uac::print_info("update project and studio settings");
$config->{access}->{write} = 1;
user_settings::update( $config, $settings );
} else {
uac::print_info("insert user settings, as missing on updating default project and studio");
update_settings($config, $request);
}
$config->{access}->{write} = 0;
}
sub update_settings {
@@ -137,20 +160,22 @@ sub update_settings {
}
my $settings = {
user => $user,
colors => join( "\n", @colors ),
language => $params->{language},
period => $params->{period}
user => $user,
colors => join( "\n", @colors ),
language => $params->{language},
period => $params->{period},
};
my $results = user_settings::get( $config, { user => $user } );
if ( defined $results ) {
uac::print_info("update");
if ( defined $results ) {
uac::print_info("update user settings");
$config->{access}->{write} = 1;
user_settings::update( $config, $settings );
} else {
$config->{access}->{write} = 1;
uac::print_info("insert");
uac::print_info("insert user settings");
$settings->{project_id} = $params->{project_id};
$settings->{studio_id} = $params->{studio_id};
user_settings::insert( $config, $settings );
}
$config->{access}->{write} = 0;
@@ -168,7 +193,7 @@ sub check_params {
$checked->{template} = $template;
#numeric values
for my $param ( 'project_id', 'default_studio_id', 'studio_id' ) {
for my $param ( 'project_id', 'default_studio_id', 'studio_id', 'default_studio', 'default_project' ) {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
$checked->{$param} = $params->{$param};
}
@@ -198,7 +223,7 @@ sub check_params {
#actions
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(save)$/ ) {
if ( $params->{action} =~ /^(save|updateDefaultProjectStudio)$/ ) {
$checked->{action} = $params->{action};
}
}