Skip to content

Commit

Permalink
Fixed issue with add members
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jul 14, 2023
1 parent a5d4048 commit 4cfa803
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

'pl.grouperlite.message.flash.group-detail-members-failed' => 'Error in viewing the members of this group, please try again later.',

'pl.grouperlite.message.flash.add-subscriber-success' => 'Added subscriber.',
'pl.grouperlite.message.flash.add-subscriber-success' => 'has been added to the group:',
'pl.grouperlite.message.flash.add-subscriber-failed' => 'Error in adding subscriber.',
'pl.grouperlite.message.flash.remove-subscriber-success' => 'Removed subscriber.',
'pl.grouperlite.message.flash.remove-subscriber-success' => 'has been removed from the group:',
'pl.grouperlite.message.flash.remove-subscriber-failed' => 'Error in removing subscriber.',

'pl.grouperlite.table.name' => 'Name',
Expand Down
21 changes: 1 addition & 20 deletions View/GrouperGroups/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
provide: {
collapsed: <?php echo $config['defaultCollapse'] == 'collapsed' ? 'true' : 'false'; ?>,
optAction: "<?php echo isset($optAction) ? $optAction : 'none'; ?>",
allowAddSubscribers: <?php echo isset($addSubscribers) && $addSubscribers ? 'true' : 'false' ?>,
owner: <?php echo $treatAsOwner ? 'true' : 'false'; ?>,
url: "<?php echo isset($actionUrl) ? $actionUrl : 'null'; ?>",
grouperUrl: "<?php echo $grouperUrlBase ?>",
Expand Down Expand Up @@ -174,22 +173,4 @@
<div id="grouper-lite-widget">
<router-view></router-view>
</div>
</div>
<?php /*
<template v-slot:actionform="actionform">
<?php echo $this->Form->create(false, array(
'url' => array('controller' => 'grouper_groups', 'action' => isset($optAction) ? $optAction : ''),
'class' => 'd-flex justify-content-center',
'id' => 'group-action'
)); ?>
<input type="hidden" name="data[GroupName]" :value="actionform.groupname" />
<input type="hidden" name="data[GroupDisplayName]" :value="actionform.groupdisplayname" />
<button
:class="actionform.actiontype"
class="btn btn-sm btn-block text-nowrap m-1 btn-success" type="submit">
{{ actionform.actionlabel }}
&nbsp;
<em class="material-icons mt-0" aria-hidden="true">{{ actionform.actionicon }}</em>
</button>
<?php echo $this->Form->end(null); ?>
</template>*/ ?>
</div>
10 changes: 7 additions & 3 deletions webroot/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ export default {
data() {
return {
search: '',
val: ''
val: '',
item: null,
};
},
methods: {
addUser(search) {
this.$emit('add', search);
this.$emit('add', this.item);
}
},
mounted(el) {
Expand All @@ -24,11 +25,14 @@ export default {
maxShowItems: 10,
focus: function( event, ui ) {
this.search = ui.item.label;
this.val = ui.item.identifier;
this.item = ui.item;
return false;
},
select: (event, ui) => {
this.val = ui.item.identifier;
this.search = ui.item.label;
this.item = ui.item;
$("#addUserbutton").prop('disabled', false).focus();
return false;
},
Expand All @@ -39,7 +43,7 @@ export default {
<input id="add-user-value" type="hidden" name="addUser" class="form-control" v-model="val" />
<input id="add-user-input" type="text" name="display" class="form-control" v-model="search" />
<div class="input-group-append">
<button id="addUserbutton" class=" btn btn-grouper btn-primary px-4" type="button" @click="addUser(val)">
<button id="addUserbutton" class=" btn btn-grouper btn-primary px-4" type="button" @click="addUser(val)" :disabled="!uten">
<em class="material-icons lg" aria-hidden="true">add</em>
<span class="ml-2">{{ txt.addUser }}</span>
</button>
Expand Down
5 changes: 1 addition & 4 deletions webroot/js/groups-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ export default {
mixins: [
Table
],

data() {

},
data() {},
computed: {
},
created() {},
Expand Down
8 changes: 4 additions & 4 deletions webroot/js/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export default {
});
if (resp.ok) {
this.loadGroups(this.apiPath, this.query, false);
generateFlash(`${this.txt.leaveSuccess}: ${group.displayName}`, 'success');
generateFlash(`${this.txt.leaveSuccess} ${group.displayName}`, 'success');
} else {
this.error = resp;
generateFlash(`${this.txt.leaveError}: ${group.displayName}`, 'error');
generateFlash(`${this.txt.leaveError} ${group.displayName}`, 'error');
}
},
async joinGroup(group) {
Expand All @@ -83,10 +83,10 @@ export default {
});
if (resp.ok) {
this.loadGroups(this.apiPath, this.query, false);
generateFlash(`${this.txt.joinSuccess}: ${group.displayName}`, 'success');
generateFlash(`${this.txt.joinSuccess} ${group.displayName}`, 'success');
} else {
this.error = resp;
generateFlash(`${this.txt.joinError}: ${group.displayName}`, 'error');
generateFlash(`${this.txt.joinError} ${group.displayName}`, 'error');
}
}
},
Expand Down
15 changes: 8 additions & 7 deletions webroot/js/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Autocomplete from './autocomplete.js';
export default {
props: {
add: Boolean,
remove: Boolean,
default: false
},
inject: ['txt', 'api'],
Expand Down Expand Up @@ -78,7 +79,7 @@ export default {
this.loading = false;

},
async removeSubscriber({name}, {id}) {
async removeSubscriber({name}, {id, label}) {
this.loading = true;
const resp = await fetch(`${this.api.remove}?group=${encodeURIComponent(name)}&userId=${id}`, {
method: "DELETE",
Expand All @@ -90,15 +91,15 @@ export default {
if (resp.ok) {
this.subscribers = [];
this.loadGroupSubscribers(this.group);
generateFlash(this.txt.removeSubscriberSuccess, 'success');
generateFlash(`${label} ${this.txt.removeSubscriberSuccess} ${encodeURIComponent(name)}`, 'success');
} else {
this.disabled = [ ...this.disabled, id ];
generateFlash(this.txt.removeSubscriberError, 'error');
}

this.loading = false;
},
async addSubscriber(id) {
async addSubscriber({ identifier: id, label }) {
this.loading = true;
const { name } = this.group;
const formData = new FormData();
Expand All @@ -114,7 +115,7 @@ export default {
});
if (resp.ok) {
this.loadGroupSubscribers(this.group);
generateFlash(this.txt.addSubscriberSuccess, 'success');
generateFlash(`${label} ${this.txt.addSubscriberSuccess} ${encodeURIComponent(name)}`, 'success');
} else {
generateFlash(this.txt.addSubscriberError, 'error');
}
Expand Down Expand Up @@ -157,7 +158,7 @@ export default {
<div class="d-flex mb-4">
<form id="add-user-form" class="add-user-form w-100">
<label class="sr-only" for="addUser">{{ txt.search }}</label>
<autocomplete :group="encodeURIComponent(this.group.name)" @add="(id) => addSubscriber(id)" />
<autocomplete :group="encodeURIComponent(this.group.name)" @add="(item) => addSubscriber(item)" />
</form>
</div>
</div>
Expand All @@ -172,10 +173,10 @@ export default {
<td>
{{ subscriber.name }}
</td>
<td>
<td :colspan="remove ? 1 : 2">
{{ subscriber.id }}
</td>
<td>
<td v-if="remove">
<button :disabled="disabled.indexOf(subscriber.id) > -1" @click="removeSubscriber(group, subscriber)" class="btn btn-grouper btn-block btn-primary btn-sm m-1 text-nowrap member-del-btn">
{{ txt.remove }}
</button>
Expand Down
12 changes: 4 additions & 8 deletions webroot/js/page/GroupMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
Members,
NestedTable,
},
inject: ['txt', 'api', 'allowAddSubscribers', 'owner'],
inject: ['txt', 'api', 'owner'],
data() {
return {
view: null,
Expand All @@ -32,9 +32,6 @@ export default {
}
},
computed: {
nestedColumns() {
return this.owner ? ['name', 'role', 'description'] : ['name', 'description']
},
routePath() {
return `/groupmember/co:${this.api.co}/glid:${this.api.glid}`;
}
Expand All @@ -44,7 +41,6 @@ export default {
if (view !== 'working' && view !== 'adhoc') {
view = 'adhoc';
}
console.log(view);
this.view = view;
},
template: /*html*/`
Expand All @@ -61,7 +57,7 @@ export default {
<page-count :first="paginated.start" :last="paginated.end" :total="paginated.total"></page-count>
<groups-table
:groups="paginated.records"
:columns="['name', 'role', 'description', 'action']"
:columns="['name', 'description', 'action']"
:members="true"
@leave-group="searchResult.leave"
@show-subscribers="showSubscribers"></groups-table>
Expand All @@ -73,14 +69,14 @@ export default {
<nested-table
:nested="Groups"
:groups="paginated.records"
:columns="nestedColumns"
:columns="['name', 'role', 'description']"
:members="true"
@leave-group="searchResult.leave"
@show-subscribers="showSubscribers"></nested-table>
</template>
</pagination>
</template>
</groups>
<members ref="members" :add="allowAddSubscribers"></members>
<members ref="members" :add="false" :remove="false"></members>
`
}
6 changes: 3 additions & 3 deletions webroot/js/page/GroupOwner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
GroupsTable,
Members
},
inject: ['api', 'allowAddSubscribers'],
inject: ['api'],
methods: {
showSubscribers(group) {
this.$refs.members.show(group);
Expand All @@ -26,13 +26,13 @@ export default {
<page-count :first="paginated.start" :last="paginated.end" :total="paginated.total"></page-count>
<groups-table
:groups="paginated.records"
:columns="['name', 'role', 'description', 'action']"
:columns="['name', 'description', 'action']"
:members="true"
@show-subscribers="showSubscribers"></groups-table>
</template>
</pagination>
</template>
</groups>
<members ref="members" :add="allowAddSubscribers"></members>
<members ref="members" :add="true" :remove="true"></members>
`
}
3 changes: 3 additions & 0 deletions webroot/js/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default {
},
perPage(newValue) {
setQueryParam('limit', newValue);
if (newValue === 'all') {
this.currentPage = 1;
}
},
records(newValue) {
if (this.numbers <= 1) {
Expand Down

0 comments on commit 4cfa803

Please sign in to comment.