Skip to content

Commit

Permalink
Add support for view access to projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0001 committed Oct 3, 2024
1 parent 686f3af commit a977f98
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
10 changes: 9 additions & 1 deletion application/views/metadata_editor/fields/vue-field-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Vue.component('editor-date-field', {
}
},
methods:{
isFieldReadOnly() {
if (!this.$store.getters.getUserHasEditAccess) {
return true;
}

return this.field.is_readonly;
},
momentDateISO(date) {
return moment(date).toISOString();
},
Expand Down Expand Up @@ -60,12 +67,13 @@ Vue.component('editor-date-field', {
prepend-inner-icon="mdi-calendar"
:hint="'Date format: YYYY-MM-DD - ' + value"
persistent-hint
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
></v-text-field>
</template>
<v-date-picker
v-model="date"
@change="menu1 = false"
:disabled="isFieldReadOnly"
></v-date-picker>
</v-menu>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const VueExternalResources = Vue.component('external-resources', {
})
.catch(function(response){
vm.errors=response;
alert("Failed: " + vm.erorrMessageToText(response));
});
},
importResource:function(){
Expand All @@ -56,8 +57,20 @@ const VueExternalResources = Vue.component('external-resources', {
})
.catch(function(response){
vm.errors=response;
alert("Failed: " + vm.erorrMessageToText(response));
});
},
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;
},
},
computed: {
ExternalResources()
Expand All @@ -69,7 +82,10 @@ const VueExternalResources = Vue.component('external-resources', {
},
ProjectID(){
return this.$store.state.project_id;
}
},
isProjectEditable(){
return this.$store.getters.getUserHasEditAccess;
}
},
template: `
<div class="external-resources container-fluid pt-5 mt-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ const VueExternalResourcesEdit= Vue.component('external-resources-edit', {
}
},
computed: {
ExternalResources()
{
isProjectEditable(){
return this.$store.getters.getUserHasEditAccess;
},
ExternalResources(){
return this.$store.state.external_resources;
},
ActiveResourceIndex(){
Expand All @@ -239,18 +241,9 @@ const VueExternalResourcesEdit= Vue.component('external-resources-edit', {

},
Resource(){
//return this.ExternalResources[this.ActiveResourceIndex];

return this.$store.state.external_resources.find(resource => {
return resource.id == this.ActiveResourceIndex
});

return this.$store.state.external_resources.forEach((resource, index) => {
if (resource.id==this.ActiveResourceIndex){
console.log(":resource",resource, this.ActiveResourceIndex);
return this.ExternalResources[index];
}
});
},
ResourceAttachmentType()
{
Expand All @@ -271,7 +264,6 @@ const VueExternalResourcesEdit= Vue.component('external-resources-edit', {
template: `
<div class="container-fluid edit-resource-container mt-5 pt-5">
{{is_dirty}}
<div v-if="Resource">
<v-card>
Expand Down Expand Up @@ -419,8 +411,7 @@ const VueExternalResourcesEdit= Vue.component('external-resources-edit', {
</div>
<v-btn color="primary" @click="uploadFile" :disabled="file_exists==true">Save</v-btn>
<v-btn color="primary" @click="uploadFile" :disabled="file_exists==true || !isProjectEditable">Save</v-btn>
<v-btn @click="cancelSave">Cancel</v-btn>
Expand Down
19 changes: 13 additions & 6 deletions application/views/metadata_editor/vue-form-input-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Vue.component("form-input", {
},
mounted: function () {},
computed: {
isFieldReadOnly() {
if (!this.$store.getters.getUserHasEditAccess) {
return true;
}

return this.field.is_readonly;
},
local: {
get: function () {
return this.value;
Expand Down Expand Up @@ -139,7 +146,7 @@ Vue.component("form-input", {
>
</repeated-field>
</div>
<div v-else-if="fieldDisplayType(field)=='dropdown' || fieldDisplayType(field)=='dropdown-custom'">
<div v-else-if="fieldDisplayType(field)=='dropdown' || fieldDisplayType(field)=='dropdown-custom'">
<v-combobox
v-model="fieldEnumByCodeMultiple"
:items="field.enum"
Expand All @@ -151,7 +158,7 @@ Vue.component("form-input", {
small-chips
v-bind="formTextFieldStyle"
background-color="#FFFFFF"
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
></v-combobox>
</div>
Expand All @@ -174,7 +181,7 @@ Vue.component("form-input", {
<v-text-field
v-model="local"
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
v-bind="formTextFieldStyle"
></v-text-field>
<small :id="'field-toggle-' + normalizeClassID(field.key)" class="collapse help-text form-text text-muted">{{field.help_text}}</small>
Expand Down Expand Up @@ -206,7 +213,7 @@ Vue.component("form-input", {
<v-textarea
v-else
variant="outlined"
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
v-model="local"
v-bind="formTextFieldStyle"
class="v-textarea-field"
Expand Down Expand Up @@ -240,7 +247,7 @@ Vue.component("form-input", {
:multiple="field.type=='simple_array'"
v-bind="formTextFieldStyle"
background-color="#FFFFFF"
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
></v-combobox>
<small class="text-muted">{{field.enum_store_column}} - {{local}}</small>
</div>
Expand All @@ -261,7 +268,7 @@ Vue.component("form-input", {
dense
clearable
background-color="#FFFFFF"
:disabled="field.is_readonly"
:disabled="isFieldReadOnly"
></v-select>
<small class="text-muted">{{local}}</small>
</div>
Expand Down
7 changes: 5 additions & 2 deletions application/views/metadata_editor/vue-summary-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Vue.component('summary-component', {
this.getProjectDiskUsage();
},
computed: {
isProjectEditable(){
return this.$store.getters.getUserHasEditAccess;
},
ProjectID(){
return this.$store.state.project_id;
},
Expand Down Expand Up @@ -151,11 +154,11 @@ Vue.component('summary-component', {
<div class="d-flex justify-space-between">
<div><v-icon style="font-size:25px;">mdi-alpha-t-box</v-icon> {{$t("template")}}</div>
<v-btn small title="Apply template default values" text @click="templateApplyDefaults"><v-icon>mdi-checkbox-multiple-marked-circle</v-icon>Defaults</v-btn>
<v-btn :disabled="!isProjectEditable" small title="Apply template default values" text @click="templateApplyDefaults"><v-icon>mdi-checkbox-multiple-marked-circle</v-icon>Defaults</v-btn>
</div>
<div class="mt-1">
<v-btn text color="primary" @click="loadTemplates();dialog_template=true">
<v-btn text color="primary" @click="loadTemplates();dialog_template=true" :disabled="!isProjectEditable">
{{ProjectTemplate.name}} - {{ProjectTemplate.version}}
</v-btn>
</div>
Expand Down
21 changes: 13 additions & 8 deletions application/views/metadata_editor/vue-table-grid-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ Vue.component('table-grid-component', {
}
return keys;
},
isReadOnly(){
isFieldReadOnly() {
if (!this.$store.getters.getUserHasEditAccess) {
return true;
}

if (this.field && this.field.is_readonly){
return this.field.is_readonly;
}

return false;
}
},
Expand Down Expand Up @@ -240,7 +245,7 @@ Vue.component('table-grid-component', {
<tr>
<th>
<!--options -->
<v-menu bottom left v-if="!isReadOnly">
<v-menu bottom left v-if="!isFieldReadOnly">
<template v-slot:activator="{ on, attrs }">
<v-btn
light
Expand Down Expand Up @@ -302,7 +307,7 @@ Vue.component('table-grid-component', {
</span>
</th>
<th scope="col">
<span class="float-right" v-show="enums" v-if="!isReadOnly">
<span class="float-right" v-show="enums" v-if="!isFieldReadOnly">
<v-btn
light
icon
Expand All @@ -324,7 +329,7 @@ Vue.component('table-grid-component', {
<td v-for="(column,idx_col) in localColumns" scope="row">
<div v-if="fieldDisplayType(column)=='textarea'" >
<textarea class="form-control form-control-sm"
:disabled="isReadOnly"
:disabled="isFieldReadOnly"
:value="local[index][column.key]"
@input="update(index,column.key, $event.target.value)"
>
Expand All @@ -344,30 +349,30 @@ Vue.component('table-grid-component', {
item-value="code"
:return-object="false"
class="form-field-dropdown-custom"
:disabled="isReadOnly"
:disabled="isFieldReadOnly"
></v-combobox>
</div>
<div v-else>
<input type="text"
:value="local[index][column.key]"
@input="update(index,column.key, $event.target.value)"
class="form-control form-control-sm"
:disabled="isReadOnly"
:disabled="isFieldReadOnly"
>
</div>
</td>
<td scope="row">
<div class="mr-1">
<v-icon v-if="!isReadOnly" class="v-delete-icon" v-on:click="remove(index)">mdi-trash-can-outline</v-icon>
<v-icon v-if="!isFieldReadOnly" class="v-delete-icon" v-on:click="remove(index)">mdi-trash-can-outline</v-icon>
</div>
</td>
</tr>
<!--end-v-for -->
</tbody>
</table>
<div class="d-flex justify-content-center" v-if="!isReadOnly">
<div class="d-flex justify-content-center" v-if="!isFieldReadOnly">
<v-btn @click="addRow" class="m-2" text small ><v-icon>mdi-plus</v-icon>{{ $t("add_row") }}</v-btn>
</div>
Expand Down

0 comments on commit a977f98

Please sign in to comment.