Skip to content

Commit

Permalink
simplify action check in container
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Feb 3, 2022
1 parent b4fe213 commit dd20071
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</li>
<li>
<media-browser-action-item-edit
v-if="canEdit"
v-if="canEdit && canOpenEditView"
ref="actionEdit"
:on-focused="focused"
:main-action="editItem"
Expand Down Expand Up @@ -115,15 +115,14 @@

<script>
import * as types from '../../../store/mutation-types.es6';
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserActionItemsContainer',
props: {
item: { type: Object, default: () => {} },
onFocused: { type: Function, default: () => {} },
edit: { type: Function, default: () => {} },
editable: { type: Boolean, default: false },
deletable: { type: Boolean, default: false },
previewable: { type: Boolean, default: false },
downloadable: { type: Boolean, default: false },
shareable: { type: Boolean, default: false },
Expand All @@ -134,12 +133,20 @@ export default {
};
},
computed: {
/* Check if the item is an document to edit */
canEdit() {
return this.editable();
canEdit() {
if (typeof this.item.canEdit !== 'undefined') {
return this.item.canEdit;
}
return api.canEdit;
},
canOpenEditView() {
return ['jpg', 'jpeg', 'png'].includes(this.item.extension.toLowerCase());
},
canDelete() {
return this.deletable();
if (typeof this.item.canDelete !== 'undefined') {
return this.item.canDelete;
}
return api.canDelete;
},
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<media-browser-action-items-container
ref="container"
:focused="focused"
:deleteable="canDelete"
:item="item"
:previewable="true"
:downloadable="true"
Expand All @@ -27,8 +26,6 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemAudio',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -39,12 +36,6 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
</div>
<media-browser-action-items-container
ref="container"
:editable="canEdit"
:deletable="canDelete"
:focused="focused"
:item="item"
/>
</div>
</template>
<script>
import navigable from '../../../mixins/navigable.es6';
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemDirectory',
Expand All @@ -40,12 +37,6 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Handle the on preview double click event */
onPreviewDblClick() {
this.navigateTo(this.item.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
ref="container"
:focused="focused"
:item="item"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -33,8 +31,6 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemDocument',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -45,12 +41,6 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
ref="container"
:focused="focused"
:item="item"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -32,8 +30,6 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemFile',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -44,12 +40,6 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
:focused="focused"
:item="item"
:edit="editItem"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand Down Expand Up @@ -58,13 +56,6 @@ export default {
},
},
methods: {
/* Check if the item is a document to edit */
canEdit() {
return api.canEdit && ['jpg', 'jpeg', 'png'].includes(this.item.extension.toLowerCase());
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
ref="container"
:focused="focused"
:item="item"
:editable="canEdit"
:deletable="canDelete"
:previewable="true"
:downloadable="true"
:shareable="true"
Expand All @@ -28,8 +26,6 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
export default {
name: 'MediaBrowserItemVideo',
// eslint-disable-next-line vue/require-prop-types
Expand All @@ -40,12 +36,6 @@ export default {
};
},
methods: {
canEdit() {
return api.canEdit;
},
canDelete() {
return api.canDelete;
},
/* Hide actions dropdown */
hideActions() {
this.$refs.container.hideActions();
Expand Down

0 comments on commit dd20071

Please sign in to comment.