1
0
Fork 0
mirror of synced 2024-06-24 17:20:36 +12:00

feat: event model ui init

This commit is contained in:
Torsten Dittmann 2022-04-28 13:40:59 +02:00
parent 840f7419dc
commit 1457bab4b1
7 changed files with 305 additions and 51 deletions

View file

@ -162,9 +162,7 @@ App::get('/console/webhooks')
$page = new View(__DIR__.'/../../views/console/webhooks/index.phtml');
$page
->setParam('events', Config::getParam('events', []))
;
$page->setParam('events', Config::getParam('events', []));
$layout
->setParam('title', APP_NAME.' - Webhooks')

View file

@ -1,8 +1,27 @@
<?php
$events = array_keys($this->getParam('events', []));
$events = $this->getParam('events', []);
foreach ($events as $name => $event) {
foreach ($event as $key => $value) {
if (!\str_starts_with($key, '$')) {
if (!($value['$resource'] ?? false)) {
$patterns[] = "{$name}.{$key}";
} else {
foreach ($value as $key2 => $value2) {
if (!\str_starts_with($key2, '$')) {
if (!($value2['$resource'] ?? false)) {
$patterns[] = "{$key}.{$key2}";
}
}
}
}
}
}
}
?>
<div class="cover margin-bottom-large">
<h1 class="zone xl margin-bottom-large">
<a data-ls-attrs="href=/console/home?project={{router.params.project}}" class="back text-size-small link-return-animation--start"><i class="icon-left-open"></i> Home</a>
@ -61,22 +80,46 @@ $events = array_keys($this->getParam('events', []));
<label data-ls-attrs="for=url-{{webhook.$id}}">POST URL</label>
<input type="url" class="full-width" data-ls-attrs="id=url-{{webhook.$id}}" name="url" required autocomplete="off" placeholder="https://example.com/callback" data-ls-bind="{{webhook.url}}" />
<section data-forms-select-all>
<label data-ls-attrs="for=events-{{webhook.$id}}">Events</label>
<div class="row responsive thin">
<?php foreach ($events as $i => $event): ?>
<div class="col span-6 text-one-liner margin-bottom text-height-large text-size-small" title="<?php echo $event; ?>">
<input type="checkbox" name="events" data-ls-bind="{{webhook.events}}" id="update-<?php echo $event; ?>" value="<?php echo $event; ?>" data-by-key="true" />
&nbsp;
<label class="inline" for="update-<?php echo $event; ?>"><?php echo $event; ?></label>
<section x-data="events" class="margin-bottom-small" data-ls-attrs="x-init=events={{webhook.events}}">
<label>Events</label>
<template x-for="(event, index) in events">
<div class="row responsive thin margin-bottom-tiny">
<div class="col span-12 margin-bottom-small">
<span x-text="event"></span>
<span class="pull-end" style="cursor: pointer;" @click="removeEvent(index)">
<i class="icon-trash"></i>
</span>
</div>
<?php if (($i + 1) % 2 === 0): ?>
</div>
<div class="row responsive thin">
<?php endif;?>
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
<label>Add event</label>
<select x-model="selected" @change="setEvent()">
<option value="" selected>---</option>
<?php foreach ($patterns as $event): ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach;?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent()">Add Event</button>
</section>
<div class="margin-bottom toggle" data-ls-ui-open data-button-aria="Advanced Options">
@ -99,7 +142,7 @@ $events = array_keys($this->getParam('events', []));
<a href="https://en.wikipedia.org/wiki/Self-signed_certificate" target="_blank" rel="noopener">Learn more<i class="icon-link-ext"></i></a>
</p>
<label class="text-bold">HTTP Authentication <span class="tooltip" data-tooltip="Use to secure your endpoint from untrusted sources"><i class="icon-question"></i></span> &nbsp;<small>(optional)</small></label>
<label>HTTP Authentication <span class="tooltip" data-tooltip="Use to secure your endpoint from untrusted sources"><i class="icon-question"></i></span> &nbsp;<small>(optional)</small></label>
<div class="row responsive thin">
<div class="col span-6 margin-bottom">
@ -183,22 +226,46 @@ $events = array_keys($this->getParam('events', []));
<label for="url">POST URL</label>
<input type="url" class="full-width" id="url" name="url" required autocomplete="off" placeholder="https://example.com/callback" />
<section data-forms-select-all>
<label for="events">Events</label>
<div class="row responsive thin">
<?php foreach ($events as $i => $event): ?>
<div class="col span-6 text-one-liner margin-bottom text-height-large text-size-small" title="<?php echo $event; ?>">
<input type="checkbox" name="events" id="add-<?php echo $event; ?>" value="<?php echo $event; ?>" data-by-key="true" />
&nbsp;
<label class="inline" for="add-<?php echo $event; ?>"><?php echo $event; ?></label>
<section x-data="events" class="margin-bottom-small">
<label>Events</label>
<template x-for="(event, index) in events">
<div class="row responsive thin margin-bottom-tiny">
<div class="col span-12 margin-bottom-small">
<span x-text="event"></span>
<span class="pull-end" style="cursor: pointer;" @click="removeEvent(index)">
<i class="icon-trash"></i>
</span>
</div>
<?php if (($i + 1) % 2 === 0): ?>
</div>
<div class="row responsive thin">
<?php endif;?>
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
<label>Add event</label>
<select x-model="selected" @change="setEvent()">
<option value="" selected>---</option>
<?php foreach ($patterns as $event): ?>
<option value="<?php echo $event; ?>"><?php echo $event; ?></option>
<?php endforeach;?>
</select>
<div x-show="hasResource">
<label x-text="'Select ' + resourceName + ' (optional)'"></label>
<input type="text" :placeholder="resourceName" x-model="resource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasSubResource">
<label x-text="'Select ' + subResourceName + ' (optional)'"></label>
<input type="text" :placeholder="subResourceName" x-model="subResource">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom">Leave empty for wildcard access</div>
</div>
<div x-show="hasAttribute">
<label for="subResource">Add Attribute (optional)</label>
<select x-model="attribute">
<option value="*">Select attribute</option>
<template x-for="attr in attributes">
<option :value="attr" x-text="attr"></option>
</template>
</select>
</div>
<button x-show="selected" type="button" @click="addEvent()">Add Event</button>
</section>
<div class="margin-bottom toggle" data-ls-ui-open data-button-aria="Advanced Options">
@ -221,7 +288,7 @@ $events = array_keys($this->getParam('events', []));
<a href="https://en.wikipedia.org/wiki/Self-signed_certificate" target="_blank" rel="noopener">Learn more<i class="icon-link-ext"></i></a>
</p>
<label class="text-bold">HTTP Authentication <span class="tooltip" data-tooltip="Use to secure your endpoint from untrusted sources"><i class="icon-question"></i></span> &nbsp;<small>(optional)</small></label>
<label>HTTP Authentication <span class="tooltip" data-tooltip="Use to secure your endpoint from untrusted sources"><i class="icon-question"></i></span> &nbsp;<small>(optional)</small></label>
<div class="row responsive thin">
<div class="col span-6 margin-bottom">

