Skip to content

Commit

Permalink
Add option for controlled vocabularies to specify which value (code, …
Browse files Browse the repository at this point in the history
…label or both) to store in metadata
  • Loading branch information
mah0001 committed Oct 1, 2024
1 parent 508765c commit 300af1d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 22 deletions.
38 changes: 28 additions & 10 deletions application/controllers/api/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function update_post($uid=null)
{
try{
//$this->has_access($resource_='template_manager',$privilege='edit');
$this->editor_acl->user_has_template_access($uid,$permission='edit',$this->user);
$this->editor_acl->user_has_template_access($uid,$permission='edit',$this->user);

if (!$uid){
throw new Exception("Missing parameter: UID");
Expand Down Expand Up @@ -394,10 +394,22 @@ function defaults_get($type=null)
*/
function share_post()
{
try{
$this->has_access($resource_='template_manager',$privilege='edit');

try{

$options=$this->raw_json_input();

if (!is_array($options)){
throw new Exception("Invalid input: must be an array");
}

foreach($options as $option){
if (!isset($option['template_uid'])){
throw new Exception("Missing parameter: template_uid");
}

$this->editor_acl->user_has_template_access($option['template_uid'],$permission='admin',$this->user);
}

$result=$this->Editor_template_model->share_template($options, $this->user_id);

$output=array(
Expand All @@ -408,7 +420,11 @@ function share_post()
$this->set_response($output, REST_Controller::HTTP_OK);
}
catch(Exception $e){
$this->set_response($e->getMessage(), REST_Controller::HTTP_BAD_REQUEST);
$error_output=array(
'status'=>'failed',
'message'=>$e->getMessage()
);
$this->set_response($error_output, REST_Controller::HTTP_BAD_REQUEST);
}
}

Expand Down Expand Up @@ -438,9 +454,7 @@ function share_get($uid)

function remove_access_post()
{
try{
$this->has_access($resource_='template_manager',$privilege='edit');

try{
$options=$this->raw_json_input();

if (!isset($options['template_uid'])){
Expand All @@ -451,7 +465,7 @@ function remove_access_post()
throw new Exception("Missing parameter: user_id");
}


$this->editor_acl->user_has_template_access($options['template_uid'],$permission='admin',$this->user);
$result=$this->Editor_template_model->unshare_template($options['template_uid'], $options['user_id']);

$output=array(
Expand All @@ -462,7 +476,11 @@ function remove_access_post()
$this->set_response($output, REST_Controller::HTTP_OK);
}
catch(Exception $e){
$this->set_response($e->getMessage(), REST_Controller::HTTP_BAD_REQUEST);
$error_output=array(
'status'=>'failed',
'message'=>$e->getMessage()
);
$this->set_response($error_output, REST_Controller::HTTP_BAD_REQUEST);
}
}

Expand Down
3 changes: 3 additions & 0 deletions application/language/english/general_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
$lang['field_content_format_help']="Text, Markdown, LaTex, HTML. Default is Text";


$lang['enum_store_options_label']="Select column to use as value";



/* End of file general_lang.php */
/* Location: ./application/language/base/general_lang.php */
40 changes: 33 additions & 7 deletions application/views/metadata_editor/vue-form-input-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,40 @@ Vue.component("form-input", {
return code || this.local;
},
set: function (value) {
let code = this.findEnumByCode(value);

if (code) {
this.local = code.label + " [" + code.code + "]";
} else {
this.local = value;
let enum_store_column = this.field.enum_store_column;

if (!enum_store_column) {
enum_store_column = "both";
}

//if enum_store_column is both, store the code and label
if (enum_store_column == "both") {
let code = this.findEnumByCode(value);

if (code) {
this.local = code.label + " [" + code.code + "]";
} else {
this.local = value;
}
}
else if (enum_store_column == "code") {
let code = this.findEnumByCode(value);
if (code) {
this.local = code.code;
} else {
this.local = value;
}
}
else if (enum_store_column == "label") {
let code = this.findEnumByCode(value);
if (code) {
this.local = code.label;
} else {
this.local = value;
}
}

},
},
formTextFieldStyle() {
Expand Down Expand Up @@ -215,8 +242,7 @@ Vue.component("form-input", {
background-color="#FFFFFF"
:disabled="field.is_readonly"
></v-combobox>
<small class="text-muted">{{local}}</small>
<small class="text-muted">{{field.enum_store_column}} - {{local}}</small>
</div>
</div>
Expand Down
21 changes: 20 additions & 1 deletion application/views/template_manager/edit_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,30 @@ class="form-control form-field-dropdown" >
<template >
<div class="form-group" >
<label for="controlled_vocab">{{$t("controlled_vocabulary")}}:</label>
<div class="border bg-white" style="max-height:300px;overflow:auto;">
<div class="bg-white border " style="max-height:300px;overflow:auto;">


<template v-if="!ActiveNodeControlledVocabColumns">

<div>

<div class="m-3">
<div>{{$t("enum_store_options_label")}}:</div>

<v-select
style="max-width:300px;"
v-model="ActiveNodeEnumStoreColumn"
:items="enum_store_options"
:item-text="item => item.label"
:item-value="item => item.value"
dense
outlined
clearable
label=""
></v-select>
</div>
</div>

<table-grid-component
:key="ActiveNode.key"
:columns="ActiveNodeSimpleControlledVocabColumns"
Expand Down
29 changes: 28 additions & 1 deletion application/views/template_manager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,21 @@ function getTreeKeys(tree_items, output) {
"image": "fa fa-image",
"video": "fa fa-video",
"script": "fa fa-file-code"
}
},
enum_store_options:[
{
"value":"both",
"label":"Label with code"
},
{
"value":"code",
"label":"Code"
},
{
"value":"label",
"label":"Label"
}
]
}
},
created: function() {
Expand All @@ -602,6 +616,7 @@ function getTreeKeys(tree_items, output) {
});
},
methods: {

onWindowUnload: function(event){
if (!this.is_dirty){
return null;
Expand Down Expand Up @@ -1081,6 +1096,18 @@ enum_list.push({
set: function(newValue) {
Vue.set(this.ActiveNode, "enum", newValue);
}
},
ActiveNodeEnumStoreColumn:{
get: function(){
if (this.ActiveNode.enum_store_column){
return this.ActiveNode.enum_store_column;
}
return 'both';
},
set: function(newValue){
Vue.set(this.ActiveNode, "enum_store_column", newValue);
}

},
ActiveNodeEnumCount() {
if (this.ActiveNode.enum) {
Expand Down
20 changes: 17 additions & 3 deletions application/views/templates/vue-template-share-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ Vue.component('vue-template-share', {
this.searchUsers(val);
}
},
methods: {
methods: {
erorrMessageToText: function(error){
let error_text = '';
if (error.response.data.errors) {
for (let key in error.response.data.errors) {
error_text += error.response.data.errors[key] + '\n';
}
} else {
error_text = error.response.data.message;
}
return error_text;
},
getSelectedUsersList: function(){
let selected_users = [];
for (let i = 0; i < this.selected_users.length; i++) {
Expand Down Expand Up @@ -81,6 +92,7 @@ Vue.component('vue-template-share', {
})
.catch(function (error) {
console.log(error);
alert("Failed: " + vm.erorrMessageToText(error));
})
.finally(() => (this.is_loading = false));
},
Expand All @@ -104,6 +116,7 @@ Vue.component('vue-template-share', {
})
.catch(function (error) {
console.log(error);
alert("Failed: " + vm.erorrMessageToText(error));
});

},
Expand All @@ -130,7 +143,7 @@ Vue.component('vue-template-share', {
})
.catch(function (error) {
console.log(error);
alert("Error removing user access");
alert("Failed: " + vm.erorrMessageToText(error));
});
},

Expand Down Expand Up @@ -181,6 +194,7 @@ Vue.component('vue-template-share', {
v-model="selected_users"
:loading="is_loading"
:search-input.sync="search"
@input="search=null"
:items="users"
solo
chips
Expand All @@ -191,7 +205,7 @@ Vue.component('vue-template-share', {
multiple
cache-items
return-object
no-data-text="Type user name or email to search for a user"
no-data-text="Type user name or email to search for a user"
>
<template v-slot:selection="data">
<v-chip
Expand Down

0 comments on commit 300af1d

Please sign in to comment.