Skip to content

Commit

Permalink
add confirm for delete visual component
Browse files Browse the repository at this point in the history
add validator to component add
  • Loading branch information
A1Gard committed May 19, 2021
1 parent 6fb1790 commit 153ac31
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anubias",
"version": "0.2.0",
"version": "0.2.1",
"private": true,
"description": "anubias desktop application",
"author": {
Expand Down
3 changes: 3 additions & 0 deletions src/components/elements/PropertyElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ td {
border-bottom: 0;
padding: 0;
margin: 0;
overflow: hidden;
height: 30px;
}

tr:last-child td, tr:last-child th {
Expand All @@ -144,6 +146,7 @@ input, select, .dropdown {
line-height: 1.2em !important;
height: auto !important;
margin: 0 !important;
box-sizing: border-box;
}

select option {
Expand Down
3 changes: 1 addition & 2 deletions src/components/flutter/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export default {

<style scoped>
#appBar {
font-size: 24px;
padding: 10px;
margin-bottom: 5px !important;
}
.fa{
margin-right: .3em;
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/AboutPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</titlec>
<div>
<h1>
Abubias v0.2.0
Abubias v0.2.1
</h1>
<img src="@/assets/img/logo.svg" alt="logo" class="logo">
<h2>
Expand Down
57 changes: 50 additions & 7 deletions src/components/pages/MainAppPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@
<div id="mobile" :class="(data.pages.length < 1?'inactive':'')"
:style="'width:'+(display.landscape?display.height:display.width )* display.scale+'px;height:'+(display.landscape?display.width:display.height ) * display.scale+'px'+';background-color:'+data.project.bgColor+';color:'+data.project.textColor+' !important' ">
<!-- direction of project and page padding -->
<div id="dir" :style="'direction:'+(data.project.isRTL?'rtl':'ltr')+';padding:'+calcPadding(data.pages[currentPage].padding,this.display.scale)">
<div id="dir"
:style="'direction:'+(data.project.isRTL?'rtl':'ltr')+';padding:'+calcPadding(data.pages[currentPage].padding,this.display.scale)">
<!-- visual components of page -->
<div
v-if="data.pages[currentPage] !== undefined && data.pages[currentPage].children.visual !== undefined">
<span v-for="(comp,i) in data.pages[currentPage].children.visual"
:key="i">
<simulator @dblclick.native="removeVisual(i)" @click.native="currentProperties = comp;"
:type="comp.type" :properties="comp" :scale="display.scale" :page="data.pages[currentPage]"></simulator>
:type="comp.type" :properties="comp" :scale="display.scale"
:page="data.pages[currentPage]"></simulator>
</span>
</div>

Expand Down Expand Up @@ -257,19 +259,52 @@ export default {
window.alertify.error('Cancel')
});
},
visualValidator: function (component, visuals) {
if (component.type === 'appbar') {
// check non duplicate app bar
for (const comp of visuals) {
if (comp.type === 'appbar') {
window.alertify.warning("You can't drop two AppBar in page");
return false;
}
}
// add appbar
visuals.unshift(component);
return true;
}
// add component
visuals.push(component);
// choose name
// check not duplicate name add number to name
let names = [];
for (const comp of visuals) {
names.push(comp.name);
}
let i = 0;
let nextName = false;
do {
nextName = false;
i++;
if (names.indexOf(component.type +i.toString()) > -1) {
nextName = true;
}
} while (nextName);
visuals[visuals.length -1 ].name = component.type +i.toString();
return true;
},
onVisualDrop(event) { // on add a viusal component to page
// this.evenDropped.push(event.data);
try {
// find component
var component = window.components[event.data];
let component = window.components[event.data];
// load default value
var properties = eval(component.data);
let properties = eval(component.data);
// if can't loaded
if (properties === undefined) {
window.alertify.warning('Invalid component', 15);
} else {
// when loaded add to page
this.data.pages[this.currentPage].children.visual.push(properties);
// when loaded add to page with validate
this.visualValidator(properties, this.data.pages[this.currentPage].children.visual);
// ***!*** need sort and rename here
}
} catch (e) {
Expand All @@ -283,7 +318,15 @@ export default {
console.log(event);
},
removeVisual(n) { // remove visual component from page
this.data.pages[this.currentPage].children.visual.splice(n, 1);
var self = this;
window.alertify.confirm(`Are you sure to remove this component
"${this.data.pages[this.currentPage].children.visual[n].name}" ?`,
'Remove confirm', function () {
self.data.pages[self.currentPage].children.visual.splice(n, 1)
}
, function () {
// window.alertify.error('Cancel')
});
},
isVisual: function (n) { // check is visual component or not
return window.components[n].visual;
Expand Down

0 comments on commit 153ac31

Please sign in to comment.