Olobase Admin input components allow editing of specific properties of the current API resource object. Mainly for creating and editing views It is used in form. It can also be used as a filter entry for VaList. For resource support, it must be used within the VaForm component, which handles adding elements and providing the model with error messages.
Va entries support both source and model sup
port. The source is the original feature object from which the value will be fetched and the model will be the final feature name with the new value to be sent to your data provider.
Olobase Admin inputs accept dot notation for source support. Very useful for nested object:
<template>
<va-text-input source="address.street"></va-text-input>
<va-text-input source="address.postcode"></va-text-input>
<va-text-input source="address.city"></va-text-input>
</template>
As seen in the example above, the value of the street property of the address object is directly taken. The final form model data to be sent to your data provider also complies with this nested structure.
In this section, Olobase Admin input components in the packages/admin/src/components/ui/inputs folder will be discussed.
Edits text for text value type via basic text input. Supports textarea mode for long texts via multi-line support. Can be used for any date, datetime or time arrangement; Use date, datetime-local, or time-based type. Processing will depend on browser support.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot representation for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
type | string |
Text input type. All HTML types are allowed. |
multiline | boolean |
Convert text input to textarea. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-text-input :label="$t('demo.text')" source="founder"></va-text-input>
</v-col>
<v-col lg="3" md="4" sm="6">
<va-text-input :label="$t('demo.text')" source="headquarter"></va-text-input>
</v-col>
</v-row>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-text-input :label="$t('demo.text')" source="description" multiline></va-text-input>
</v-col>
</v-row>
</template>
Şifre alanları için kullanılır. Geçerli giriş için gösterme/gizleme davranışı vardır.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-password-input label="Password" source="password"></va-password-input>
</v-col>
</v-row>
</template>
Optimized for number editing. Supports min, max and step features.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
v-model | string |
Text to be edited. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
step | number |
Interval step. |
min | number |
Minimum accepted value. |
max | number |
Maximum accepted value. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-number-input source="level" label="Level" :step="1" :min="0" :max="99"></va-number-input>
</v-col>
</v-row>
</template>
It is used to edit the date type value. Vuetify consists of a read-only text field associated with the date picker. It does not support time value, in this case use classic VaTextInput.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
header | string |
Allows you to write text in the section shown under the title. The default value is empty. |
format | string |
The date format to use. For example: (dd-mm-YYYY). |
allowedDates | function , array |
Restricts which dates can be selected. |
color | string |
Applies the specified color to the component - supports auxiliary colors (e.g. success or purple) or css color (e.g. success or purple) or css color (like #033 or rgba(255, 0, 0, 0.5)). Default value: primary. |
elevation | string , number |
Specifies a height applied to the component, from 0 to 24. More information can be found on elevation. |
hideHeader | boolean |
Completely hides the header section of the component. (Default: false). |
height | string , number |
Sets the height of the component. |
width | string , number |
Sets the width of the component. |
max | string , number , date |
Maximum date/month allowed. (ISO 8601 format). |
maxHeight | string , number |
Sets the maximum height of the component. |
maxWidth | string , number |
Sets the maximum width of the component. |
min | string , number , date |
Minimum date/month allowed (ISO 8601 format). |
minHeight | string , number |
Sets the minimum height of the component. |
minWidth | string , number |
Sets the minimum width of the component. |
multiple | boolean |
Allow multiple date selections. |
position | boolean |
Sets the position of the component (static, relative, fixed, absolute, sticky). |
rounded | string , number , boolean |
Specifies the edge radius applied to the component. |
showAdjacentMonths | boolean |
Toggles the visibility of previous and next months' days. |
showWeek | boolean |
Toggles the visibility of week numbers in the body of the calendar. |
hideActions | boolean |
Hides select actions. |
hideWeekdays | boolean |
Hides weekdays. |
inputPlaceholder | string |
Sets the placeholder value for the entry. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
viewMode | string |
Switches between month or year view (month, year). |
disabled | boolean |
Removes the ability to click on the component. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-date-input source="publishDate" label="Publish Date" format="shortFormat"></va-date-input>
</v-col>
</v-row>
</template>
When a value is sent to a boolean input type as boolean or 0/1, the input is displayed as a toggle button.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-boolean-input source="active" label="Active"></va-boolean-input>
</v-col>
</v-row>
</template>
Edit the number value as rating stars. If half increments are enabled, the value must be a valid integer or decimal number. Icons can be edited via $ratingFull, $ratingEmpty and $ratingHalf in Vuetify settings.
Mixins
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
active-color | string |
Color applied to the component while it is active. |
clearable | boolean |
Allows the component to be cleared by clicking on the current value. |
color | string |
Applies the specified color to the control. |
density | string |
Sets the vertical height used by the component. (default, comfortable, compact). |
disabled | boolean |
Removes the ability to click on the component. |
empty-icon | string , array , function |
Icon displayed when empty. |
full-icon | string , array , function |
Icon displayed when full. |
half-increments | boolean |
Allows selection of half increments. |
hover | boolean |
Provides visual feedback when hovering over icons. |
item-aria-label | string |
Settings for item tags. |
item-label-position | string |
Position of element labels accepts 'top' and 'bottom'. |
item-labels | array |
Array of labels to display next to each item. |
length | string , number |
Amount of items to display. |
model-value | string , number |
The v-model value of the component. If the component supports multitasking, this defaults to an empty array. |
name | string |
Sets the name property of the component. |
readonly | boolean |
Removes all hover effects and pointer events. |
size | string , number |
Sets the height and width of the component. The default unit is pixels. (x-small, small, default, large, x-large). |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-rating-input source="rating" length="10" half-increments></va-rating-input>
</v-col>
</v-row>
</template>
Creates a WYSIWYG HTML editor using the Tiptap.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-rich-text-editor
:label="$t('demo.richtext')"
source="richtext"
v-model="model.richText"
:active-buttons="[
'bold',
'italic',
'strike',
'underline',
'code',
'h1',
'h2',
'h3',
'bulletList',
'orderedList',
'blockquote',
'codeBlock',
'horizontalRule',
'undo',
'redo',
]"
>
</va-rich-text-editor>
</v-col>
</v-row>
</template>
Creates a WYSIWYG HTML editor using the Tiny MCE GPL license.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-tiny-mce-editor
:options="{ min_height: 250 }"
v-model="model.richText"
>
</va-tiny-mce-editor>
</v-col>
</v-row>
</template>
Lets you select a value or values from a selection list. Supports multiple selections and references. If no options are available, by default it can retrieve localized lists containing resources from src/I18n/locales/en.json.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
reference | string |
Name of the resource to search for. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
multiple | boolean |
Activates multiple selection. |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-select-input
label="Select"
clearable
multiple
reference="employeegrades"
v-model="model.grades"
>
</va-select-input>
</v-col>
</v-row>
</template>
You can centralize all reuse options directly in your locale as described here. If no options are set, VaSelectInput will search for the following valid translated key format: resources.{resource}.enums.{source}.{value}
If you want to select from the current source reference, use the reference option as follows:
<template>
<va-select-input
source="companyId"
model="companyId"
reference="companies"
:filter="{ active: true }"
></va-select-input>
</template>
The example above will fetch all companies from the api service and list them as options. For filtering, use the filter option. In case the schema name on the backend side is different from the source, you can use the model option. Otherwise, you do not need to use this option.
If you want to change another selection field interactively after selecting a selection field, take a look at the code in the example below.
<va-select-input
source="companyId"
v-model="model.companyId"
reference="departments"
variant="outlined"
></va-select-input>
<va-select-input
source="departmentId"
:key="model.companyId"
:filter="{ companyId: model.companyId }"
v-model="model.departmentId"
reference="departments"
variant="outlined"
></va-select-input>
Lets you select values from a selection list. Supports references. If no options are available, by default it can retrieve localized lists containing resources from src/I18n/locales/en.json.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
reference | string |
Name of the resource to search for. |
inline | boolean |
Shows options horizontally. (Default: false). |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-radio-group-input
clearable
label="Currencies"
v-model="model.radios"
reference="currencies"
>
</va-radio-group-input>
</v-col>
<v-col lg="3" md="4" sm="6">
<va-radio-group-input
clearable
inline
label="Currencies"
v-model="model.radios"
reference="currencies"
>
</va-radio-group-input>
</v-col>
</v-row>
</template>
References
The same reference description for VaSelectInput as above applies, multi-selection is not supported.
Allows selection of value or values from searchable options. Supports multiple selections and references. Allows searching for linked resources from your API service.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
reference | string |
Name of the resource to search for. |
minChars | number |
Minimum characters that must be tapped before the search query is initiated. |
searchQuery | string |
The name of the request query to search your API service. (Default: "q"). |
taggable | boolean |
Enable taggable mode. Convert autocomplete to combo box. |
Slots
Ad | Description |
---|---|
selection | Define a custom selection view. |
item | Define a custom item view |
Example
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<template>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-auto-complete-input
density="compact"
source="userId"
resource="employees"
reference="employees"
variant="outlined"
multiple
>
<template v-slot:chip="{ props, item }">
<v-chip v-if="item.raw.name"
class="cursor-pointer"
v-bind="props"
:text="item.raw.name"
>
{{ item.raw.name }}
</v-chip>
</template>
</va-auto-complete-input>
</v-col>
</v-row>
</template>
</v-col>
</v-row>
</template>
searchQuery and minChars:
Use minChars and searchQuery to configure the minimum characters required before searching and the query search parameter key, which defaults to q. This element will reuse the GetList data provider method with a custom search filter.
For better performance, use the fields option to reduce API query overload.
taggable
Autocomplete will be converted to a combo box component as soon as you enable taggable support. It allows you to create new tags instantly.
Allows single line file uploads. One or both installations are supported simultaneously. Use VaFileField or VaImageField with this element to show a preview of uploaded files.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
itemValue | string |
Specifies where to retrieve the ID value to identify files to delete (Default: "id"). |
accept | string |
Adds HTML5 `accept` feature for simple client-side validation. |
base64 | boolean |
Enables uploading with base64 encoding. |
tableName | string |
Name of the table in the database where global installation files are kept. |
download | boolean |
Activates the click and download file option. |
Example
<template>
<v-row no-gutters>
<v-col sm="3" class="mr-3">
<va-file-field
source="files"
:item="model"
action-type="download"
table-name="employeeFiles"
></va-file-field>
</v-col>
</v-row>
<v-row>
<v-col lg="3" md="4" sm="6">
<va-file-input
source="files"
table-name="employeeFiles"
></va-file-input>
</v-col>
</v-row>
</template>
It allows multiple data entries as arrays in tabular format. Supports adding new data, deleting and updating data.
Mixins
Properties
Property | Type | Description |
---|---|---|
class | String |
The array table assigns a value to the html class attribute of the div element surrounding it. |
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
title | string |
Sets the header of the array table. |
headers | array |
Determines the column headers of the array table. |
fields | array |
Places the va-entries to use from the array table. |
primaryKey | string |
Sets the key field name for the Array. This name is required for backend side validation and database registration. |
errorMessages | array |
Allows display of assigned form validation errors. |
Slots
Ad | Description |
---|---|
top | Edits the section of the series title when needed. |
bottom | Arranges the bottom section of the array table. |
headers | Customizes the columns of the array table. |
item.actions | Customizes the operations section of the array table. |
Events
After the form saving stage of the Array Table events, it receives the responses returned from the server and organizes the actions accordingly.
Event Name | Description |
---|---|
save | It allows you to access the object of the saved data after the form row is saved. |
delete | It allows you to access the object of the deleted data after the form row is deleted. |
edit | It allows you to store the object belonging to the data edited while the form row is open. |
Example
<template>
<v-row no-gutters>
<v-col lg="8" md="12" sm="12">
<va-array-table-input
source="employeeChildren"
:title="$t('resources.employees.fields.employeeChildren')"
primary-key="childId"
:headers="headers"
:fields="fields"
:generate-uid="true"
>
<template v-slot:[`input.childName`]="{ field }">
<va-text-input
:key="field.source"
v-model="employeeChildrenForm.childName"
variant="outlined"
:error-messages="childNameErrors"
clearable
>
</va-text-input>
</template>
<template v-slot:[`input.childBirthdate`]="{ field }">
<va-date-input
:key="field.source"
v-model="employeeChildrenForm.childBirthdate"
variant="outlined"
:error-messages="childBirthdateErrors"
>
</va-date-input>
</template>
</va-array-table-input>
</v-col>
</v-row>
</template>
<script>
import { useVuelidate } from "@vuelidate/core";
import { required, maxLength, numeric } from "@vuelidate/validators";
import Utils from "vuetify-admin/src/mixins/utils";
import Resource from "vuetify-admin/src/mixins/resource";
import { provide } from 'vue'
export default {
props: ["id", "item"],
mixins: [Utils, Resource],
setup() {
let vuelidate = useVuelidate();
provide('v$', vuelidate)
return { v$: vuelidate }
},
data() {
return {
model: {
id: null,
employeeChildren: null,
},
employeeChildrenHeaders: [
{ key: "childName", width: "40%" },
{ key: "childBirthdate", width: "40%" },
{ key: "actions" },
],
employeeChildrenFields: [
{
source: "childName",
type: "text",
},
{
source: "childBirthdate",
type: "date",
},
]
};
},
validations() {
return {
// model: {},
employeeChildrenForm: {
childName: {
required,
},
childBirthdate: {
required,
}
}
}
},
created() {
this.model.id = this.generateId(this);
},
computed: {
employeeChildrenForm: {
get() {
return this.$store.getters[`${this.resource}/getRow`];
},
set(val) {
this.$store.commit(`${this.resource}/setRow`, val);
}
},
childNameErrors() {
const errors = [];
const field = "childName";
if (!this.v$["employeeChildrenForm"][field].$dirty) return errors;
this.v$["employeeChildrenForm"][field].required.$invalid &&
errors.push(this.$t("v.text.required"));
return errors;
},
childBirthdateErrors() {
const errors = [];
const field = "childBirthdate";
if (!this.v$["employeeChildrenForm"][field].$dirty) return errors;
this.v$["employeeChildrenForm"][field].required.$invalid &&
errors.push(this.$t("v.text.required"));
return errors;
},
},
}
</script>
It facilitates the creation of a user's profile picture with cutting and shrinking options.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
backgroundColor | string |
Sets the background color. The default value is #ededed. |
defaultSrc | string |
Determines the image shown by default. The default value is /src/assets/avatar_2x.png. |
setLabel | string |
Determines the label of the button for adding an avatar. |
delLabel | string |
Avatar determines the label of the button for deletion. |
Example
<template>
<v-row no-gutters>
<v-col sm="3" class="mr-3">
<va-avatar-input
source="avatarImage"
:set-label="$t('resources.account.fields.avatar.set')"
:del-label="$t('resources.account.fields.avatar.delete')"
>
</va-avatar-input>
</v-col>
</v-row>
</template>
It enables the creation together of checkbox input components grouped under each other at the first level. Features such as the toggle feature, the ability to select all entries with a higher checkbox, and searching within the list are supported by default.
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
disableSearch | boolean |
Hide/show the search feature at the top. (Default: false). |
disableFooter | boolean |
Hide/show the pagination feature that appears at the bottom (Default: false). |
primaryKey | string |
Sets the primary key name for grouping operations. |
itemsPerPage | string |
Determines the number of data to display per page. |
headers | array |
Determines column headers. |
fields | string |
Determines column fields. |
initUrl | string |
Sets the backend url address that fetches the entire list. |
groupBy | string |
Determines which column will be grouped based on the entered value. |
Example
<template>
<h2 class="h2 mb-4">
{{ $t("menu.permissions") }}
</h2>
<v-row no-gutters>
<v-col cols="6">
<va-check-list-input
source="rolePermissions"
:headers="headers"
:fields="fields"
primary-key="permId"
items-per-page="25"
:group-header="$t('resources.roles.fields.moduleName')"
group-by="moduleName"
init-url="/permissions/findAll"
>
</va-check-list-input>
</v-col>
</v-row>
</template>
<script>
import utils from "vuetify-admin/src/mixins/utils";
import { provide } from 'vue'
export default {
props: ["id", "item"],
mixins: [utils],
setup() {
let vuelidate = useVuelidate();
provide('v$', vuelidate)
return { v$: vuelidate }
},
data() {
return {
rolePermissions: [],
model: {
rolePermissions: null,
},
fields: [
{ source: "moduleName" },
{ source: "action" },
{ source: "route" },
{ source: "method"},
],
};
},
computed: {
headers() {
return [
{
key: "moduleName",
sortable: false,
},
{
key: "action",
sortable: false,
},
{
key: "route",
sortable: false,
},
{
key: "method",
sortable: false,
},
];
}
}
}
</script>
It creates the component that makes it easy to select HEX color codes.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
color | string |
Determines the overall color of the component. |
border | string |
Applies border styles to the component. |
rounded | boolean , string , number |
Specifies the edge radius applied to the component. |
dotSize | string |
Changes the size of the selection point on the canvas. |
hideCanvas | boolean |
Hides the canvas. |
canvasHeight | string , Number |
Determines the height of the canvas. |
mode | string |
The currently selected entry type. Input can be synchronized with v-model:mode. Possible Values: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hex' | 'hexa'. |
modes | Array |
Sets the available input types. Values that can be given: ['rgb', 'rgba', 'hsl', 'hsla', 'hex', 'hexa']. |
hideInputs | boolean |
Hides input fields. (Default: false). |
hideSliders | boolean |
Hides input fields. (Default: false). |
showSwatches | boolean |
Displays swatches on canvas. (Default: false). |
swatchesMaxHeight | string , Number |
Sets the maximum height of the swatches section. |
position | string |
Sets the location of the component (Default: undefined). Possible Values: 'static' | 'relative' | 'fixed' | 'absolute' | 'sticky'. |
width | string |
Sets the width of the color picker. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
Example
<template>
<v-row no-gutters>
<v-col sm="3" class="mr-3">
<va-color-picker-input
source="themeColor"
resource="account"
dot-size="25"
mode="hexa"
show-swatches
swatches-max-height="150"
v-model="themeColor"
:error-messages="themeColorErrors"
></va-color-picker-input>
</v-col>
</v-row>
</template>
For currency representation, use the vue-currency-input component to display the current value relative to the existing currency. formats.
Mixins
Properties
Property | Type | Description |
---|---|---|
source | string |
The property of the resource to fetch the value to display. Supports dot display for slot used object. |
model | string |
By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior. |
variant | string |
Applies different styles to the component. (outlined, plain, underlined, solo, filled, solo-filled, solo-inverted). |
options | object |
Allows you to enter vue-currency-input options. Example: options="{ currency: "USD", precision: 2 } |
Example
<template>
<v-row no-gutters>
<v-col lg="3" md="4" sm="6">
<va-select-input
:label="$t('demo.currencyId')"
reference="currencies"
v-model="model.currencyId"
>
</va-select-input>
<va-currency-input
clearable
:label="$t('demo.amount')"
v-model="model.amount"
:key="'amount_' + getCurrencyId"
:options="{ currency: getCurrencyId, precision: 2 }"
></va-currency-input>
</v-col>
</v-row>
</template>
<script>
export default {
data() {
return {
model: {
amount: 0,
currencyId: { id: "USD", name: "Usd" },
},
};
},
computed: {
getCurrencyId() {
if (this.model && this.model.currencyId && this.model.currencyId.id) {
return this.model.currencyId.id;
}
return "TRY";
},
}
};
</script>
It is the input component that allows you to read large amounts of Excel data and add it to the database in cli mode. To save the imported data, it should be used with a sheet saving template that you have created yourself.
Example
<template>
<va-list
disable-create
:filters="filters"
:fields="fields"
:items-per-page="50"
>
<va-data-table-server
row-edit
row-create
disable-edit
disable-create
disable-clone
disable-show
:disable-empty-data-row-create="true"
>
<template v-slot:row.actions="{ item }">
<v-btn
:item="item"
:label="$t('va.actions.show')"
:color="'blue'"
variant="text"
exact
@click.stop="getRoute(item)"
>
<v-icon size="small">mdi-eye</v-icon>
</v-btn>
</template>
</va-data-table-server>
</va-list>
<v-card
class="mx-auto mt-2"
variant="flat"
>
<template v-slot:title>
{{ $t("resources.jobtitles.createNewList") }}
</template>
<v-card-text>
<div>
{{ $t("resources.jobtitles.importDescription") }}
</div>
</v-card-text>
<v-card-actions>
<v-btn
color="primary"
@click="downloadEmptyXls()">
{{ $t("resources.jobtitles.downloadXls") }}
</v-btn>
</v-card-actions>
</v-card>
<v-card
variant="flat"
class="mt-2"
>
<v-card-text>
<v-row class="mt-2">
<v-col sm="2">
<va-select-input
v-model="yearId"
reference="years"
variant="outlined"
clearable
:disabled="loadingStatus"
:error-messages="yearIdErrors"
></va-select-input>
</v-col>
<v-col sm="2">
<va-text-input
v-model="listName"
variant="outlined"
clearable
:disabled="loadingStatus"
:error-messages="listNameErrors"
></va-text-input>
</v-col>
<v-col sm="8">
<v-btn
v-if="loadingStatus"
color="primary"
class="mr-2"
@click="cancelSaveList()"
variant="outlined"
>
{{ $t("va.actions.cancel") }}
</v-btn>
<v-btn
:loading="loadingStatus"
color="primary"
variant="outlined"
@click="saveList()">
{{ $t("resources.jobtitles.saveList") }}
</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>
<v-card
variant="flat"
class="mt-2"
v-if="!loadingStatus"
>
<v-card-text>
<h5 class="h4 mb-3">Sheet Input Component</h5>
<va-sheet-input
icon="mdi-file-excel"
items-per-page="100"
upload-url="/jobtitlelists/upload"
preview-url="/jobtitlelists/preview"
remove-url="/jobtitlelists/remove"
@importedItems="onItems"
>
</va-sheet-input>
</v-card-text>
</v-card>
</template>
<script>
import { useVuelidate } from "@vuelidate/core";
import { required } from "@vuelidate/validators";
import { provide } from 'vue';
import { mapActions } from "vuex"
export default {
props: [],
inject: ['admin'],
setup() {
provide('v$', useVuelidate() )
return { v$: useVuelidate() }
},
provide() {
return {
validations: {
form: {
listName: {
required
},
}
},
errors: {
listNameErrors: (v$) => {
const errors = [];
if (!v$['form'].listName.$dirty) return errors;
v$['form'].listName.required.$invalid &&
errors.push(this.$t("v.text.required"));
return errors;
},
}
};
},
validations() {
return {
yearId: {
required
},
listName: {
required
}
}
},
data() {
return {
cancel: false,
status: false,
loadingStatus: false,
listId: null,
listName: null,
companyId: null,
yearId: new Date().getFullYear(),
loading: false,
loadingList: false,
importData: [],
validationError: null,
filters: [
{
source: "yearId",
type: "selectfilter",
attributes: {
optionText: "name",
multiple: true,
reference: "years",
}
},
],
fields: [
{
source: "yearId",
type: "select",
attributes: {
reference: "years",
},
sortable: true,
},
{
source: "listName",
sortable: true,
},
],
}
},
computed: {
yearIdErrors() {
const errors = [];
if (!this.v$.yearId.$dirty) return errors;
this.v$.yearId.required.$invalid &&
errors.push(this.$t("v.text.required"));
return errors;
},
listNameErrors() {
const errors = [];
if (!this.v$.listName.$dirty) return errors;
this.v$.listName.required.$invalid &&
errors.push(this.$t("v.text.required"));
return errors;
}
},
methods: {
...mapActions({
checkAuth: "auth/checkAuth",
}),
onItems(items, vError) {
this.importData = items;
if (items.length == 0) {
this.validationError = null
} else {
this.validationError = vError
}
},
getRoute(item) {
let filter = null
if (item.listId) {
filter = '{ "yearId" : ["'+ item.yearId.id + '"] , "listId" : ["' + item.listId + '"] }';
}
this.$router.push({ name: "jobtitles_list", query: { filter: filter } });
},
async importStatus() {
let Self = this;
this.loadingStatus = true;
try {
//
// get status with EventSource
//
let user = await this.checkAuth();
if (user) {
const apiUrl = import.meta.env.VITE_API_URL;
this.source = new EventSource(apiUrl + '/stream/events?userId=' + user.id + '&route=list');
this.source.onmessage = function(e) {
if (e.data) {
let data = JSON.parse(e.data);
if (data.status == 1 || data.status == true) {
Self.source.close(); // lets close it when the process is done !
Self.status = false;
Self.loadingStatus = false
Self.importData = []; // reset import data
Self.admin.http({ method: "DELETE", url: "/jobtitlelists/reset" }); // reset all status
Self.$store.dispatch("api/refresh", 'jobtitlelists');
}
}
};
}
} catch (e) {
if (e["response"]
&& e["response"]["status"]
&& e.response.status === 400) {
this.admin.message("error", e.response.data.data.error);
}
}
},
saveList() {
this.cancel = false;
this.v$.yearId.$touch();
this.v$.listName.$touch();
if (this.v$.listName.$invalid || this.v$.yearId.$invalid) {
return false;
}
if (this.validationError) {
this.$store.commit("messages/show", { type: 'error', message: this.$t("employees.fixErrorsMessage") });
} else {
if (this.importData.length == 0) {
this.$store.commit("messages/show", { type: 'error', message: this.$t("employees.importDataMessage") });
} else {
// save imported data
//
this.admin.http({ method: "POST", url: "/jobtitlelists/import", data: { yearId: this.yearId, listName: this.listName } });
// check status every 1 seconds
//
this.importStatus();
}
}
},
cancelSaveList() {
this.cancel = true;
this.loadingStatus = false;
this.importData = []; // reset import data
this.admin.http({ method: "DELETE", url: "/jobtitlelists/reset" }); // reset all status
this.$store.dispatch("api/refresh", 'jobtitlelists'); // refresh page
},
downloadEmptyXls() {
window.location.href = "/src/assets/JobTitles.xlsx"
}
}
}
</script>