Skip to content

Commit

Permalink
Add draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyatthaya committed Jun 23, 2021
1 parent 1cdd8ad commit 9c26410
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/resources/js/components/BadasoContentAddField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
:placeholder="$t('content.fill.field.addField.name.placeholder')"
v-model="field.name"
size="12"
:alert="$v.field.name.$error ? $t('vuelidate.required', [ $t('content.fill.field.addField.name.title')]) : ''"
:alert="$v.field.type.$error ? [
$v.field.name.required ? '' : $t('vuelidate.required', [ $t('content.fill.field.addField.name.title')]),
$v.field.name.alphaNum ? '' : $t('vuelidate.alphaNum', [ $t('content.fill.field.addField.name.title')]),
$v.field.name.nonNumericOnFirstChar ? '' : $t('vuelidate.nonNumericOnFirstChar'),
] : ''"
></badaso-text>
</td>
<td v-show="show">
Expand Down Expand Up @@ -42,10 +46,12 @@
</template>

<script>
import { required } from "vuelidate/lib/validators";
import { required, alphaNum, helpers } from "vuelidate/lib/validators";
import contentHelper from '../utils/content-helper'
const nonNumericOnFirstChar = (value) => helpers.regex(value, /^(?![0-9_])\w+$/)
export default {
name : "BadasoContentAddField",
data: () => ({
Expand Down Expand Up @@ -74,6 +80,8 @@ export default {
},
name: {
required,
alphaNum,
nonNumericOnFirstChar: nonNumericOnFirstChar(this.name)
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions src/resources/js/lang/modules/en.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default {
vuelidate: {
nonNumericOnFirstChar: 'No numeric on first character.'
},
action: {
yes: "Yes",
no: "No"
Expand Down
3 changes: 3 additions & 0 deletions src/resources/js/lang/modules/id.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default {
vuelidate: {
nonNumericOnFirstChar: 'Tidak boleh diawali oleh angka.'
},
action: {
yes: "Ya",
no: "Tidak"
Expand Down
53 changes: 53 additions & 0 deletions src/resources/js/pages/content/add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@
>
<vs-icon icon="delete"></vs-icon>
</vs-button>
<vs-button
color="warning"
type="relief"
@click="moveUp(index)"
v-if="Object.values(items).length > 1"
:disabled="index === 0"
>
<vs-icon icon="expand_less"></vs-icon>
</vs-button>
<vs-button
color="warning"
type="relief"
@click="moveDown(index)"
v-if="Object.values(items).length > 1"
:disabled="index === Object.values(items).length - 1"
>
<vs-icon icon="expand_more"></vs-icon>
</vs-button>
</td>
</tr>
<tr :key="items.name + '-' + key + '-opened'" v-if="opened.includes(index)">
Expand Down Expand Up @@ -282,6 +300,41 @@ export default {
text: ""
};
}
},
moveDown(index) {
const temp = []
var tempObject = {}
for (const item in this.items) {
if (Object.hasOwnProperty.call(this.items, item)) {
temp.push(this.items[item])
}
}
[temp[index], temp[index + 1]] = [temp[index + 1], temp[index]]
tempObject = this.convertArrayToObject(temp, 'name')
this.items = tempObject
},
moveUp(index) {
const temp = []
var tempObject = {}
for (const item in this.items) {
if (Object.hasOwnProperty.call(this.items, item)) {
temp.push(this.items[item])
}
}
[temp[index], temp[index - 1]] = [temp[index - 1], temp[index]]
tempObject = this.convertArrayToObject(temp, 'name')
this.items = tempObject
},
convertArrayToObject(array, key) {
const initialValue = {};
return array.reduce((obj, item) => {
return {
...obj,
[item[key]]: item,
};
}, initialValue);
}
},
};
Expand Down
53 changes: 53 additions & 0 deletions src/resources/js/pages/content/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@
>
<vs-icon icon="delete"></vs-icon>
</vs-button>
<vs-button
color="warning"
type="relief"
@click="moveUp(index)"
v-if="Object.values(items).length > 1"
:disabled="index === 0"
>
<vs-icon icon="expand_less"></vs-icon>
</vs-button>
<vs-button
color="warning"
type="relief"
@click="moveDown(index)"
v-if="Object.values(items).length > 1"
:disabled="index === Object.values(items).length - 1"
>
<vs-icon icon="expand_more"></vs-icon>
</vs-button>
</td>
</tr>
<tr
Expand Down Expand Up @@ -329,6 +347,41 @@ export default {
};
}
},
moveDown(index) {
const temp = []
var tempObject = {}
for (const item in this.items) {
if (Object.hasOwnProperty.call(this.items, item)) {
temp.push(this.items[item])
}
}
[temp[index], temp[index + 1]] = [temp[index + 1], temp[index]]
tempObject = this.convertArrayToObject(temp, 'name')
this.items = tempObject
},
moveUp(index) {
const temp = []
var tempObject = {}
for (const item in this.items) {
if (Object.hasOwnProperty.call(this.items, item)) {
temp.push(this.items[item])
}
}
[temp[index], temp[index - 1]] = [temp[index - 1], temp[index]]
tempObject = this.convertArrayToObject(temp, 'name')
this.items = tempObject
},
convertArrayToObject(array, key) {
const initialValue = {};
return array.reduce((obj, item) => {
return {
...obj,
[item[key]]: item,
};
}, initialValue);
}
},
};
</script>
Expand Down

0 comments on commit 9c26410

Please sign in to comment.