Yadcf integrate with Meteor simple schema - mongodb

I want to filter column header data from my tabular table.
My goal is to filter:
Numbers (greater than, equal etc...)
Strings
Dates
as in the following example
Thus I want to integrate the filters of yadcf with my tabular table by using the Orion schema, by I can´t conclude,
FIRST OPTION WITH SCHEMA
Mi schema
Tickets = new orion.collection('tickets', {
singularName: 'Tickets',
pluralName: 'Tickets',
title: 'Tickets',
parentPath: '/admin',
link: {title: 'Tickets', parent: '_template'},
tabular: {
scrollX: true,
"processing": true,
dom: 'lBfrtip',
columns: [
{ data: "id", title: "ID" },
{ data: 'employeeName', title: 'Name' }
]
}
});
Tickets.attachSchema(new SimpleSchema({
id: { type: Number, label:'Id del Empleado', optional: true },
employeeName: { type: String, label:'Name', optional: true }
}));
if (Meteor.isServer) {
Meteor.publish('get_Tickets', function() {return Tickets.find();});
};
if (Meteor.isClient) {
Meteor.subscribe('get_Tickets');
};
My.html
{{> tabular table=collection.tabularTable class="table table-striped bordered" id=collection.pluralName }}
SECOND OPTION WITH INSTANCE OF DATATABLE
my.js
var TicketsTab=new Tabular.Table({
name: 'Tickets',
collection: Tickets,
searching:true,
columns: [
{data: "id",title:"ID"},
{data: "employeeName",title:"Name"}
]
});
var myTable = $('#TicketsTab').DataTable();
yadcf.init(myTable, [{column_number:0}]);
In this point I can´t conclude because I don´t know how to add .dataTable().yadcf([...]);

Related

Documents inserted without schema not being found with schema

I have two new collections in MongoDB of data that I pulled from an old Firestore database that I'm moving to mongo. Since the total number between these two collections is roughly 20,000, I opted to paste the raw JSON into the insert document section in mongo, which worked like a charm and I didn't have to write a new insert route to do the same.
I then created a schema in Mongoose that matched the inserted documents, and tried to use the schema to pull back some data, and its always returning nothing.
An example of a ticket inserted via JSON:
{
"title": "How to add and manage users for your company in QuickBooks Online",
"priority": "1",
"type": "Video",
"course": "G205",
"transcriptId": "07dom27Zz98jakvB1oh5",
"status": "In Review",
"tags": "",
"url": "",
"revisionNumber": 0,
"directoryId": 19,
"checkedOut": false
},
And my schema I made to match. The collection name in mongo is also called oldTickets, the plural of my schema name here:
const mongoose = require('mongoose');
var Schema = mongoose.Schema
const schema = new Schema({
course: { type: String },
title: { type: String },
priority: { type: String },
type: { type: String },
course: { type: String },
transcriptId: { type: String },
status: { type: String },
tags: { type: String },
url: { type: String },
revisionNumber: { type: Number },
directoryId: { type: Number },
checkedOut: { type: Boolean },
});
module.exports = mongoose.model('oldTicket', schema);
And finally my model import and fetch call:
const OldTicket = require('./models/model_old_ticket');
/***************************************************************************
* Get Old Tickets - Returns all old tickets, 10 at a time
****************************************************************************/
app.get('/getOldTickets/:offset', (req, res) => {
checkConnection();
OldTicket.find().skip(parseInt(req.params.offset)).limit(10).exec((err, data) => {
if (err){ res.status(500).send({err: err}); }
//If we got data, count the tickets & return the tickets & count
if (data) {
OldTicket.find().countDocuments().then(count => {
return res.status(200).send({
tickets: data,
count: count
})
})
}
});
});
Why isn't this finding anything? Both the count and the tickets are 0. I've run into this issue before when manually creating a collection without a schema, and in those instances I would simply delete the collection, write a route to create a document, and then things would work fine. But with the large data size of these two collections, I'd rather not do that since everything should be working as is.
Edit: Example of document in Mongo
And the name of the collection I'm currently viewing:
And I just now realized that for some reason there are now two collection names, oldTickets, which has data, and oldtickets, which is empty. I'm assuming my query is searching through the empty one? How can I get it to go to the one that actually has data?
can you attach the screenshot of your data with the collection? might be it's different.in mongoose, every collection name is complete with 's'. please verify your collection is created manually by you then it has to same as mongoose schema and also completed with 's'.
example:
const mongoose = require("mongoose");
const schema = new mongoose.Schema(
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
index: true
},
filmId: {
type: mongoose.Schema.Types.ObjectId,
index: true
},
filmType: {
type: String,
index: true
},
birthday: {
type: Date
},
age: {
type: Number
},
terms: {
type: Boolean
}
},
{
versionKey: false,
timestamps: true,
}
);
schema.index({ filmId: 1, user: 1 })
module.exports = mongoose.model("UserAgeVerification", schema);
see my database

