1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00
This commit is contained in:
Torsten Dittmann 2022-05-08 15:09:08 +02:00
parent 809767401e
commit 6f2bdb527a
8 changed files with 117 additions and 99 deletions

View file

@ -489,7 +489,7 @@ foreach ($events as $name => $event) {
</div>
</div>
</li>
<li data-state="/console/functions/function/settings?id={{router.params.id}}&project={{router.params.project}}">
<li data-state="/console/functions/function/settings?id={{router.params.id}}&project={{router.params.project}}" x-data="events">
<h2>Settings</h2>
<div class="row responsive margin-top-negative">
@ -527,49 +527,20 @@ foreach ($events as $name => $event) {
<div class="text-size-small text-fade margin-bottom margin-top-negative-small">Max value is <?php echo $this->escape(number_format($timeout)); ?> seconds (<?php echo $this->escape((int) ($timeout / 60)); ?> minutes)</div>
</section>
<section x-data="events" class="margin-bottom-small" data-ls-attrs="x-init=events={{project-function.events}}">
<label class="margin-bottom">Events
<div data-ui-modal x-ref="modal" class="modal box close width-small height-small" data-button-text="Add Event" data-button-class="pull-end small">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</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($refs.modal)">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</div>
</label>
<template x-for="(event, index) in events">
<div class="row events responsive thin margin-bottom-small">
<div class="col span-12 margin-bottom-small">
<span class="text" x-text="event"></span>
<span class="action" @click="removeEvent(index)">
<i class="icon-trash"></i>
</span>
</div>
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
</section>
<section class="margin-bottom-small" data-ls-attrs="x-init=load({{project-function.events}})">
<label class="margin-bottom">Events <button class="pull-end small" type="button" @click="showModal($refs.modal)">Add Event</button></label>
<template x-for="event in Array.from(events)">
<div class="row events responsive thin margin-bottom-small">
<div class="col span-12 margin-bottom-small">
<span class="text" x-text="event"></span>
<span class="action" @click="removeEvent(event)">
<i class="icon-trash"></i>
</span>
</div>
<input name="events" data-cast-to="array" type="hidden" :value="event"></input>
</div>
</template>
</section>
<label for="schedule">Schedule (CRON Syntax) <span class="tooltip small" data-tooltip="Set a CRON schedule to trigger this function."><i class="icon-info-circled"></i></span></label>
<input type="text" id="function-schedule" class="full-width" name="schedule" autocomplete="off" data-ls-bind="{{project-function.schedule}}" placeholder="* * * * *" />
@ -647,6 +618,38 @@ foreach ($events as $name => $event) {
</form>
</div>
</div>
<div x-ref="modal" data-ui-modal class="modal box close width-small height-small" data-button-hide="on">
<div>
<form @submit.prevent="addEvent($refs.modal)">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</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="submit">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</form>
</div>
</div>
</li>
</ul>
</div>

View file

@ -45,8 +45,9 @@ foreach ($events as $name => $event) {
</h1>
</div>
<div class="zone xl">
<div class="row responsive margin-top-negative">
<div class="zone xl" x-data="events">
<h2 class="margin-top">Settings</h2>
<div class="row responsive">
<div class="col span-8 margin-bottom">
<label>&nbsp;</label>
@ -86,42 +87,13 @@ foreach ($events as $name => $event) {
<label data-ls-attrs="for=url-{{webhook.$id}}">POST URL</label>
<input type="url" class="full-width" data-ls-attrs="id=url-{{project-webhook.$id}}" name="url" required autocomplete="off" placeholder="https://example.com/callback" data-ls-bind="{{project-webhook.url}}" />
<section x-data="events" class="margin-bottom-small" data-ls-attrs="x-init=events={{project-webhook.events}}">
<label class="margin-bottom">Events
<div data-ui-modal x-ref="modal" class="modal box close width-small height-small" data-button-text="Add Event" data-button-class="pull-end small">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</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($refs.modal)">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</div>
</label>
<template x-for="(event, index) in events">
<section class="margin-bottom-small" data-ls-attrs="x-init=load({{project-webhook.events}})">
<label class="margin-bottom">Events <button class="pull-end small" type="button" @click="showModal($refs.modal_function)">Add Event</button></label>
<template x-for="event in Array.from(events)">
<div class="row events responsive thin margin-bottom-small">
<div class="col span-12 margin-bottom-small">
<span class="text" x-text="event"></span>
<span class="action" @click="removeEvent(index)">
<span class="action" @click="removeEvent(event)">
<i class="icon-trash"></i>
</span>
</div>
@ -186,6 +158,38 @@ foreach ($events as $name => $event) {
</form>
</div>
<?php endif; ?>
<div x-ref="modal_function" data-ui-modal class="modal box close width-small height-small" data-button-hide="on">
<div>
<form @submit.prevent="addEvent($refs.modal_function)">
<select x-model="selected" @change="setEvent()">
<option value="" selected>Select event</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="submit">Add Event</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</form>
</div>
</div>
</div>
</div>
</div>

View file

@ -3748,15 +3748,14 @@ 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){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:[],reset(){this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!this.selected){this.reset();return;}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){document.addEventListener('alpine:init',()=>{Alpine.data('events',()=>({events:new Set(),selected:null,action:null,type:null,subType:null,resource:null,resourceName:'',subResource:null,subResourceName:'',hasResource:false,hasSubResource:false,attribute:null,hasAttribute:false,attributes:[],load(events){this.events=new Set(events);},reset(){this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!this.selected){this.reset();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(modal){if(modal){document.documentElement.classList.remove("modal-open");modal.classList.add("close");modal.classList.remove("open");}
let event=`${this.type}.${this.resource ? this.resource : '*'}`;if(this.hasSubResource){event+=`.${this.subType}.${this.subResource ? this.subResource : '*'}`;}
this.action=action;},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");},addEvent(modal){this.closeModal(modal);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.reset();},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();}
this.events.add(event);this.reset();},removeEvent(value){this.events.delete(value);}}));});})(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,15 +695,14 @@ 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){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:[],reset(){this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!this.selected){this.reset();return;}
document.dispatchEvent(new CustomEvent('storage.createFile'));}}});});})(window);(function(window){document.addEventListener('alpine:init',()=>{Alpine.data('events',()=>({events:new Set(),selected:null,action:null,type:null,subType:null,resource:null,resourceName:'',subResource:null,subResourceName:'',hasResource:false,hasSubResource:false,attribute:null,hasAttribute:false,attributes:[],load(events){this.events=new Set(events);},reset(){this.hasResource=this.hasSubResource=this.hasAttribute=false;this.type=this.subType=this.subResource=this.resource=this.attribute=this.selected=this.action=null;},setEvent(){this.hasResource=this.hasSubResource=this.hasAttribute=this.action=false;if(!this.selected){this.reset();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(modal){if(modal){document.documentElement.classList.remove("modal-open");modal.classList.add("close");modal.classList.remove("open");}
let event=`${this.type}.${this.resource ? this.resource : '*'}`;if(this.hasSubResource){event+=`.${this.subType}.${this.subResource ? this.subResource : '*'}`;}
this.action=action;},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");},addEvent(modal){this.closeModal(modal);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.reset();},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();}
this.events.add(event);this.reset();},removeEvent(value){this.events.delete(value);}}));});})(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];}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
(function (window) {
document.addEventListener('alpine:init', () => {
Alpine.data('events', () => ({
events: [],
events: new Set(),
selected: null,
action: null,
type: null,
@ -15,6 +15,9 @@
attribute: null,
hasAttribute: false,
attributes: [],
load(events) {
this.events = new Set(events);
},
reset() {
this.hasResource = this.hasSubResource = this.hasAttribute = false;
this.type = this.subType = this.subResource = this.resource = this.attribute = this.selected = this.action = null;
@ -156,12 +159,18 @@
}
this.action = action;
},
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");
},
addEvent(modal) {
if (modal) {
document.documentElement.classList.remove("modal-open");
modal.classList.add("close");
modal.classList.remove("open");
}
this.closeModal(modal);
let event = `${this.type}.${this.resource ? this.resource : '*'}`;
@ -177,12 +186,12 @@
event += `.${this.attribute}`;
}
this.events.push(event);
this.events.add(event);
this.reset();
},
removeEvent(index) {
this.events.splice(index, 1);
removeEvent(value) {
this.events.delete(value);
}
}));
});

View file

@ -1,6 +1,6 @@
.events.row {
border-bottom: solid 1px var(--config-color-fade-super);
.col {
span.text {
display: inline-block;
@ -13,4 +13,8 @@
cursor: pointer;
}
}
&:last-child {
border-bottom: none;
}
}