Add basic Buefy support for merging 2 objects

i.e. special grid stuff, plus "merge" view
This commit is contained in:
Lance Edgar 2019-05-06 21:43:59 -05:00
parent 9d6cc86e60
commit b2b4e1bfbc
5 changed files with 83 additions and 5 deletions

View file

@ -1116,6 +1116,11 @@ class Grid(object):
value = "" value = ""
row[name] = six.text_type(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 # set action URL(s) for row, as needed
self.set_action_urls(row, rowobj, i) self.set_action_urls(row, rowobj, i)

View file

@ -84,6 +84,13 @@
:loading="loading" :loading="loading"
:row-class="getRowClass" :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]" :default-sort="[sortField, sortOrder]"
backend-sorting backend-sorting
@sort="onSort" @sort="onSort"
@ -161,6 +168,8 @@
sortField: '${grid.sortkey}', sortField: '${grid.sortkey}',
sortOrder: '${grid.sortdir}', sortOrder: '${grid.sortdir}',
rowStatusMap: ${json.dumps(grid_data['row_status_map'])|n}, rowStatusMap: ${json.dumps(grid_data['row_status_map'])|n},
## TODO: should be dumping json from server here
checkedRows: [],
% if grid.pageable: % if grid.pageable:
% if static_data: % if static_data:
@ -307,6 +316,14 @@
if (confirm("You are about to delete " + this.total + " ${grid.model_title_plural}.\n\nAre you sure?")) { if (confirm("You are about to delete " + this.total + " ${grid.model_title_plural}.\n\nAre you sure?")) {
event.target.form.submit() event.target.form.submit()
} }
},
checkedRowUUIDs() {
var uuids = [];
for (var row of this.$data.checkedRows) {
uuids.push(row.uuid)
}
return uuids
} }
} }

View file

@ -134,10 +134,24 @@
## merge 2 objects ## merge 2 objects
% if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)): % if master.mergeable and request.has_perm('{}.merge'.format(permission_prefix)):
${h.form(url('{}.merge'.format(route_prefix)), name='merge-things', class_='control')} ${h.form(url('{}.merge'.format(route_prefix)), name='merge-things', class_='control')}
${h.csrf_token(request)} ${h.csrf_token(request)}
% 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')} ${h.hidden('uuids')}
<button type="submit" class="button">Merge 2 ${model_title_plural}</button> <button type="submit" class="button">Merge 2 ${model_title_plural}</button>
% endif
${h.end_form()} ${h.end_form()}
% endif % endif

View file

@ -3,8 +3,9 @@
<%def name="title()">Merge 2 ${model_title_plural}</%def> <%def name="title()">Merge 2 ${model_title_plural}</%def>
<%def name="head_tags()"> <%def name="extra_javascript()">
${parent.head_tags()} ${parent.extra_javascript()}
% if not use_buefy:
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
@ -29,11 +30,17 @@
}); });
</script> </script>
% endif
</%def>
<%def name="extra_styles()">
${parent.extra_styles()}
<style type="text/css"> <style type="text/css">
p { p {
margin: 20px auto; margin: 20px auto;
} }
p.warning { p.warning,
p.warning strong {
color: red; color: red;
} }
a.merge-object { a.merge-object {
@ -132,6 +139,36 @@
</tbody> </tbody>
</table> </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.form(request.current_route_url(), class_='merge')}
${h.csrf_token(request)} ${h.csrf_token(request)}
<div class="buttons"> <div class="buttons">
@ -141,3 +178,4 @@ ${h.csrf_token(request)}
${h.submit('merge', "Yes, perform this merge")} ${h.submit('merge', "Yes, perform this merge")}
</div> </div>
${h.end_form()} ${h.end_form()}
% endif

View file

@ -82,6 +82,10 @@ class UsersView(PrincipalMasterView):
'sent_message_count', 'sent_message_count',
'received_message_count', 'received_message_count',
] ]
merge_coalesce_fields = [
'person_uuid',
'person_name',
]
merge_fields = merge_additive_fields + [ merge_fields = merge_additive_fields + [
'uuid', 'uuid',
'username', 'username',