View file

@ -34,6 +34,7 @@ const configApp = {
'public/scripts/filters.js',
'public/scripts/app.js',
'public/scripts/upload-modal.js',
'public/scripts/events.js',
'public/scripts/views/service.js',

32
package-lock.json generated
View file

@ -2950,6 +2950,15 @@
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"dev": true
},
"node_modules/meow/node_modules/trim-newlines": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz",
"integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/micromatch": {
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz",
@ -4601,18 +4610,6 @@
"xtend": "~4.0.1"
}
},
"node_modules/trim-newlines": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-4.0.2.tgz",
"integrity": "sha512-GJtWyq9InR/2HRiLZgpIKv+ufIKrVrvjQWEj7PxAXNc5dwbNJkqhAUoAGgzRmULAnoOM5EIpveYd3J2VeSAIew==",
"dev": true,
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
@ -7490,6 +7487,12 @@
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"dev": true
},
"trim-newlines": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz",
"integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=",
"dev": true
}
}
},
@ -8837,11 +8840,6 @@
}
}
},
"trim-newlines": {
"version": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-4.0.2.tgz",
"integrity": "sha512-GJtWyq9InR/2HRiLZgpIKv+ufIKrVrvjQWEj7PxAXNc5dwbNJkqhAUoAGgzRmULAnoOM5EIpveYd3J2VeSAIew==",
"dev": true
},
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",

