Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions frontend/src/directives/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { App, Directive } from 'vue';
import integerInput from './modules/integer';

const directivesList: { [key: string]: Directive } = {
'integer-input': integerInput,
};

const directives = {
install: function (app: App<Element>) {
Object.keys(directivesList).forEach((key) => {
app.directive(key, directivesList[key]);
});
},
};

export default directives;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find any major syntax errors in your provided code. However, there might be an issue with importing modules directly using $import which is outdated and may cause issues depending on how Vue.js was configured or updated since 2017.

Here's a minor improvement suggestion:

// Importing components instead of full module imports

const directives = {
    install: (app) => {
        const directivesListModules = ['integerInput'];
        
        // Register each component separately
        directivesListModules.forEach(moduleName => {
            app.component(moduleName, require(`./components/${moduleName}`));
        });

        Object.keys(directivesList).forEach((key) => {
            app.directive(key, directivesList[key]());
        });
    }
};

23 changes: 23 additions & 0 deletions frontend/src/directives/modules/integer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Directive, DirectiveBinding } from 'vue';

const integerInput: Directive = {
mounted(el: HTMLElement, binding: DirectiveBinding) {
const { value } = binding;
el.addEventListener('input', (event: Event) => {
const inputElement = event.target as HTMLInputElement;
let inputValue = inputElement.value;
inputValue = inputValue.replace(/\..*/, '');
if (value?.min !== undefined && Number(inputValue) < value.min) {
inputValue = value.min.toString();
}
if (value?.max !== undefined && Number(inputValue) > value.max) {
inputValue = value.max.toString();
}
inputElement.value = inputValue;
const inputEvent = new Event('input', { bubbles: true });
inputElement.dispatchEvent(inputEvent);
});
},
};

export default integerInput;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no known irregularities or potential issues with the code provided. As of August 2022, there have been updates to CSS properties introduced in future versions of WebKit-based browsers (CSS3 and above). If you're using such features and need to update this directive class, please reference these changes.

However, since the code is simple and does not introduce new syntaxes for specific frameworks like Vue, it should work effectively without requiring explicit JavaScript modifications beyond what's already stated. So far, there don't appear to be any issues other than the ones mentioned due to its simplicity.

If there were bugs affecting modern browsers where innerText can get confused when trying to replace certain characters, then some kind of escaping might be required on that property.

I would suggest keeping this updated only as needed based on new browser compatibility needs.
It could also lead to cleaner logic if considering further enhancement.

4 changes: 4 additions & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import hljsVuePlugin from '@highlightjs/vue-plugin';
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
import VirtualScroller from 'vue-virtual-scroller';

import directives from '@/directives/index';

const app = createApp(App);
app.use(hljsVuePlugin);
app.component('SvgIcon', SvgIcon);
Expand All @@ -43,4 +45,6 @@ app.use(router);
app.use(i18n);
app.use(pinia);
app.use(Components);
app.use(directives);

app.mount('#app');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None found

2 changes: 1 addition & 1 deletion frontend/src/views/host/file-management/process/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<div class="w-full">
<el-progress
v-if="value.total === 0"
v-if="value.total === 0 && value.percent != 100"
:percentage="100"
:indeterminate="true"
:duration="1"
Expand Down
Loading