ExtJS 7.2 - Loading record into a form with chained comboboxes and forceSelection:true does not load all values

I have a form with two chained comboboxes. The first chained combobox dictates the values that appear in the second. I have forceSelection:true on the second combobox so that when a user changes the first combo, the second will be set blank because it no longer will be a valid option. The chained combos function as expected but when I load a record into this form using getForm().loadRecord(record) the value for the first combo is set properly but the second is not unless I set forceSelection:false.
The following fiddle should make things pretty clear: sencha fiddle
Clicking "Load Record" should load in Fruits/Apple, but only Fruits is shown. Clicking "Load Record" a second time achieves the desired result. If you comment out forceSelection: true it works as expected but then the chained combos don't function as desired. Is there anything I'm doing wrong here?
It is not so easy. What is happening when you are running form.loadRecord(rec).
you set the FoodGroup combobox
you set the FoodName combobox. BUT the value is not there, because your filter did not switch to appropriate food groups. That is why commenting force selection helps. (That is why commenting filter also help).
turned on the filter of food names. Store now have new values.
You are clicking the button second time. The first combobox value is the same, filters are not trigged (triggered?), you already have appropriate values in the second store and the value is selected.
How to fix:
The fix is ugly. You can listen on store 'refresh' (it means the filters are triggered) and then set the second value (or set the values again).
Ext.define('Fiddle.view.FormModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.fiddle-form-model',
stores: {
foodgroups: {
fields: ['name'],
data: [{
foodgroupname: 'Fruits'
}, {
foodgroupname: 'Vegetables'
}]
},
foods: {
fields: ['foodgroupname', 'foodname'],
filters: {
property: 'foodgroupname',
value: '{selectedFoodgroup.foodgroupname}'
},
data: [{
foodname: 'Apple',
foodgroupname: 'Fruits'
}, {
foodname: 'Banana',
foodgroupname: 'Fruits'
}, {
foodname: 'Lettuce',
foodgroupname: 'Vegetables'
}, {
foodname: 'Carrot',
foodgroupname: 'Vegetables'
}]
}
}
});
Ext.define('Fiddle.view.Form', {
extend: 'Ext.form.Panel',
xtype: 'fiddle-form',
viewModel: {
type: 'fiddle-form-model'
},
title: 'Combos',
items: [{
xtype: 'combo',
itemId: 'FoodGroup', // To access FoodGroup
displayField: 'foodgroupname',
bind: {
store: '{foodgroups}',
selection: '{selectedFoodgroup}'
},
valueField: 'foodgroupname',
forceSelection: true,
name: 'foodgroup',
fieldLabel: 'Food Group',
value: 'Vegetables'
}, {
xtype: 'combo',
itemId: 'FoodName', // To access FoodName
bind: {
store: '{foods}'
},
queryMode: 'local',
forceSelection: true, //COMMENTING THIS OUT ACHIEVES DESIRED LOAD RECORD BEHAVIOR
displayField: 'foodname',
valueField: 'foodname',
name: 'food',
fieldLabel: 'Food',
value: 'Carrot'
}],
buttons: [{
text: 'Load Record',
handler: function (btn) {
// OUR UGLY FIX
var form = btn.up('form'),
foodGroupComboBox = form.down('combobox#FoodGroup'),
foodNameComboBox = form.down('combobox#FoodName'),
record = Ext.create('Ext.data.Model', {
foodgroup: 'Fruits',
food: 'Apple'
});
foodNameComboBox.getStore().on('refresh', function (store) {
form.loadRecord(record);
}, this, {
single: true
})
form.loadRecord(record);
}
}]
});
Ext.application({
name: 'Fiddle',
launch: function () {
var form = new Fiddle.view.Form({
renderTo: document.body,
width: 600,
height: 400
});
}
});

