Add basic Buefy support for merging 2 objects
i.e. special grid stuff, plus "merge" view
This commit is contained in:
parent
9d6cc86e60
commit
b2b4e1bfbc
|
@ -1116,6 +1116,11 @@ class Grid(object):
|
|||
value = ""
|
||||
row[name] = six.text_type(value)
|
||||
|
||||
# maybe add UUID for convenience
|
||||
if 'uuid' not in self.columns:
|
||||
if hasattr(rowobj, 'uuid'):
|
||||
row['uuid'] = rowobj.uuid
|
||||
|
||||
# set action URL(s) for row, as needed
|
||||
self.set_action_urls(row, rowobj, i)
|
||||
|
||||
|
|
|
@ -84,6 +84,13 @@
|
|||
:loading="loading"
|
||||
:row-class="getRowClass"
|
||||
|
||||
% if grid.checkboxes:
|
||||
checkable
|
||||
:checked-rows.sync="checkedRows"
|
||||
## TODO: definitely will be wanting this...
|
||||
## :is-row-checkable=""
|
||||
% endif
|
||||
|
||||
:default-sort="[sortField, sortOrder]"
|
||||
backend-sorting
|
||||
@sort="onSort"
|
||||
|
@ -161,6 +168,8 @@
|
|||
sortField: '${grid.sortkey}',
|
||||
sortOrder: '${grid.sortdir}',
|
||||
rowStatusMap: ${json.dumps(grid_data['row_status_map'])|n},
|
||||
## TODO: should be dumping json from server here
|
||||
checkedRows: [],
|
||||
|
||||
% if grid.pageable:
|
||||
% if static_data:
|
||||
|
@ -307,6 +316,14 @@
|
|||
if (confirm("You are about to delete " + this.total + " ${grid.model_title_plural}.\n\nAre you sure?")) {
|
||||
event.target.form.submit()
|
||||
}
|
||||
},
|
||||
|
||||
checkedRowUUIDs() {
|
||||
var uuids = [];
|
||||
for (var row of this.$data.checkedRows) {
|
||||
uuids.push(row.uuid)
|
||||
}
|
||||
return uuids
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,10 +134,24 @@
|
|||
|
||||
## merge 2 objects
|
||||
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
|
||||
|
||||
${h.form(url('{}.merge'.format(route_prefix)), name='merge-things', class_='control')}
|
||||
${h.csrf_token(request)}
|
||||
${h.hidden('uuids')}
|
||||
<button type="submit" class="button">Merge 2 ${model_title_plural}</button>
|
||||
% if use_buefy:
|
||||
<input type="hidden"
|
||||
name="uuids"
|
||||
:value="checkedRowUUIDs()" />
|
||||
<b-button type="is-primary"
|
||||
native-type="submit"
|
||||
icon-pack="fas"
|
||||
icon-left="object-ungroup"
|
||||
:disabled="checkedRows.length != 2">
|
||||
Merge 2 ${model_title_plural}
|
||||
</b-button>
|
||||
% else:
|
||||
${h.hidden('uuids')}
|
||||
<button type="submit" class="button">Merge 2 ${model_title_plural}</button>
|
||||
% endif
|
||||
${h.end_form()}
|
||||
% endif
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
<%def name="title()">Merge 2 ${model_title_plural}</%def>
|
||||
|
||||
<%def name="head_tags()">
|
||||
${parent.head_tags()}
|
||||
<%def name="extra_javascript()">
|
||||
${parent.extra_javascript()}
|
||||
% if not use_buefy:
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
|
@ -29,11 +30,17 @@
|
|||
});
|
||||
|
||||
</script>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="extra_styles()">
|
||||
${parent.extra_styles()}
|
||||
<style type="text/css">
|
||||
p {
|
||||
margin: 20px auto;
|
||||
}
|
||||
p.warning {
|
||||
p.warning,
|
||||
p.warning strong {
|
||||
color: red;
|
||||
}
|
||||
a.merge-object {
|
||||
|
@ -132,6 +139,36 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
% if use_buefy:
|
||||
|
||||
<div class="level" style="margin-top: 2em;">
|
||||
<div class="level-left">
|
||||
|
||||
<div class="level-item">
|
||||
<a class="button" href="${index_url}">Whoops, nevermind</a>
|
||||
</div>
|
||||
|
||||
<div class="level-item">
|
||||
${h.form(request.current_route_url())}
|
||||
${h.csrf_token(request)}
|
||||
${h.hidden('uuids', value='{},{}'.format(object_to_keep.uuid, object_to_remove.uuid))}
|
||||
${h.submit('submit', "Swap which {} is kept/removed".format(model_title), class_='button')}
|
||||
${h.end_form()}
|
||||
</div>
|
||||
|
||||
<div class="level-item">
|
||||
${h.form(request.current_route_url())}
|
||||
${h.csrf_token(request)}
|
||||
${h.hidden('uuids', value='{},{}'.format(object_to_remove.uuid, object_to_keep.uuid))}
|
||||
${h.hidden('commit-merge', value='yes')}
|
||||
${h.submit('merge', "Yes, perform this merge", class_='button is-primary')}
|
||||
${h.end_form()}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
% else:
|
||||
${h.form(request.current_route_url(), class_='merge')}
|
||||
${h.csrf_token(request)}
|
||||
<div class="buttons">
|
||||
|
@ -141,3 +178,4 @@ ${h.csrf_token(request)}
|
|||
${h.submit('merge', "Yes, perform this merge")}
|
||||
</div>
|
||||
${h.end_form()}
|
||||
% endif
|
||||
|
|
|
@ -82,6 +82,10 @@ class UsersView(PrincipalMasterView):
|
|||
'sent_message_count',
|
||||
'received_message_count',
|
||||
]
|
||||
merge_coalesce_fields = [
|
||||
'person_uuid',
|
||||
'person_name',
|
||||
]
|
||||
merge_fields = merge_additive_fields + [
|
||||
'uuid',
|
||||
'username',
|
||||
|
|
Loading…
Reference in a new issue