@mixd-id/web-scaffold 0.1.230406019 → 0.1.230406021

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406019",
4
+ "version": "0.1.230406021",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -3,7 +3,7 @@
3
3
  <Transition name="alert-outer">
4
4
  <div v-if="!!state" :class="$style.alert" ref="alert">
5
5
  <Transition name="alert" @after-appear="onAfterAppear" appear>
6
- <div class="p-4 flex flex-col items-center leading-6">
6
+ <div :class="$style.cont1">
7
7
  <slot v-if="$slots['icon']" name="icon"></slot>
8
8
  <svg v-else-if="mode === 'alert'" width="100" height="100" class="fill-red-500" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
9
9
  <path fill-rule="evenodd" clip-rule="evenodd" d="M12 13.75C12.4142 13.75 12.75 13.4142 12.75 13V8.00001C12.75 7.5858 12.4142 7.25001 12 7.25001C11.5858 7.25001 11.25 7.5858 11.25 8.00001V13C11.25 13.4142 11.5858 13.75 12 13.75Z"/>
@@ -16,9 +16,9 @@
16
16
  <path fill-rule="evenodd" clip-rule="evenodd" d="M12 20.5C16.6944 20.5 20.5 16.6944 20.5 12C20.5 7.30558 16.6944 3.5 12 3.5C7.30558 3.5 3.5 7.30558 3.5 12C3.5 16.6944 7.30558 20.5 12 20.5ZM12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z"/>
17
17
  </svg>
18
18
 
19
- <div class="my-4 text-center flex-1 overflow-y-auto">
20
- <h5 class="my-1 break-all">{{ title }}</h5>
21
- <p class="break-words overflow-y-auto whitespace-pre-line text-center">{{ description }}</p>
19
+ <div :class="$style.cont2">
20
+ <h5 :class="$style.title">{{ title }}</h5>
21
+ <p :class="$style.description">{{ description }}</p>
22
22
  </div>
23
23
 
24
24
  <div class="mt-4" v-if="mode === 'alert'">
@@ -140,6 +140,22 @@ export default{
140
140
  @apply min-w-[280px] max-w-[80vw] md:max-w-[400px];
141
141
  }
142
142
 
143
+ .cont1{
144
+ @apply p-4 flex flex-col items-center leading-6;
145
+ }
146
+
147
+ .cont2{
148
+ @apply my-4 text-center flex-1 overflow-y-auto;
149
+ }
150
+
151
+ .title{
152
+ @apply my-1 break-words;
153
+ }
154
+
155
+ .description{
156
+ @apply break-words overflow-y-auto whitespace-pre-line text-center;
157
+ }
158
+
143
159
  </style>
144
160
 
145
161
  <style>
@@ -1,9 +1,9 @@
1
1
  <template>
2
2
  <div :class="computedClass">
3
3
  <slot name="start"></slot>
4
- <input :type="type" :disabled="isDisabled" @focus="isActive = true" @blur="onBlur"
4
+ <input :type="computedType" :disabled="isDisabled" @focus="isActive = true" @blur="onBlur"
5
5
  :placeholder="placeholder" :maxlength="maxlength" ref="input" autocomplete="new-password"
6
- :value="modelValue ?? value" @input="onInput" :readonly="Boolean(readonly)"
6
+ :value="displayedValue" @input="onInput" :readonly="Boolean(readonly)"
7
7
  @keydown="onKeyDown"/>
8
8
  <div v-if="!!(errors)">
9
9
  <svg :class="$style.svg" width="24" height="24" class="fill-red-500" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
@@ -100,6 +100,36 @@ export default{
100
100
 
101
101
  isDisabled(){
102
102
  return this.state === 2
103
+ },
104
+
105
+ displayedValue(){
106
+ if(this.isActive){
107
+ return this.modelValue ?? this.value
108
+ }
109
+ else{
110
+ switch(this.type){
111
+
112
+ case 'number':
113
+ const val = parseInt(this.modelValue)
114
+ return isNaN(val) ? '' : val.toLocaleString()
115
+
116
+ default:
117
+ return this.modelValue ?? this.value
118
+
119
+ }
120
+ }
121
+ },
122
+
123
+ computedType(){
124
+
125
+ switch(this.type){
126
+
127
+ case 'number':
128
+ return 'text'
129
+
130
+ default:
131
+ return this.type
132
+ }
103
133
  }
104
134
 
105
135
  },
@@ -228,6 +228,35 @@ const getPresetSortWhereParams = (order, afterItem) => {
228
228
  return sortWhere
229
229
  }
230
230
 
