-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#193): support edit and create rooms
- Loading branch information
1 parent
2e2a812
commit 1ff9420
Showing
8 changed files
with
235 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { ErrorList } from '../shared/errorlist.js' | ||
import { RoomList } from './roomlist.js' | ||
import { RoomCreateForm } from './roomcreate.js' | ||
import { RoomForm } from './roomform.js' | ||
|
||
const { useI18n } = VueI18n | ||
const { ref } = Vue | ||
|
||
export const App = { | ||
setup() { | ||
const { t } = useI18n() | ||
const roomId = ref('') | ||
const updateCount = ref(0) | ||
|
||
const setRoomId = (id) => { | ||
console.log('received '+id) | ||
roomId.value = id | ||
} | ||
const reloadRooms = () => { | ||
console.log('reload rooms') | ||
roomId.value = '' | ||
updateCount.value++ | ||
} | ||
|
||
return { | ||
t | ||
roomId, | ||
updateCount, | ||
setRoomId, | ||
reloadRooms, | ||
} | ||
}, | ||
components: { | ||
ErrorList, | ||
RoomForm, | ||
RoomList, | ||
RoomCreateForm, | ||
}, | ||
template: ` | ||
<ErrorList /> | ||
<div class="headline"><br/>{{ t('rooms.list.title') }}</div> | ||
<hr class="contentbox"/> | ||
<RoomList /> | ||
<div class="headline"><br/>{{ t('rooms.create.title') }}</div> | ||
<hr class="contentbox"/> | ||
<RoomCreateForm /> | ||
<RoomForm :id="roomId" @rooms-possibly-updated="reloadRooms"/> | ||
<RoomList :reload="updateCount" @room-clicked="(id) => setRoomId(id)"/> | ||
` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { CreateRoom, UpdateRoom, GetRoomByID } from '../apis/roomsrv.js' | ||
import { StoredErrorList } from '../stores/errorlist.js' | ||
|
||
const { ref, computed, watch } = Vue | ||
const { useI18n } = VueI18n | ||
|
||
export const RoomForm = { | ||
props: ['id'], | ||
emits: ['rooms-possibly-updated'], | ||
setup(props, { emit }) { | ||
const { t } = useI18n() | ||
|
||
const id = ref(props.id) | ||
const name = ref('') | ||
const roomsize = ref('2') | ||
const comments = ref('') | ||
|
||
const isNew = computed(() => { | ||
return id.value.length === 0 | ||
}) | ||
const isNameError = computed(() => { | ||
return name.value.length === 0 | ||
}) | ||
const isSizeError = computed(() => { | ||
return !roomsize.value.match(/^[1-9][0-9]*$/) | ||
}) | ||
|
||
const errorList = StoredErrorList // get a local reference to the store ref | ||
const resetHandler = () => { | ||
// even a reset will at least de-select the currently edited room | ||
emit('rooms-possibly-updated') | ||
errorList.resetErrors() | ||
id.value = '' | ||
name.value = '' | ||
roomsize.value = '2' | ||
comments.value = '' | ||
} | ||
const submitHandler = () => { | ||
errorList.resetErrors() | ||
if (id.value.length === 0) { | ||
CreateRoom({ | ||
name: name.value, | ||
flags: [], | ||
size: Number(roomsize.value), | ||
comments: comments.value, | ||
}, (room) => { | ||
resetHandler() | ||
},(status, apiError) => { | ||
errorList.addError(apiError) | ||
}) | ||
} else { | ||
UpdateRoom({ | ||
id: id.value, | ||
name: name.value, | ||
flags: [], // TODO | ||
size: Number(roomsize.value), | ||
comments: comments.value, | ||
}, (room) => { | ||
resetHandler() | ||
}, (status, apiError) => { | ||
errorList.addError(apiError) | ||
}) | ||
} | ||
} | ||
|
||
watch(() => props.id, (newIdValue, oldIdValue) => { | ||
console.log('RoomForm received props.id change: ' + oldIdValue + ' -> ' + newIdValue) | ||
id.value = newIdValue | ||
}) | ||
|
||
watch(id, (newIdValue, oldIdValue) => { | ||
if (newIdValue !== oldIdValue) { | ||
if (newIdValue.length === 0) { | ||
resetHandler() | ||
} else { | ||
GetRoomByID(newIdValue, (room) => { | ||
id.value = newIdValue | ||
name.value = room.name | ||
roomsize.value = '' + room.size | ||
comments.value = room.comments ?? "" | ||
}, (status, apiError) => { | ||
errorList.addError(apiError) | ||
}) | ||
} | ||
} | ||
}, { immediate: true }) | ||
|
||
return { | ||
t, | ||
name, | ||
roomsize, | ||
comments, | ||
isNew, | ||
isNameError, | ||
isSizeError, | ||
submitHandler, | ||
resetHandler, | ||
errorList, | ||
} | ||
}, | ||
template: ` | ||
<div class="headline"><br/>{{ isNew ? t('rooms.create.title') : t('rooms.edit.title') }}</div> | ||
<hr class="contentbox"/> | ||
<table width="100%" cellpadding="0" cellspacing="4" border="0"> | ||
<tr> | ||
<td class="label" ALIGN="right" VALIGN="middle" width="20%">{{ isNew ? t('rooms.create.name') : t('rooms.edit.name') }}</TD> | ||
<td class="input" ALIGN="left" VALIGN="middle" width="80%"><input type="text" size="40" maxlength="80" v-model.trim="name" :class="{ error: isNameError }" :placeholder="isNew ? t('rooms.create.namehint') : t('rooms.edit.namehint')"/></td> | ||
</tr> | ||
<tr> | ||
<td class="label" ALIGN="right" VALIGN="middle" width="20%">{{ isNew ? t('rooms.create.size') : t('rooms.edit.size') }}</TD> | ||
<td class="input" ALIGN="left" VALIGN="middle" width="80%"><input type="text" size="5" maxlength="5" v-model.trim="roomsize" :class="{ error: isSizeError }"/></td> | ||
</tr> | ||
<tr> | ||
<td class="label" ALIGN="right" VALIGN="middle" width="20%">{{ isNew ? t('rooms.create.comments') : t('rooms.edit.comments') }}</TD> | ||
<td class="input" ALIGN="left" VALIGN="middle" width="80%"><input type="text" size="40" maxlength="80" v-model.trim="comments"/></td> | ||
</tr> | ||
<tr> | ||
<td class="label" ALIGN="right" VALIGN="middle" width="20%"> </TD> | ||
<td class="input" ALIGN="left" VALIGN="middle" width="80%"><button :disabled="isNameError || isSizeError" @click="submitHandler">{{ isNew ? t('rooms.create.save') : t('rooms.edit.save') }}</button> <button @click="resetHandler">{{ isNew ? t('rooms.create.cancel') : t('rooms.edit.cancel') }}</button></td> | ||
</tr> | ||
</table> | ||
` | ||
} |
Oops, something went wrong.