Skip to content

Commit

Permalink
Add user input for link share labels
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <gary@garykim.dev>
  • Loading branch information
gary-kim committed Jul 8, 2020
1 parent 44f8312 commit 7820e83
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ public function updateShare(

// only link shares have labels
if ($share->getShareType() === IShare::TYPE_LINK && $label !== null) {
if (strlen($label) > 255) {
throw new OCSBadRequestException("Maxmimum label length is 255");
}
$share->setLabel($label);
}

Expand Down
50 changes: 48 additions & 2 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:class="isEmailShareType ? 'icon-mail-white' : 'icon-public-white'"
class="sharing-entry__avatar" />
<div class="sharing-entry__desc">
<h5>{{ title }}</h5>
<h5 :title="title">{{ title }}</h5>
</div>

<!-- clipboard -->
Expand Down Expand Up @@ -124,6 +124,24 @@
@close="onMenuClose">
<template v-if="share">
<template v-if="share.canEdit">
<!-- Custom Label -->
<ActionInput
ref="label"
v-tooltip.auto="{
content: errors.label,
show: errors.label,
trigger: 'manual',
defaultContainer: '.app-sidebar'
}"
:class="{ error: errors.label }"
:disabled="saving"
:placeholder="t('files_sharing', 'Share label')"
:aria-label="t('files_sharing', 'Share label')"
:value="share.newLabel || share.label"
icon="icon-edit"
maxlength="255"
@update:value="onLabelChange"
@submit="onLabelSubmit" />
<!-- folder -->
<template v-if="isFolder && fileHasCreatePermission && config.isPublicUploadEnabled">
<ActionRadio :checked="sharePermissions === publicUploadRValue"
Expand Down Expand Up @@ -391,7 +409,9 @@ export default {
})
}
if (this.share.label && this.share.label.trim() !== '') {
return this.share.label
return t('files_sharing', 'Share link ({label})', {
label: this.share.label.trim()
})
}
if (this.isEmailShareType) {
return this.share.shareWith
Expand Down Expand Up @@ -712,6 +732,25 @@ export default {
this.queueUpdate('permissions')
},

/**
* Label changed, let's save it to a different key
* @param {String} label the share label
*/
onLabelChange(label) {
this.$set(this.share, 'newLabel', label.trim())
},

/**
* When the note change, we trim, save and dispatch
*/
onLabelSubmit() {
if (typeof this.share.newLabel === 'string') {
this.share.label = this.share.newLabel
this.$delete(this.share, 'newLabel')
this.queueUpdate('label')
}
},

/**
* Generate a valid policy password or
* request a valid password if password_policy
Expand Down Expand Up @@ -856,6 +895,13 @@ export default {
justify-content: space-between;
padding: 8px;
line-height: 1.2em;
overflow: hidden;

h5 {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
}

&:not(.sharing-entry--share) &__actions {
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export default {
case 'password':
case 'pending':
case 'expireDate':
case 'label':
case 'note': {
// show error
this.$set(this.errors, property, message)
Expand Down
26 changes: 23 additions & 3 deletions apps/files_sharing/src/models/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ export default class Share {
this.#share.note = note
}

/**
* Get the share label if any
* Should only exist on link shares
*
* @returns {string}
* @readonly
* @memberof Share
*/
get label() {
return this.#share.label
}

/**
* Set the share label if any
* Should only be set on link shares
*
* @param {string} label the label
* @memberof Share
*/
set label(label) {
this.#share.label = label
}

/**
* Have a mail been sent
*
Expand Down Expand Up @@ -488,9 +511,6 @@ export default class Share {
}

// TODO: SORT THOSE PROPERTIES
get label() {
return this.#share.label
}

get parent() {
return this.#share.parent
Expand Down

0 comments on commit 7820e83

Please sign in to comment.