231
+ const unflatten = (flatObject) => {
232
+ const nestedObject = {};
233
+
234
+ for (const key in flatObject) {
235
+ if (Object.prototype.hasOwnProperty.call(flatObject, key)) {
236
+ const value = flatObject[key];
237
+ const keys = key.split('.');
238
+
239
+ let currentObj = nestedObject;
240
+ for (let i = 0; i < keys.length; i++) {
241
+ const currentKey = keys[i];
242
+
243
+ if (!currentObj[currentKey]) {
244
+ currentObj[currentKey] = {};
245
+ }
246
+
247
+ if (i === keys.length - 1) {
248
+ currentObj[currentKey] = value;
249
+ } else {
250
+ currentObj = currentObj[currentKey];
251
+ }
252
+ }
253
+ }
254
+ }
255
+
256
+ return nestedObject;
257
+ }
258
+
259
+
231
260
  module.exports = {
232
261
  ceil,
233
262
  floor,
@@ -244,5 +273,6 @@ module.exports = {
244
273
  writeStorage,
245
274
  bufferToStream,
246
275
  sequelizeChunk,
247
- getPresetSortWhereParams
276
+ getPresetSortWhereParams,
277
+ unflatten
248
278
  }
@@ -3,7 +3,7 @@ const fs = require("fs");
3
3
  const AdmZip = require("adm-zip");
4
4
  const glob = require("glob");
5
5
  const Exceljs = require("exceljs")
6
- const { saveBuffer } = require('./helpers.js')
6
+ const { saveBuffer, unflatten } = require('./helpers.js')
7
7
 
8
8
  const analyseRequest = async(req) => {
9
9
 
@@ -64,10 +64,17 @@ const analyseRequest = async(req) => {
64
64
 
65
65
  const columns = []
66
66
  const header = worksheet.getRow(1)
67
+
67
68
  if(!header)
68
69
  throw new Error('Invalid file')
69
70
  header.eachCell((cell) => {
70
- columns.push(cell.value)
71
+ if(cell.isMerged){
72
+ const sub = worksheet.getCell(cell.address.replace(/\d/g, '') + '2').value
73
+ columns.push(cell.value + '>' + sub)
74
+ }
75
+ else{
76
+ columns.push(cell.value)
77
+ }
71
78
  })
72
79
 
73
80
  return {
@@ -87,8 +94,7 @@ const importRequest = async(req) => {
87
94
  throw new Error({name: ['Kolom ' + key.text + ' harus diisi']})
88
95
  })
89
96
 
90
- const rows = []
91
- const cols = {}
97
+ let rows = []
92
98
  const workbook = new Exceljs.Workbook();
93
99
  switch(xlsxFileType){
94
100
 
@@ -106,37 +112,35 @@ const importRequest = async(req) => {
106
112
  }
107
113
 
108
114
  const worksheet = workbook.worksheets[0]
109
- worksheet.eachRow((row, index) => {
110
- if(index === 1){
111
- row.eachCell((cell, index) => {
112
-
113
- let mapped = false
114
- keys.forEach((key) => {
115
- if(key.value === cell.value){
116
- cols[key.key] = index
117
- mapped = true
118
- }
119
- })
120
-
121
- if(!mapped){
122
- cols[cell.value] = index
123
- }
124
- })
115
+
116
+ let rowStart = 2
117
+ const header = worksheet.getRow(1)
118
+ const columnAddress = {}
119
+ header.eachCell((cell, index) => {
120
+ if(cell.isMerged){
121
+ const sub = worksheet.getCell(cell.address.replace(/\d/g, '') + '2').value
122
+ columnAddress[cell.value + '>' + sub] = index
123
+ rowStart = 3
125
124
  }
126
125
  else{
126
+ columnAddress[cell.value] = index
127
+ }
128
+ })
129
+
130
+ worksheet.eachRow((row, index) => {
131
+ if(index >= rowStart){
127
132
  const obj = {}
128
133
 
129
- for(let key in cols){
130
- const cell = row.getCell(cols[key])
131
- obj[key] = cell.formulaType === 1 ? cell.result : cell.value
134
+ for(let idx in keys){
135
+ const key = keys[idx]
136
+ const cell = row.getCell(columnAddress[key.value])
137
+ obj[key.key] = cell.formulaType === 1 ? cell.result : cell.value
132
138
  }
133
139
 
134
- rows.push(obj)
140
+ rows.push(unflatten(obj))
135
141
  }
136
142
  })
137
143
 
138
- //console.log(JSON.stringify(rows, null, 2))
139
-
140
144
  const images = glob.sync(process.env.ROOT_PATH + '/storage/files/temp/' + folderName +
141
145
  '/**/*(*.jpg|*.jpeg|*.png|*.webp)')
142
146