forked from BrainCOGS/U19-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BrainCOGS#15 from Alvalunasan/master
GUI to add lab users to database
- Loading branch information
Showing
20 changed files
with
1,281 additions
and
8 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
database/AddLabUsers/@DataJointLabUserTable/DataJointLabUserTable.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
classdef DataJointLabUserTable | ||
% DataJointLabUserTable Summary of DataJointLabUserTable | ||
% Define a simple interface to define records to be added for specific | ||
% tables | ||
% | ||
% DataJointLabUserTable main Properties: | ||
% GUI_info - structure with information for each field of the tables | ||
% that will update for defining the GUI | ||
% tables_info - reference for all the tables that will be updated | ||
% | ||
% DataJointLabUserTable Methods: | ||
% get_GUI_table_info(obj,parent) - Function that defines two structures with information about tables that | ||
% will be updated | ||
% insert_user(obj, all_values_insert) - Function that calls database to insert record in tables referenced in | ||
% table_info structure | ||
% get_values_table_field(~, table, field, sort_limit) -Function to get specific fields from table | ||
properties (Constant) | ||
|
||
%dj_conn = getdjconnection('u19_', 'datajoint00.pni.princeton.edu'); | ||
|
||
end | ||
|
||
%_________________________________________________________________________________________________ | ||
properties (SetAccess = protected) | ||
|
||
GUI_info | ||
tables_info | ||
|
||
end | ||
|
||
%_________________________________________________________________________________________________ | ||
methods | ||
|
||
[GUI_info, tables_update] = get_GUI_table_info(obj); | ||
example_value = get_values_table_field(obj, table, field, sort_limit); | ||
insert_user(obj, all_values_insert); | ||
|
||
function obj = DataJointLabUserTable() | ||
%----- Class constructor, defining structures | ||
|
||
[obj.GUI_info, obj.tables_info] = obj.get_GUI_table_info(); | ||
|
||
|
||
end | ||
|
||
end | ||
|
||
|
||
end |
172 changes: 172 additions & 0 deletions
172
database/AddLabUsers/@DataJointLabUserTable/get_GUI_table_info.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
function [GUI_info, tables_update] = get_GUI_table_info(obj) | ||
% Function that defines two structures with information about tables that | ||
% will be updated | ||
% correct | ||
% Inputs: | ||
% obj = DataJointLabUserTable object | ||
% | ||
% Outputs | ||
% GUI_info = structure with information for each field of the tables | ||
% that will update for defining the GUI | ||
% tables_update = reference for all the tables that will be updated | ||
|
||
|
||
%Create GUI_info structure with information for all fields | ||
GUI_info(1).name = 'user_id'; | ||
GUI_info(1).gui_type = 'edit'; | ||
GUI_info(1).datatype = 'string'; | ||
GUI_info(1).default = ''; | ||
GUI_info(1).list_values = {}; | ||
GUI_info(1).example_value = ''; | ||
GUI_info(1).tooltip = 'username'; | ||
|
||
GUI_info(2).name = 'user_nickname'; | ||
GUI_info(2).gui_type = 'edit'; | ||
GUI_info(2).datatype = 'string'; | ||
GUI_info(2).default = ''; | ||
GUI_info(2).list_values = {}; | ||
GUI_info(2).example_value = ''; | ||
GUI_info(2).tooltip = 'same as netID for new users, for old users, this is used in the folder name etc'; | ||
|
||
GUI_info(3).name = 'full_name'; | ||
GUI_info(3).gui_type = 'edit'; | ||
GUI_info(3).datatype = 'string'; | ||
GUI_info(3).default = ''; | ||
GUI_info(3).list_values = {}; | ||
GUI_info(3).example_value = ''; | ||
GUI_info(3).tooltip = 'first name'; | ||
|
||
GUI_info(4).name = 'email'; | ||
GUI_info(4).gui_type = 'edit'; | ||
GUI_info(4).datatype = 'string'; | ||
GUI_info(4).default = ''; | ||
GUI_info(4).list_values = {}; | ||
GUI_info(4).example_value = ''; | ||
GUI_info(4).tooltip = 'email address'; | ||
|
||
GUI_info(5).name = 'phone'; | ||
GUI_info(5).gui_type = 'edit'; | ||
GUI_info(5).datatype = 'string'; | ||
GUI_info(5).default = ''; | ||
GUI_info(5).list_values = {}; | ||
GUI_info(5).example_value = ''; | ||
GUI_info(5).tooltip = 'phone number'; | ||
|
||
GUI_info(6).name = 'mobile_carrier'; | ||
GUI_info(6).gui_type = 'popupmenu'; | ||
GUI_info(6).datatype = 'string'; | ||
GUI_info(6).default = ''; | ||
GUI_info(6).list_values = obj.get_values_table_field(lab.MobileCarrier(), 'mobile_carrier'); | ||
GUI_info(6).example_value = ''; | ||
GUI_info(6).tooltip = 'allowed mobile carrier'; | ||
|
||
GUI_info(7).name = 'slack'; | ||
GUI_info(7).gui_type = 'edit'; | ||
GUI_info(7).datatype = 'string'; | ||
GUI_info(7).default = ''; | ||
GUI_info(7).list_values = {}; | ||
GUI_info(7).example_value = ''; | ||
GUI_info(7).tooltip = 'slack username'; | ||
|
||
GUI_info(8).name = 'contact_via'; | ||
GUI_info(8).gui_type = 'popupmenu'; | ||
GUI_info(8).datatype = 'string'; | ||
GUI_info(8).default = ''; | ||
GUI_info(8).list_values = {'Slack','text','Email'}; | ||
GUI_info(8).example_value = ''; | ||
GUI_info(8).tooltip = 'Preferred method of contact'; | ||
|
||
GUI_info(9).name = 'presence'; | ||
GUI_info(9).gui_type = 'popupmenu'; | ||
GUI_info(9).datatype = 'string'; | ||
GUI_info(9).default = ''; | ||
GUI_info(9).list_values = {'Available','Away'}; | ||
GUI_info(9).example_value = ''; | ||
GUI_info(9).tooltip = ''; | ||
|
||
GUI_info(10).name = 'primary_tech'; | ||
GUI_info(10).gui_type = 'popupmenu'; | ||
GUI_info(10).datatype = 'string'; | ||
GUI_info(10).default = 'N/A'; | ||
GUI_info(10).list_values = {'yes','no','N/A'}; | ||
GUI_info(10).example_value = ''; | ||
GUI_info(10).tooltip = ''; | ||
|
||
GUI_info(11).name = 'tech_responsibility'; | ||
GUI_info(11).gui_type = 'popupmenu'; | ||
GUI_info(11).datatype = 'string'; | ||
GUI_info(11).default = 'N/A'; | ||
GUI_info(11).list_values = {'yes','no','N/A'}; | ||
GUI_info(11).example_value = ''; | ||
GUI_info(11).tooltip = ''; | ||
|
||
GUI_info(12).name = 'day_cutoff_time'; | ||
GUI_info(12).gui_type = 'blob'; | ||
GUI_info(12).datatype = 'numeric array'; | ||
GUI_info(12).default = ''; | ||
GUI_info(12).list_values = {}; | ||
GUI_info(12).example_value = obj.get_values_table_field(lab.User(), 'day_cutoff_time', 'LIMIT 1'); | ||
GUI_info(12).tooltip = ''; | ||
|
||
GUI_info(13).name = 'slack_webhook'; | ||
GUI_info(13).gui_type = 'edit'; | ||
GUI_info(13).datatype = 'string'; | ||
GUI_info(13).default = ''; | ||
GUI_info(13).list_values = {}; | ||
GUI_info(13).example_value = ''; | ||
GUI_info(13).tooltip = ''; | ||
|
||
GUI_info(14).name = 'watering_logs'; | ||
GUI_info(14).gui_type = 'edit'; | ||
GUI_info(14).datatype = 'string'; | ||
GUI_info(14).default = ''; | ||
GUI_info(14).list_values = {}; | ||
GUI_info(14).example_value = ''; | ||
GUI_info(14).tooltip = ''; | ||
|
||
GUI_info(15).name = 'lab'; | ||
GUI_info(15).gui_type = 'popupmenu'; | ||
GUI_info(15).datatype = 'string'; | ||
GUI_info(15).default = ''; | ||
GUI_info(15).list_values = obj.get_values_table_field(lab.Lab(), 'lab'); | ||
GUI_info(15).example_value = ''; | ||
GUI_info(15).tooltip = ''; | ||
|
||
GUI_info(16).name = 'secondary_contact'; | ||
GUI_info(16).gui_type = 'popupmenu'; | ||
GUI_info(16).datatype = 'string'; | ||
GUI_info(16).default = ''; | ||
GUI_info(16).list_values = obj.get_values_table_field(lab.User(), 'user_id'); | ||
GUI_info(16).example_value = ''; | ||
GUI_info(16).tooltip = ''; | ||
|
||
GUI_info(17).name = 'project'; | ||
GUI_info(17).gui_type = 'popupmenu'; | ||
GUI_info(17).datatype = 'string'; | ||
GUI_info(17).default = ''; | ||
GUI_info(17).list_values = obj.get_values_table_field(lab.Project(), 'project'); | ||
GUI_info(17).example_value = ''; | ||
GUI_info(17).tooltip = ''; | ||
|
||
GUI_info(18).name = 'protocol'; | ||
GUI_info(18).gui_type = 'popupmenu'; | ||
GUI_info(18).datatype = 'string'; | ||
GUI_info(18).default = ''; | ||
GUI_info(18).list_values = obj.get_values_table_field(lab.Protocol(), 'protocol'); | ||
GUI_info(18).example_value = ''; | ||
GUI_info(18).tooltip = ''; | ||
|
||
|
||
%Create tables_update structure with references for all tables | ||
tables_update(1).table = lab.User(); | ||
tables_update(2).table = lab.UserLab(); | ||
tables_update(3).table = lab.UserSecondaryContact(); | ||
tables_update(4).table = lab.ProjectUser(); | ||
tables_update(5).table = lab.UserProtocol(); | ||
|
||
for i=1:length(tables_update) | ||
tables_update(i).fields = tables_update(i).table.header.names; | ||
end | ||
|
||
end | ||
|
29 changes: 29 additions & 0 deletions
29
database/AddLabUsers/@DataJointLabUserTable/get_values_table_field.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function example_value = get_values_table_field(~, table, field, sort_limit) | ||
% Function to get specific fields from table | ||
% Inputs: | ||
% obj = DataJointLabUserTable object | ||
% table = Reference to table in the database | ||
% field = Name of the field to read | ||
% sort_limit = Optional argument for sorting or limiting query | ||
% | ||
% Outputs | ||
% example_value = Result from the query | ||
|
||
|
||
%If sort_limit argument is not present, will be defined as empty string | ||
if nargin <= 3 | ||
sort_limit = ''; | ||
end | ||
|
||
if ~isempty(sort_limit) | ||
example_value = fetchn(table, field, sort_limit); | ||
%If only one record needed for the query extract cell value | ||
if strcmp(sort_limit,'LIMIT 1') | ||
example_value = example_value{:}; | ||
end | ||
else | ||
example_value = fetchn(table, field); | ||
example_value = example_value(:); | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function insert_user(obj, all_values_insert) | ||
% Function that calls database to insert record in tables referenced in | ||
% table_info structure | ||
% Inputs: | ||
% obj = DataJointLabUserTable object | ||
% all_values_insert = structure with values to insert in table | ||
% | ||
|
||
% for each table of the tables_info structure | ||
for table_info = obj.tables_info | ||
|
||
table = table_info.table; | ||
values_insert_table = struct; | ||
%Select the fields to be written | ||
for field = table_info.fields | ||
field_str = field{:}; | ||
values_insert_table.(field_str) = all_values_insert.(field_str); | ||
|
||
end | ||
%Call datajoint database and insert data | ||
insert(table, values_insert_table); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
function GUI_add_user(obj, hobject, event) | ||
% Function called when add user button is pressed | ||
% Reads and check input by the user and insert record if everything is | ||
% correct | ||
% Inputs: | ||
% obj = AddRecordsGUI object | ||
% | ||
% Outputs | ||
% title = GUI object for the title | ||
|
||
% Disable buttons while processing data | ||
for i=1:length(obj.button) | ||
set(obj.button, 'Enable', 'off'); | ||
end | ||
|
||
% Initialize status and error message | ||
status = true; | ||
error_msg = {'Error: Data could not be inserted'}; | ||
error_msg(end+1) = {''}; | ||
struct_insert = struct; | ||
|
||
% For each input | ||
for i = 1:length(obj.GUI_inputs) | ||
|
||
GUI_input = obj.GUI_inputs{i}; | ||
%Read value written by user | ||
struct_insert.(GUI_input.name) = GUI_input.get_value(); | ||
%Check if value is something accepted for the database | ||
[ac_status, ac_error] = GUI_input.check_input(struct_insert.(GUI_input.name)); | ||
|
||
%Update status and possible error messages | ||
status = and(status, ac_status); | ||
if ~ac_status | ||
error_msg(end+1) = {ac_error}; | ||
end | ||
|
||
end | ||
|
||
% If there is at least one mistake in inputs | ||
if ~status | ||
%Show error message for each mistaken input | ||
msgbox(error_msg, 'Error','error'); | ||
|
||
% If there is no error in input | ||
else | ||
|
||
|
||
try | ||
%Try to insert record to database | ||
obj.DatabaseTable.insert_user(struct_insert); | ||
msgbox({'Record added succesfully'}); | ||
%And close GUI | ||
obj.close_figure(); | ||
|
||
catch e | ||
%If there is a problem adding the record it shows corresponding error | ||
error_msg = {sprintf('The identifier was:\n%s',e.identifier)}; | ||
error_msg(end+1) = {sprintf('There was an error! The message was:\n%s',e.message)}; | ||
msgbox(error_msg, 'Error','error'); | ||
end | ||
|
||
end | ||
|
||
|
||
end | ||
|
Oops, something went wrong.