View file

@ -3748,7 +3748,13 @@ let write=formData.get('write');if(write){write=JSON.parse(write);}
if(this.getFile(id)){this.updateFile(id,{name:file.name,completed:false,failed:false,cancelled:false,error:"",});}else{this.addFile({id:id,name:file.name,progress:0,completed:false,failed:false,cancelled:false,error:"",});}
target.reset();try{const response=await sdk.storage.createFile(bucketId,fileId,file,read,write,(progress)=>{this.updateFile(id,{id:progress.$id,progress:Math.round(progress.progress),error:"",});id=progress.$id;const file=this.getFile(id)??{};if(file.cancelled===true){throw'USER_CANCELLED';}});const existingFile=this.getFile(id)??{};if(existingFile.cancelled){this.updateFile(id,{id:response.$id,name:response.name,failed:false,});id=response.$id;throw'USER_CANCELLED'}else{this.updateFile(id,{id:response.$id,name:response.name,progress:100,completed:true,failed:false,});id=response.$id;}
document.dispatchEvent(new CustomEvent('storage.createFile'));}catch(error){if(error==='USER_CANCELLED'){await sdk.storage.deleteFile(bucketId,id);this.updateFile(id,{cancelled:false,failed:true,});this.removeFile(id);}else{this.updateFile(id,{id:id,failed:true,error:error.message??error});}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){"use strict";window.ls.view.add({selector:"data-service",controller:function(element,view,container,form,alerts,expression,window){let action=element.dataset["service"];let service=element.dataset["name"]||null;let event=expression.parse(element.dataset["event"]);let confirm=element.dataset["confirm"]||"";let loading=element.dataset["loading"]||"";let loaderId=null;let scope=element.dataset["scope"]||"sdk";let success=element.dataset["success"]||"";let failure=element.dataset["failure"]||"";let running=false;let callbacks={hide:function(){return function(){return element.style.opacity='0';};},reset:function(){return function(){if("FORM"===element.tagName){return element.reset();}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){document.addEventListener('alpine:init',()=>{Alpine.data('events',()=>({events:[],selected:null,action:null,type:null,subType:null,resource:null,resourceName:'',subResource:null,subResourceName:'',hasResource:false,hasSubResource:false,attribute:null,hasAttribute:false,attributes:[],setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!event)return;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':this.hasResource=true;this.type=type;this.resourceName='Collection ID';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':this.hasResource=this.hasSubResource=true;this.type='collections';this.subType=type;this.resourceName='Collection ID';this.subResourceName='Document ID';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;break;}
this.action=action;},addEvent(){let event=`${this.type}.${this.resource ? this.resource : '*'}`;if(this.hasSubResource){event+=`.${this.subType}.${this.subResource ? this.subResource : '*'}`;}
if(this.action){event+=`.${this.action}`;}
if(this.attribute){event+=`.${this.attribute}`;}
this.events.push(event);this.status=[];this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},removeEvent(index){this.events.splice(index,1);}}));});})(window);(function(window){"use strict";window.ls.view.add({selector:"data-service",controller:function(element,view,container,form,alerts,expression,window){let action=element.dataset["service"];let service=element.dataset["name"]||null;let event=expression.parse(element.dataset["event"]);let confirm=element.dataset["confirm"]||"";let loading=element.dataset["loading"]||"";let loaderId=null;let scope=element.dataset["scope"]||"sdk";let success=element.dataset["success"]||"";let failure=element.dataset["failure"]||"";let running=false;let callbacks={hide:function(){return function(){return element.style.opacity='0';};},reset:function(){return function(){if("FORM"===element.tagName){return element.reset();}
throw new Error("This callback is only valid for forms");};},alert:function(text,classname){return function(alerts){alerts.add({text:text,class:classname||"success"},6000);};},redirect:function(url){return function(router){if(url==="/console"){window.location=url;return;}
router.change(url||"/");};},reload:function(){return function(router){router.reload();};},state:function(keys){let updateQueryString=function(key,value,url){var re=new RegExp("([?&])"+key+"=.*?(&|#|$)(.*)","gi"),hash;if(re.test(url)){if(typeof value!=="undefined"&&value!==null){return url.replace(re,"$1"+key+"="+value+"$2$3");}else{hash=url.split("#");url=hash[0].replace(re,"$1$3").replace(/(&|\?)$/,"");if(typeof hash[1]!=="undefined"&&hash[1]!==null){url+="#"+hash[1];}
return url;}}else{if(typeof value!=="undefined"&&value!==null){var separator=url.indexOf("?")!==-1?"&":"?";hash=url.split("#");url=hash[0]+separator+key+"="+value;if(typeof hash[1]!=="undefined"&&hash[1]!==null){url+="#"+hash[1];}

View file

@ -695,7 +695,13 @@ let write=formData.get('write');if(write){write=JSON.parse(write);}
if(this.getFile(id)){this.updateFile(id,{name:file.name,completed:false,failed:false,cancelled:false,error:"",});}else{this.addFile({id:id,name:file.name,progress:0,completed:false,failed:false,cancelled:false,error:"",});}
target.reset();try{const response=await sdk.storage.createFile(bucketId,fileId,file,read,write,(progress)=>{this.updateFile(id,{id:progress.$id,progress:Math.round(progress.progress),error:"",});id=progress.$id;const file=this.getFile(id)??{};if(file.cancelled===true){throw'USER_CANCELLED';}});const existingFile=this.getFile(id)??{};if(existingFile.cancelled){this.updateFile(id,{id:response.$id,name:response.name,failed:false,});id=response.$id;throw'USER_CANCELLED'}else{this.updateFile(id,{id:response.$id,name:response.name,progress:100,completed:true,failed:false,});id=response.$id;}
document.dispatchEvent(new CustomEvent('storage.createFile'));}catch(error){if(error==='USER_CANCELLED'){await sdk.storage.deleteFile(bucketId,id);this.updateFile(id,{cancelled:false,failed:true,});this.removeFile(id);}else{this.updateFile(id,{id:id,failed:true,error:error.message??error});}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){"use strict";window.ls.view.add({selector:"data-service",controller:function(element,view,container,form,alerts,expression,window){let action=element.dataset["service"];let service=element.dataset["name"]||null;let event=expression.parse(element.dataset["event"]);let confirm=element.dataset["confirm"]||"";let loading=element.dataset["loading"]||"";let loaderId=null;let scope=element.dataset["scope"]||"sdk";let success=element.dataset["success"]||"";let failure=element.dataset["failure"]||"";let running=false;let callbacks={hide:function(){return function(){return element.style.opacity='0';};},reset:function(){return function(){if("FORM"===element.tagName){return element.reset();}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){document.addEventListener('alpine:init',()=>{Alpine.data('events',()=>({events:[],selected:null,action:null,type:null,subType:null,resource:null,resourceName:'',subResource:null,subResourceName:'',hasResource:false,hasSubResource:false,attribute:null,hasAttribute:false,attributes:[],setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!event)return;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':this.hasResource=true;this.type=type;this.resourceName='Collection ID';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':this.hasResource=this.hasSubResource=true;this.type='collections';this.subType=type;this.resourceName='Collection ID';this.subResourceName='Document ID';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;break;}
this.action=action;},addEvent(){let event=`${this.type}.${this.resource ? this.resource : '*'}`;if(this.hasSubResource){event+=`.${this.subType}.${this.subResource ? this.subResource : '*'}`;}
if(this.action){event+=`.${this.action}`;}
if(this.attribute){event+=`.${this.attribute}`;}
this.events.push(event);this.status=[];this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},removeEvent(index){this.events.splice(index,1);}}));});})(window);(function(window){"use strict";window.ls.view.add({selector:"data-service",controller:function(element,view,container,form,alerts,expression,window){let action=element.dataset["service"];let service=element.dataset["name"]||null;let event=expression.parse(element.dataset["event"]);let confirm=element.dataset["confirm"]||"";let loading=element.dataset["loading"]||"";let loaderId=null;let scope=element.dataset["scope"]||"sdk";let success=element.dataset["success"]||"";let failure=element.dataset["failure"]||"";let running=false;let callbacks={hide:function(){return function(){return element.style.opacity='0';};},reset:function(){return function(){if("FORM"===element.tagName){return element.reset();}
throw new Error("This callback is only valid for forms");};},alert:function(text,classname){return function(alerts){alerts.add({text:text,class:classname||"success"},6000);};},redirect:function(url){return function(router){if(url==="/console"){window.location=url;return;}
router.change(url||"/");};},reload:function(){return function(router){router.reload();};},state:function(keys){let updateQueryString=function(key,value,url){var re=new RegExp("([?&])"+key+"=.*?(&|#|$)(.*)","gi"),hash;if(re.test(url)){if(typeof value!=="undefined"&&value!==null){return url.replace(re,"$1"+key+"="+value+"$2$3");}else{hash=url.split("#");url=hash[0].replace(re,"$1$3").replace(/(&|\?)$/,"");if(typeof hash[1]!=="undefined"&&hash[1]!==null){url+="#"+hash[1];}
return url;}}else{if(typeof value!=="undefined"&&value!==null){var separator=url.indexOf("?")!==-1?"&":"?";hash=url.split("#");url=hash[0]+separator+key+"="+value;if(typeof hash[1]!=="undefined"&&hash[1]!==null){url+="#"+hash[1];}

178
public/scripts/events.js Normal file
View file

@ -0,0 +1,178 @@
(function (window) {
document.addEventListener('alpine:init', () => {
Alpine.data('events', () => ({
events: [],
selected: null,
action: null,
type: null,
subType: null,
resource: null,
resourceName: '',
subResource: null,
subResourceName: '',
hasResource: false,
hasSubResource: false,
attribute: null,
hasAttribute: false,
attributes: [],
setEvent() {
this.hasResource = this.hasSubResource = this.hasAttribute = this.action = false;
if (!event) return;
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':
this.hasResource = true;
this.type = type;
this.resourceName = 'Collection ID';
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':
this.hasResource = this.hasSubResource = true;
this.type = 'collections';
this.subType = type;
this.resourceName = 'Collection ID';
this.subResourceName = 'Document ID';
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;
break;
}
this.action = action;
},
addEvent() {
let event = `${this.type}.${this.resource ? this.resource : '*'}`;
if (this.hasSubResource) {
event += `.${this.subType}.${this.subResource ? this.subResource : '*'}`;
}
if (this.action) {
event += `.${this.action}`;
}
if (this.attribute) {
event += `.${this.attribute}`;
}
this.events.push(event);
this.status = [];
this.hasResource = this.hasSubResource = this.hasAttribute = false;
this.type = this.subType = this.subResource = this.resource = this.attribute = this.selected = this.action = null;
},
removeEvent(index) {
this.events.splice(index, 1);
}
}));
});
})(window);