How to filter a query based on collection from many-to-many

I have two model objects. Doctors and Hospitals. The model definitions look like:
module.exports = {
schema: true,
autoUpdatedAt: true,
autoCreatedAt: true,
attributes: {
name: {
type: 'string',
required: true,
unique: true
},
hospitals: {
collection: 'hospital',
via: 'doctors',
dominant: true,
},
}
};
and
module.exports = {
schema: true,
autoUpdatedAt: true,
autoCreatedAt: true,
attributes: {
name: {
type: 'string',
required: true,
unique: true
},
doctors: {
collection: 'doctor',
via: 'hospitals',
},
}
};
How can I query doctors that are mapped to certain hospitals? I read a couple posts about through keyword, but I wasn't able to get records to persist to the through/join table. Seems like if I could query the automatic join table, I could get it to work, but I'm curious if there is an "official" way to accomplish this type of query.
My current query looks like: Doctor.find().where({'hospitals': ['548303dcf49435ec4a01f2a2','548303cbf49435ec4a01f2a0']}).populate('hospitals').exec(function (err, doctors) { ... });
The underlying db is mongo, if that matters.
I did cheat a bit but things seem to be working. That said, I am interested if there's a better way to accomplish this type of query.
I created a model object that maps to the auto created join table. So in this case, my additional model object looks like:
module.exports = {
schema: true,
autoUpdatedAt: true,
autoCreatedAt: true,
tableName: 'doctor_hospitals__hospital_doctors',
attributes: {
doctor: {
model: 'doctor',
columnName: 'doctor_hospitals'
},
hospital: {
model: 'hospital',
columnName: 'hospital_doctors'
}
}
};
Now, I query the join table directly and use the results for a sub query:
DoctorHospital.find().where({'hospital': ['548303dcf49435ec4a01f2a2','548303cbf49435ec4a01f2a0']}).exec(function(err, doctorHospitals) {
if(err) return next(err);
Doctor.find().where({'id': _.pluck(doctorHospitals, 'doctor')}).populate('hospitals').exec(function (err, doctors){
if(err) return next(err);
return res.view({
doctors: doctors
});
});
});

I am having trouble with a date field being displayed in a grid

