I am trying to show data in vue table using api in api url. Basically I am doing a post request in created method that is sending an id to the server and the server is returning data associated with the id. And simply I am using the api that is returning data. Every thing looks okay but data is not showing in vue table.
vue table
`
<vuetable ref="vuetable"
api-url="http://127.0.0.1:8000/api/patient_previous_appointments"
:fields="fields"
pagination-path=""
:per-page="5"
:multi-sort="true"
:sort-order="sortOrder"
:append-params="moreParams"
:data = "data"
#vuetable:pagination-data="onPaginationData"
>
`
data property
`
data () {
return {
data: [],
fields: FieldsDef_previous_appointment,
sortOrder: [],
moreParams: {}
}
}
`
Fields
`
export const FieldsDef_previous_appointment = [
{
name:'date',
title: 'Date',
sortField: 'date',
titleClass: 'center aligned',
dataClass: 'center aligned',
},
{
name:'doctor',
title: '<i class="fa fa-tag"></i> Doctor',
sortField: 'doctor'
},
{
name:'appointed_by',
title: '<i class="fa fa-tag"></i> Appointed By',
sortField: 'appointed_by'
},
{
name: '__slot:actions',
title: 'Actions',
dataClass: 'center aligned'
}
]
`
Created
`
created () {
const tokenData = JSON.parse(window.localStorage.getItem('authUser'))
var pt_id = tokenData.patient_id
this.$http.get(apiDomain + 'api/patient_previous_appointments',
{patientID:
pt_id})
.then(response => {
console.log(response)
}).catch((e) => {
console.log(e)
})
}
`
response
enter image description here
Related
I am having trouble deleting a MongoDB document using Apollo Client. I don't think my query syntax is the cause because I tested the query in Graphiql and it works fine. This is the error I am getting:
Unhandled Runtime Error
Error: Response not successful: Received status code 500
Call Stack
new ApolloError
node_modules/#apollo/client/errors/index.js (26:0)
Object.error
node_modules/#apollo/client/core/QueryManager.js (127:0)
notifySubscription
node_modules/zen-observable/lib/Observable.js (140:0)
onNotify
node_modules/zen-observable/lib/Observable.js (179:0)
SubscriptionObserver.error
node_modules/zen-observable/lib/Observable.js (240:0)
eval
node_modules/#apollo/client/utilities/observables/iteration.js (4:48)
Array.forEach
<anonymous>
iterateObserversSafely
node_modules/#apollo/client/utilities/observables/iteration.js (4:0)
Object.error
node_modules/#apollo/client/utilities/observables/Concast.js (35:42)
notifySubscription
node_modules/zen-observable/lib/Observable.js (140:0)
onNotify
node_modules/zen-observable/lib/Observable.js (179:0)
SubscriptionObserver.error
node_modules/zen-observable/lib/Observable.js (240:0)
eval
node_modules/#apollo/client/link/http/createHttpLink.js (110:0)
This is my code for the back end:
const CompanyType = new GraphQLObjectType({
name: 'Company',
fields: () => ({
_id: { type: GraphQLString },
name: { type: GraphQLString },
description: { type: GraphQLString },
users: {
type: new GraphQLList(UserType),
resolve(parentValue, args) {
return User.findUsers(parentValue._id);
},
},
}),
});
const mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
deleteCompany: {
type: CompanyType,
args: { _id: { type: new GraphQLNonNull(GraphQLString) } },
resolve(parentValue, { _id }) {
return Company.remove({ _id }).catch((err) => console.log(err));
},
},
},
});
This is my code for my React frontend
import React from 'react';
import { gql, useMutation } from '#apollo/client';
const DELETE_COMPANY = gql`
mutation DeleteCompany($id: String!) {
deleteCompany(_id: $id) {
_id
}
}
`;
const CompanyList = () => {
const { loading: loadingList, error: errorList, data: dataList } = useQuery(
COMPANY_LIST
);
const [
deleteCompany,
{ loading: loadingDelete, error: errorDelete, data: dataDelete },
] = useMutation(DELETE_COMPANY);
const renderCompanies = () =>
dataList.companies.map((company) => (
<li key={company._id}>
{company.name}
<button
onClick={() => {
deleteCompany({ variables: { _id: company._id } });
}}
>
delete
</button>
</li>
));
return (
<div>
{loadingList || loadingDelete ? <h1>Loading...</h1> : renderCompanies()}
</div>
);
};
I am using CKEditor5 with Vue. In my Vuex store, I have the following property:
const state = {
EditMode: false,
}
On a button click by a user with permission, I modify the Vuex store. If EditMode: true, I want to display the in-line editor. Else, display the raw HTML editorData (the user is not authorized to edit, or not in edit mode). I do that below:
<template>
<vx-card :title="editorName" v-if="this.$store.state.EditMode">
<ckeditor :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
</vx-card>
<vx-card :title="editorName" v-else>
<div v-html="editorData"></div>
</vx-card>
</template>
<script>
import InlineEditor from '#ckeditor/ckeditor5-build-inline'
export default {
name: "RichTextEditor",
props: {
editorName: {
type: String,
required: true,
},
},
data() {
return {
loaded: false,
time: null,
timeElapsedSinceEdit: 0,
editor: InlineEditor,
editorData: 'New entry!',
editorConfig: {
toolbar: {
items: [
'|',
'heading',
'fontFamily',
'fontSize',
'fontColor',
'bold',
'underline',
'italic',
'alignment',
'link',
'highlight',
'superscript',
'subscript',
'|',
'indent',
'outdent',
'|',
'blockQuote',
'horizontalLine',
'imageUpload',
'insertTable',
'mediaEmbed',
'undo',
'redo'
]
},
language: 'en',
image: {
toolbar: [
'imageTextAlternative',
'imageStyle:full',
'imageStyle:side'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
},
},
}
},
// Below code is situation-specific and not completely relevant
watch: {
editorData: function() {
if (this.loaded) {
this.upsertData()
}
}
},
methods: {
async pollData() {
await
this.$http.get('/api/rte/' + this.editorName)
.then((response) => {
this.editorData = response.data.content
})
.catch((error) => {
if (window.environment == "production") {
location.href = 'pages/error-500/'
} else {
console.log(error.stack)
}
})
this.loaded = true;
},
async upsertData() {
console.log('up')
await
this.$http.post('/api/rte/' + this.editorName + '/upsert', {
data: this.editorData,
})
.then((response) => {
this.$vs.notify({
title: 'Action Completed',
text: response.data.message,
color: 'success',
position: 'top-right'})
})
.catch((error) => {
if (window.environment == "production") {
location.href = 'pages/error-500/'
} else {
console.log(error)
}
})
},
},
created() {
this.pollData();
},
}
</script>
This works, but the in-line styling isn't respected with v-html (sizing and centering). If this.$store.state.EditMode: false, I get the following output:
If this.$store.state.EditMode: true I get this in the in-line editor (as expected).
Raw HTML (editorData property after pollData() is called)
<figure class="image image_resized" style="width:25.51%;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTRJO0xRohucbxcjlRoiRaw2cWYTbilYch5NQ&usqp=CAU" alt="Free clipart megaphone announcement public domain vectors - Clipartix"></figure><h2 style="text-align:center;"><span style="color:hsl(30,75%,60%);"><strong>We have a new Intranet!</strong></span></h2><p style="text-align:center;">Summer / Fall Wellness Challenge Link</p>
Research showed that Vue's v-html doesn't respect scoped styling. I'm not entirely sure how that applies to in-line styling. To test output, I replaced my else with the raw HTML and got the same visual output as when I used v-html:
<vx-card :title="editorName" v-else>
<figure class="image image_resized" style="width:25.51%;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTRJO0xRohucbxcjlRoiRaw2cWYTbilYch5NQ&usqp=CAU" alt="Free clipart megaphone announcement public domain vectors - Clipartix"></figure><h2 style="text-align:center;"><span style="color:hsl(30,75%,60%);"><strong>We have a new Intranet!</strong></span></h2><p style="text-align:center;">Summer / Fall Wellness Challenge Link</p>
</vx-card>
What is the proper way to disable the inline editor and maintain visual consistency?
<template>
<vx-card :title="editorName" v-if="loaded">
<ckeditor :editor="editor" v-model="editorData" :config="editorConfig" :readonly="editorDisabled" :disabled="editorDisabled" ></ckeditor>
</vx-card>
</template>
//...
watch:{
'$store.state.EditMode'(value, oldValue) {
if(value) {
this.editorDisabled = false;
} else {
this.editorDisabled = true;
}
},
},
//...
Question answered here:
https://github.com/ckeditor/ckeditor5-vue/issues/154
I have an article post service, which has an upload form with uppy.io
Everything works great, but I need to edit those articles and their linked images.
How can I prefill already uploaded images to the uppy.io DashBoard?
My actual code:
<div class="DashboardContainer"></div>
<!-- AJAX Uploading for Add Post -->
<script src="https://transloadit.edgly.net/releases/uppy/v1.8.0/uppy.min.js"></script>
<script src="https://transloadit.edgly.net/releases/uppy/locales/v1.11.0/es_ES.min.js"></script>
<script>
const uppy = Uppy.Core({
debug: true,
autoProceed: true,
restrictions: {
maxFileSize: 600000,
maxNumberOfFiles: 10,
minNumberOfFiles: 1,
allowedFileTypes: ['.jpg', '.jpeg', '.png', '.gif']
},
locale: Uppy.locales.es_ES
})
.use(Uppy.Dashboard, {
inline: true,
target: '.DashboardContainer',
replaceTargetContent: true,
showProgressDetails: true,
note: 'Sólo imágenes, hasta 10 fotos, de no más de 800kb',
height: 350,
width: '100%',
metaFields: [{
id: 'name',
name: 'Name',
placeholder: 'Nombre del fichero subido'
},
{
id: 'caption',
name: 'Caption',
placeholder: 'Describe la imagen que estás subiendo'
}
],
browserBackButtonClose: true,
plugins: ['Webcam']
})
.use(Uppy.XHRUpload, {
endpoint: "{{ route('save-image-ajax') }}",
formData: true,
fieldName: 'files[]',
headers: {
'X-CSRF-TOKEN': $('meta[name="token"]').attr('content')
},
})
uppy.on('upload-success', (file, response) => {
response.status // HTTP status code
response.body // extracted response data
// do something with file and response
$('<input>', {
type: 'hidden',
name: 'imageID[]',
value: response.body.imageID
}).appendTo("#add");
})
uppy.on('complete', result => {
console.log('successful files:', result.successful)
console.log('failed files:', result.failed)
})
</script>
The form works great for publishing an article, I just want to edit them, even the linked images.
You can prefill images from url (first converting the remote image into blob):
fetch({{your_image_url}})
.then((response) => response.blob())
.then((blob) => {
uppy.addFile({
name: "image.jpg",
type: blob.type,
data: blob
});
});
And then, set the state of the loaded images to "Completed" to avoid Uppy re upload them:
uppy.getFiles().forEach(file => {
uppy.setFileState(file.id, {
progress: { uploadComplete: true, uploadStarted: false }
})
})
Also, the property "autoProceed" must be false in the Uppy object configuration.
Source: https://github.com/transloadit/uppy/issues/1112#issuecomment-432339569
How to add action buttons in frontend vue.js when using server side dataTables?
here is what i have so far, this code is working, but action buttons not give the request when clicking. (the alert is not also firing). the action buttons are showing and calling to editTaxGroup()
$(document).ready(function() {
let tax = 1;
self.dataTable = $("#tax_groups2").DataTable({
serverSide: true,
ajax: {
"columns": [
{ "data": "tax_group_name" },
{ "data": "country.country_name" },
{ "data": "tax_rate_percentage" },
{ "data": "Edit" },
{ "data": "Delete" }
],
data: {
"token": localStorage.getItem("token"),
},
url: 'api/v1/get-tax-groups',
dataFilter: function(data){
var json = jQuery.parseJSON( data );
json.recordsTotal = 100;
json.recordsFiltered = 100;
self.tax_groups = data.data;
return JSON.stringify( json ); // return JSON string
}
},
columns: [
{data: "tax_group_name"},
{data: "country.country_name",},
{data: "tax_rate_percentage"},
{data: "Edit"},
{data: "Delete"},
],
"columnDefs": [
{
"targets": [ -2 ],
"data":"id",
"defaultContent" : '<i class="fas fa-pen"></i>'
},
{
"targets": [ -1 ],
"data":"id",
"defaultContent" : '</i>'
}
],
});
})
$('#tax_groups2 tbody ').on('click', '#edit', function () {
for (let key in self.tax_groups){
alert(1)
console.log(key);
if(self.tax_groups.hasOwnProperty(key)){
console.log(`${self.tax_groups[key]}`)
}
}
} );
});
},
This isn't using Vue at all. You could actually more efficiently use Vue to generate these tables dynamically and set buttons as well. You may want to remove the Vue tag or re-ask the question.
I am working with vue-form-wizard by Cristi Jora integrating Element UI the basic example is here
Vue.use(VueFormWizard)
new Vue({
el: '#app',
data: {
formInline: {
user: '',
region: '',
gender: ''
},
rules: {
user: [{
required: true,
message: 'Please input Activity name',
trigger: 'blur'
}, {
min: 3,
max: 5,
message: 'Length should be 3 to 5',
trigger: 'blur'
}],
region: [{
required: true,
message: 'Please select Activity zone',
trigger: 'change'
}],
}
},
methods: {
onComplete: function() {
alert('Yay. Done!');
},
validateFirstStep() {
return new Promise((resolve, reject) => {
this.$refs.ruleForm.validate((valid) => {
resolve(valid);
});
})
}
}
})
https://jsfiddle.net/bt5dhqtf/409
but i am not able to validate radio buttons, please help me :(
here is my example
https://jsfiddle.net/bt5dhqtf/884/