-
Notifications
You must be signed in to change notification settings - Fork 27
Edit task page rewritten to Vue #789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SimonAdamek
wants to merge
13
commits into
mrlvsb:master
Choose a base branch
from
SimonAdamek:edittask-vue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
401ad54
Change backend to use python urls.py instead of App.svelte
SimonAdamek fcdc3e4
Rewrite Editor and SyncLoader to Vue (old Editor.vue was not working …
SimonAdamek 3756de1
Rewrite Manager and Tests
SimonAdamek 322de48
Auto complete path + copy to clipboard
SimonAdamek 589c398
Edit task and Time range components
SimonAdamek aba48a1
Add new edit task template
SimonAdamek 0f3115d
Change pipeline docs url to new github pages
SimonAdamek 888b4bd
Fix broken reactivity between AutoCompleteTaskPath.vue and EditTask.vue
SimonAdamek 2d31852
Modify main teacher page to call new vue edit task url
SimonAdamek ba9d370
Fix github issues
SimonAdamek 3b3e319
Rewrite props to kelvin style
SimonAdamek b8292dc
Use a modern version of the component Editor.vue
SimonAdamek ebbfb56
Solve bugs, enable autocomplete for config.yml
SimonAdamek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,170 @@ | ||
| <script setup lang="ts"> | ||
| /** | ||
| * Component displays an input field that autocomplete path based on subject and username. | ||
| * It also allows user to copy entered path in SSH/RSYNC format to clipboard. | ||
| */ | ||
|
|
||
| import { user as userSvelte } from '../../global.js'; | ||
| import { clickOutside } from '../../utilities/clickOutside'; | ||
| import { User } from '../../utilities/SvelteStoreTypes'; | ||
| import { useReadableSvelteStore } from '../../utilities/useSvelteStoreInVue'; | ||
| import { defineModel, onMounted, computed, ref, watch, defineEmits } from 'vue'; | ||
| import CopyToClipboard from './CopyToClipboard.vue'; | ||
|
|
||
| /** | ||
| * @prop {string} subject - subject code used to get autocomplete hints | ||
| * @prop {(task_id: number) => void} onChange - function called once user select item from list | ||
| */ | ||
| let { subject, onChange } = defineProps<{ | ||
| subject: string; | ||
| onChange: (task_id: number) => void; | ||
| }>(); | ||
|
|
||
| const vClickOutside = clickOutside; | ||
|
|
||
| const clickEmit = defineEmits<{ | ||
| (e: 'click'): void; | ||
| }>(); | ||
|
|
||
| /** | ||
| * @model | ||
| * @type string | ||
| * Model is variable containing actual path | ||
| */ | ||
| const path = defineModel<string>(); | ||
|
|
||
| interface TaskList { | ||
| id: number; | ||
| title: string; | ||
| path: string; | ||
| subject: string; | ||
| date: Date; | ||
| link: string; | ||
| } | ||
|
|
||
| const user = useReadableSvelteStore<User>(userSvelte); | ||
|
|
||
| const items = ref<TaskList[]>([]); | ||
| const selectedId = ref<number | null>(null); | ||
| let focused = ref<boolean>(false); | ||
| const highlighted_row = ref<number>(-1); | ||
|
|
||
| const filtered = computed(() => | ||
| items.value.filter( | ||
| (i) => | ||
| i['path'].toLowerCase().includes(path.value.toLowerCase()) && | ||
| i['path'].toLowerCase() != path.value.toLowerCase() | ||
| ) | ||
| ); | ||
|
|
||
| onMounted(async () => { | ||
| // Load last 100 tasks of the given subject. | ||
| // Hopefully they will contain some useful paths to autocomplete :) | ||
| let res = await fetch(`/api/task-list/${subject}?sort=desc`); | ||
| res = await res.json(); | ||
| items.value = res['tasks']; | ||
| }); | ||
|
|
||
| // https://stackoverflow.com/a/6969486/1107768 | ||
| function escapeRegExp(string: string): string { | ||
| return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
| } | ||
|
|
||
| function keyup(e: KeyboardEvent) { | ||
| if (e.key == 'Enter' && highlighted_row.value >= 0) { | ||
| focused.value = false; | ||
| selectedId.value = filtered.value[highlighted_row.value].id; | ||
| path.value = filtered.value[highlighted_row.value].path; | ||
|
|
||
| let input: HTMLInputElement = e.target as HTMLInputElement; | ||
| input.blur(); | ||
| } else if (e.key == 'ArrowUp' && highlighted_row.value >= 0) { | ||
| highlighted_row.value = Math.max(0, highlighted_row.value - 1); | ||
| } else if (e.key == 'ArrowDown') { | ||
| highlighted_row.value = Math.min(filtered.value.length - 1, highlighted_row.value + 1); | ||
| } | ||
| } | ||
|
|
||
| watch(selectedId, () => { | ||
| if (selectedId.value) onChange(selectedId.value); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div v-click-outside="() => (focused = false)" class="form-control"> | ||
| <div class="input-group mb-1"> | ||
| <input | ||
| v-model="path" | ||
| class="form-control" | ||
| required | ||
| placeholder="Task directory" | ||
| @focus="focused = true" | ||
| @click="() => clickEmit('click')" | ||
| @keyup="keyup" | ||
| /> | ||
| <span class="btn btn-sm btn-outline-secondary"> | ||
| <CopyToClipboard | ||
| :content="`${user.username.toLowerCase()}@kelvin.cs.vsb.cz:/srv/kelvin/kelvin/tasks/${path}`" | ||
| title="Copy path for scp/rsync to the clipboard" | ||
| >path</CopyToClipboard | ||
| > | ||
| </span> | ||
| <span class="btn btn-sm btn-outline-secondary"> | ||
| <CopyToClipboard | ||
| :content="`ssh -t ${user.username.toLowerCase()}@kelvin.cs.vsb.cz 'cd /srv/kelvin/kelvin/tasks/${path} && exec bash'`" | ||
| title="Copy ssh command to the clipboard" | ||
| >ssh</CopyToClipboard | ||
| > | ||
| </span> | ||
| </div> | ||
|
|
||
| <ul v-if="filtered.length && focused"> | ||
| <li | ||
| v-for="(item, i) in filtered" | ||
| :key="i" | ||
| :class="{ highlight: highlighted_row == i }" | ||
| @click=" | ||
| () => { | ||
| path = item.path; | ||
| selectedId = item.id; | ||
| } | ||
| " | ||
| v-html=" | ||
| item.path.replace(new RegExp('(' + escapeRegExp(path) + ')', 'gi'), '<strong>$1</strong>') | ||
| " | ||
| ></li> | ||
| </ul> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .form-control { | ||
| padding-bottom: 0; | ||
| } | ||
|
|
||
| input { | ||
| width: 100%; | ||
| padding-bottom: 0; | ||
| padding-top: 0; | ||
| outline: 0; | ||
| border: 0; | ||
| } | ||
|
|
||
| ul { | ||
| background: white; | ||
| border: 1px solid rgb(206, 212, 218); | ||
| max-height: 200px; | ||
| overflow-y: auto; | ||
| list-style: none; | ||
| padding-left: 0; | ||
| position: absolute; | ||
| width: 100%; | ||
| z-index: 3; | ||
| } | ||
|
|
||
| li:hover, | ||
| li.highlight { | ||
| background: #5bc0de; | ||
| cursor: pointer; | ||
| } | ||
| </style> | ||
This file contains hidden or 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,82 @@ | ||
| <script setup lang="ts"> | ||
| /** | ||
| * Displays a button with given text and title; once clicked it copies content to clipboard | ||
| * and show a small animation informing user about the action | ||
| */ | ||
| import { ref } from 'vue'; | ||
|
|
||
| /** | ||
| * @prop {string} content - content to copy to clipboard | ||
| * @prop {string} title - appears when the user moves the mouse over the button | ||
| */ | ||
| let { content, title = 'Copy to clipboard' } = defineProps<{ | ||
| content?: string; | ||
| title: string; | ||
| }>(); | ||
|
|
||
| /** | ||
| * Pop up message coordinates | ||
| */ | ||
| interface PopUp { | ||
| left: number; | ||
| top: number; | ||
| } | ||
|
|
||
| const tooltip = ref<PopUp | null>(null); | ||
|
|
||
| function copy(e: MouseEvent): void { | ||
| navigator.clipboard.writeText(content); | ||
|
|
||
| let spanElement: HTMLElement = e.target as HTMLElement; | ||
| let container: HTMLElement = spanElement.closest('.tooltip-container') as HTMLElement; | ||
| tooltip.value = { | ||
| left: container.offsetLeft + container.offsetWidth, | ||
| top: container.offsetTop - 5 | ||
| }; | ||
|
|
||
| setTimeout(() => (tooltip.value = null), 1500); | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <span style="position: relative"> | ||
| <span class="tooltip-container" :title="title" @click="copy"> | ||
| <slot></slot> | ||
| </span> | ||
| <Transition name="fade"> | ||
| <div | ||
| v-if="tooltip" | ||
| class="tooltip bs-tooltip-right show d-flex align-items-center" | ||
| role="tooltip" | ||
| :style="{ left: tooltip.left + 'px', top: tooltip.top + 'px' }" | ||
| > | ||
| <div class="popover-arrow"></div> | ||
| <div class="tooltip-inner">Copied!</div> | ||
| </div> | ||
| </Transition> | ||
| </span> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| span { | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .fade-enter-active { | ||
| transition: opacity 2s ease; | ||
| } | ||
|
|
||
| .fade-leave-active { | ||
| transition: opacity 0.1s ease; | ||
| } | ||
|
|
||
| .fade-enter-from, | ||
| .fade-leave-to { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| .fade-enter-to, | ||
| .fade-leave-from { | ||
| opacity: 1; | ||
| } | ||
| </style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not ok, because the index
iwill be reused for different items oncefilteredchanges. Let's remove the key altogether, since there is no inner state of the rendered component.