1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00
appwrite/public/scripts/events.js

217 lines
8.3 KiB
JavaScript
Raw Normal View History

2022-04-28 23:40:59 +12:00
(function (window) {
document.addEventListener('alpine:init', () => {
Alpine.data('events', () => ({
2022-05-09 01:09:08 +12:00
events: new Set(),
2022-04-28 23:40:59 +12:00
selected: null,
action: null,
type: null,
subType: null,
2022-06-28 05:12:40 +12:00
subSubType: null,
2022-04-28 23:40:59 +12:00
resource: null,
resourceName: '',
subResource: null,
subResourceName: '',
2022-06-28 05:12:40 +12:00
subSubResource: null,
subSubResourceName: '',
2022-04-28 23:40:59 +12:00
hasResource: false,
hasSubResource: false,
2022-06-28 05:12:40 +12:00
hasSubSubResource: false,
2022-04-28 23:40:59 +12:00
attribute: null,
hasAttribute: false,
attributes: [],
2022-05-09 01:09:08 +12:00
load(events) {
this.events = new Set(events);
},
2022-05-04 22:54:34 +12:00
reset() {
2022-06-28 05:12:40 +12:00
this.hasResource = this.hasSubResource = this.hasSubSubResource = this.hasAttribute = false;
2022-05-04 22:54:34 +12:00
this.type = this.subType = this.subResource = this.resource = this.attribute = this.selected = this.action = null;
},
2022-04-28 23:40:59 +12:00
setEvent() {
2022-06-28 05:12:40 +12:00
this.hasResource = this.hasSubResource = this.hasSubSubResource = this.hasAttribute = this.action = false;
2022-04-28 23:40:59 +12:00
2022-05-04 22:54:34 +12:00
if (!this.selected) {
this.reset();
return;
}
2022-04-28 23:40:59 +12:00
let [type, action] = this.selected.split('.');
switch (type) {
case 'users':
if (action === 'update') {
this.hasAttribute = true;
this.attributes = ['email', 'name', 'password', 'status', 'prefs']
}
this.hasResource = true;
this.type = type;
this.resourceName = 'User ID';
break;
case 'collections':
2022-06-28 05:12:40 +12:00
this.hasResource = this.hasSubResource = true;
this.type = 'databases';
this.subType = type;
this.resourceName = 'Database ID';
this.subResourceName = 'Collection ID';
break;
case 'databases':
2022-04-28 23:40:59 +12:00
this.hasResource = true;
this.type = type;
2022-06-28 05:12:40 +12:00
this.resourceName = 'Database ID';
2022-04-28 23:40:59 +12:00
break;
case 'teams':
this.hasResource = true;
this.type = type;
this.resourceName = 'Team ID';
break;
case 'buckets':
this.hasResource = true;
this.type = type;
this.resourceName = 'Bucket ID';
break;
case 'functions':
this.hasResource = true;
this.type = type;
this.resourceName = 'Function ID';
break;
case 'sessions':
this.hasResource = this.hasSubResource = true;
this.type = 'users';
this.subType = type;
this.resourceName = 'User ID';
this.subResourceName = 'Session ID';
break;
case 'verification':
this.hasResource = this.hasSubResource = true;
this.type = 'users';
this.subType = type;
this.resourceName = 'User ID';
this.subResourceName = 'Verification ID';
break;
case 'recovery':
this.hasResource = this.hasSubResource = true;
this.type = 'users';
this.subType = type;
this.resourceName = 'User ID';
this.subResourceName = 'Recovery ID';
break;
case 'documents':
2022-06-28 05:12:40 +12:00
this.hasResource = this.hasSubResource = this.hasSubSubResource = true;
this.type = 'databases';
this.subType = 'collections';
this.subSubType = type;
this.resourceName = 'Database ID';
this.subResourceName = 'Collection ID';
this.subSubResourceName = 'Document ID';
2022-04-28 23:40:59 +12:00
break;
case 'attributes':
this.hasResource = this.hasSubResource = true;
this.type = 'collections';
this.subType = type;
this.resourceName = 'Collection ID';
this.subResourceName = 'Attribute ID';
break;
case 'indexes':
this.hasResource = this.hasSubResource = true;
this.type = 'collections';
this.subType = type;
this.resourceName = 'Collection ID';
this.subResourceName = 'Index ID';
break;
case 'files':
this.hasResource = this.hasSubResource = true;
this.type = 'buckets';
this.subType = type;
this.resourceName = 'Bucket ID';
this.subResourceName = 'File ID';
break;
case 'memberships':
if (action === 'update') {
this.hasAttribute = true;
this.attributes = ['status']
}
this.hasResource = this.hasSubResource = true;
this.type = 'teams';
this.subType = type;
this.resourceName = 'Team ID';
this.subResourceName = 'Membership ID';
break;
case 'executions':
this.hasResource = this.hasSubResource = true;
this.type = 'functions';
this.subType = type;
this.resourceName = 'Function ID';
this.subResourceName = 'Execution ID';
break;
case 'deployments':
this.hasResource = this.hasSubResource = true;
this.type = 'functions';
this.subType = type;
this.resourceName = 'Function ID';
this.subResourceName = 'Deployment ID';
break;
default:
this.hasResource = true;
this.hasSubResource = true;
2022-06-28 05:12:40 +12:00
this.hasSubSubResource = true;
2022-04-28 23:40:59 +12:00
break;
}
this.action = action;
},
2022-05-09 01:09:08 +12:00
showModal(modal) {
document.documentElement.classList.add("modal-open");
modal.classList.remove("close");
modal.classList.add("open");
},
closeModal(modal) {
document.documentElement.classList.remove("modal-open");
modal.classList.add("close");
modal.classList.remove("open");
},
2022-05-06 20:49:37 +12:00
addEvent(modal) {
2022-05-09 01:09:08 +12:00
this.closeModal(modal);
2022-05-06 20:49:37 +12:00
2022-04-28 23:40:59 +12:00
let event = `${this.type}.${this.resource ? this.resource : '*'}`;
if (this.hasSubResource) {
event += `.${this.subType}.${this.subResource ? this.subResource : '*'}`;
}
2022-06-28 05:12:40 +12:00
if (this.hasSubSubResource) {
event += `.${this.subSubType}.${this.subSubResource ? this.subSubResource : '*'}`;
}
2022-04-28 23:40:59 +12:00
if (this.action) {
event += `.${this.action}`;
}
if (this.attribute) {
event += `.${this.attribute}`;
}
2022-05-09 01:09:08 +12:00
this.events.add(event);
2022-04-28 23:40:59 +12:00
2022-05-04 22:54:34 +12:00
this.reset();
2022-04-28 23:40:59 +12:00
},
2022-05-09 01:09:08 +12:00
removeEvent(value) {
this.events.delete(value);
2022-04-28 23:40:59 +12:00
}
}));
});
})(window);