I am having trouble with a date field being displayed in a Extjs grid. I am using php to do the query and return my data in json format. The database is SQL Server. The date is coming back in the json file as:
"TERMDATE":{"date":"2013-02-13 00:00:00","timezone_type":3,"timezone":"America/New_York"}
this is just the date field, there are other fields in the row and they all display properly.
I just want to display the date, should I be doing something in my php file or is there a way to pull the date out of what is being sent. The date field displays as [object Object] when the grid is refreshed.
Here is my SQL Statement:
SELECT CPK_USERS, FNAME, LNAME, STATUS, DEPARTMENT, Email, PHONE1, CellPhone, Work_Ext, HIREDATE, SUPERVISOR, TERMDATE FROM USERS where DELFLAG = 0 and CPK_USERS > 0 order by FNAME
Here is the first record returned in json format:
{"succuss":true,"data":[{"CPK_USERS":153,"FNAME":"Aaron","LNAME":"Booth","STATUS":"Out","DEPARTMENT":"Customer Support","Email":"aaron.booth#xxxxx.com","PHONE1":"2134354709","CellPhone":"6357662738","Work_Ext":"550","HIREDATE":{"date":"2008-06-09 00:00:00","timezone_type":3,"timezone":"America\/New_York"},"SUPERVISOR":"","TERMDATE":{"date":"2013-02-13 00:00:00","timezone_type":3,"timezone":"America\/New_York"}},
My model:
Ext.define('DHS.model.dhsusers.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'CPK_USERS' },
{ name: 'FNAME' },
{ name: 'LNAME' },
{ name: 'STATUS' },
{ name: 'DEPARTMENT' },
{ name: 'Email' },
{ name: 'PHONE1' },
{ name: 'CellPhone' },
{ name: 'Work_Ext' },
{ name: 'HIREDATE' },
{ name: 'SUPERVISOR' },
{ name: 'TERMDATE' }
]
});
My View:
Ext.define('DHS.view.dhsusers.UserInfoList', {
extend: 'Ext.grid.Panel',
alias: 'widget.userinfolist',
frame: true,
store: Ext.create('DHS.store.dhsusers.UserInfo'),
columns:[
{text:"CPK_Users", dataIndex:'CPK_USERS', flex:1, hidden: true, hideable: false},
{text:"First Name", dataIndex:'FNAME', flex:1},
{text:"Last Name", dataIndex:'LNAME', flex:1},
{text:"Term Date", dataIndex:'TERMDATE', flex:1, type:'datecolumn'},
{text:"Email", dataIndex:'Email', flex:1},
{text:"Home Phone", dataIndex:'PHONE1', flex:1},
{text:"Cell", dataIndex:'CellPhone', flex:1},
{text:"Work Ext", dataIndex:'Work_Ext', flex:1}
]
});
I gues you are using TERMDATE as grid column, if you use TERMDATE.date(teorically) you will get riht display. but if you share extjs codes that will be better.

Form field to pick from a list of objects in a store

I'm new to Sencha, trying to implement a Sencha formpanel with a field to pick from a list of objects in a store. This seems like a sufficiently basic pattern that there must be a simple solution. I have a model which defines an ajax endpoint returning a json array (places) of name/id pairs:
Ext.define('MyApp.model.Place', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'name', type: 'string'},
{name: 'id', type: 'int'},
],
proxy: {
type: 'ajax',
url: '/m/places/',
reader: {
type: 'json',
rootProperty: 'places',
},
},
},
});
And a store:
Ext.define('MyApp.store.Place', {
extend: 'Ext.data.Store',
requires: ['MyApp.model.Place'],
config: {
model: 'MyApp.model.Place',
autoLoad: true,
sorters: [
{
property : 'name',
direction: 'ASC',
},
],
},
});
I want a read-only text field for the place name and a hidden field to submit the place id:
{
xtype: 'textfield',
name: 'place_name',
label: 'Place',
readOnly: true,
listeners: {
focus: function () {
var place_picker = Ext.create('Ext.Picker', {
slots: [
{
name: 'place_name',
title: 'Choose a Place',
store: Ext.create('MyApp.store.Place'),
itemTpl: '{name}',
listeners: {
itemtap: function (obj, index, target, record, e, eOpts) {
var form = Ext.getCmp('entityform');
form.setValues({
place_name: record.get('name'),
place_id: record.get('id'),
});
// how to dismiss the picker?
obj.parent.hide();
},
},
},
]
});
Ext.Viewport.add(place_picker);
place_picker.show();
},
},
},
{
xtype: 'hiddenfield',
name: 'place_id',
},
At this point, tapping the field causes the picker to slide up from the bottom and display the loading animation, but it is not being populated with the list of place names, although I can see that the ajax request has been made and that it has returned the expected json document.
I'll stop here and ask if I'm on the right track or is there some better approach out there?
Why isn't the picker being populated with the results of the ajax request? Is my use of itemTpl incorrect?
Am I setting the form fields in a sencha-appropriate way?
How should I dismiss the picker on itemtap? I somehow doubt that my use of hide() is the proper way.
Picker slots has an data config which is an array of objects. It should have a specific format with text and value.
slots :[
data : [{
text : someValue,
value : someValue1,}] ]
You need to add objects which has the fields text and value to slots.