adding views using EXT sdk store issue - extjs
I have the following app.js file.
When i run the command with out the "require" it works but does not include the views. When i add the required line i'm getting "store is undefine".
I guess this is because the store are not defined at that point. So what is best play here?
sencha create jsb -a http://mysite.local/ext/cutter/app/index.html -p app.jsb3
app.js
Ext.Loader.setConfig({ enabled: true });
Ext.Loader.setPath('App', '/ext/Cutter/app');
Ext.Loader.require(['App.view.ViewCutter']);
Ext.application({
name: 'Mis',
appFolder: '/ext/Cutter/app',
models: [ 'Cutter', 'Project', 'CutterHistory','Job', 'Part' , 'ClientFinder'],
stores: [ 'Cutters','CutterHistories','Projects', 'Jobs', 'Parts'],
controllers: ['Cutter'],
launch: function () {
Ext.QuickTips.init();
var cmp1 = Ext.create('App.view.ViewCutter', {
renderTo: "mis-application"
});
cmp1.show();
}
});
UPDATE
Here is the jsb created
{
"projectName": "Project Name",
"licenseText": "Copyright(c) 2012 Company Name",
"builds": [
{
"name": "All Classes",
"target": "all-classes.js",
"options": {
"debug": true
},
"files": [
{
"clsName": "Mis.model.Cutter",
"name": "Cutter.js",
"path": "/ext/Cutter/app/model/"
},
{
"clsName": "Mis.store.Cutters",
"name": "Cutters.js",
"path": "/ext/Cutter/app/store/"
},
{
"clsName": "Mis.model.CutterHistory",
"name": "CutterHistory.js",
"path": "/ext/Cutter/app/model/"
},
{
"clsName": "Mis.store.CutterHistories",
"name": "CutterHistories.js",
"path": "/ext/Cutter/app/store/"
},
{
"clsName": "Mis.model.Project",
"name": "Project.js",
"path": "/ext/Cutter/app/model/"
},
{
"clsName": "Mis.store.Projects",
"name": "Projects.js",
"path": "/ext/Cutter/app/store/"
},
{
"clsName": "Mis.model.Job",
"name": "Job.js",
"path": "/ext/Cutter/app/model/"
},
{
"clsName": "Mis.store.Jobs",
"name": "Jobs.js",
"path": "/ext/Cutter/app/store/"
},
{
"clsName": "Mis.model.Part",
"name": "Part.js",
"path": "/ext/Cutter/app/model/"
},
{
"clsName": "Mis.store.Parts",
"name": "Parts.js",
"path": "/ext/Cutter/app/store/"
}
]
},
{
"name": "Application - Production",
"target": "app-all.js",
"compress": true,
"files": [
{
"path": "",
"name": "all-classes.js"
},
{
"path": "",
"name": "app.js"
}
]
}
],
"resources": []
}
controller
Ext.define('Mis.controller.Cutter', {
extend:'Ext.app.Controller',
refs:[
{
ref:'Cutter',
selector:'Cutter'
},
{
ref:'CutterEdit',
selector:'CutterEdit'
}
],
// views: ['ViewCutter'],
stores:[ 'Cutters', 'CutterHistories', 'Clients' , 'Projects' , 'Jobs' , 'Parts' ],
init:function () {
this.control({
'#category menu':{
click:this.onCutterTypeSelect
},
'#cutterGrid button[action=create]':{
click:this.onCutterCreate
},
'#sortby menu':{
click:this.onSortBySelect
},
'#cutterGrid button[action=search]':{
click:this.onSearch
},
'#cutterGrid':{
cellclick :this.onCutterSelectRow
},
'#cutterHistories actioncolumn':{
click:this.onCutterHistoryRemove
},
'#cutterForm button[action=save]':{
click:this.onCutterUpdate
},
'#cutterForm button[action=remove]':{
click:this.onCutterRemove
},
'#cutterForm button[action=create]':{
click:this.onCutterNumberCreate
},
'#cutterForm #ClientDropdown': {
select: this.onClientSelect
},
'#cutterForm #ProjectDropdown': {
select: this.onProjectSelect
},
'#cutterForm #JobDropdown': {
select: this.onJobSelect
}/*,,
'#cutterForm #Clients': {
change: this.onClientSelect
},
'#cutterForm #Projects': {
change: this.onProjectSelect
},
'#cutterForm #Jobs': {
change: this.onJobSelect
}*/
});
},
onLaunch:function () {
var cutterStore = this.getCuttersStore();
cutterStore.load();
var clients = this.getClientsStore();
clients.load();
Ext.getCmp('cutterFieldset').setVisible(false);
},
onLoad:function (selection) {
},
onSortBySelect:function (selModel, selection) {
var action = selection.action;
if (selection != null) {
if (action != "") {
contactUrl = "/Contact/" + action;
sortBy = action;
}
}
},
onClientSelect: function (selModel, selection) {
var projects = this.getProjectsStore();
projects.load({
url: '/Projects/ReadByClientId/' + selection[0].data.Id,
scope: this
});
Ext.getCmp('ProjectDropdown').setValue("---- Select -----");
Ext.getCmp('JobDropdown').setVisible(false);
Ext.getCmp('PartDropdown').setVisible(false);
},
onProjectSelect: function (selModel, selection) {
Ext.getCmp('JobDropdown').setValue("---- Select -----");
var jobs = this.getJobsStore();
jobs.load({
url: '/Jobs/ReadByProject/' + selection[0].data.Id,
scope: this
});
Ext.getCmp('JobDropdown').setVisible(true);
Ext.getCmp('PartDropdown').setVisible(false);
},
onJobSelect: function (selModel, selection) {
var parts = this.getPartsStore();
parts.load({
url: '/Part/Read/' + selection[0].data.Id,
scope: this
});
Ext.getCmp('PartDropdown').setValue("---- Select -----");
Ext.getCmp('PartDropdown').setVisible(true);
},
onClientFinder: function (selModel, selection) {
var clientId = Ext.getCmp('ClientId').value;
var projectId = Ext.getCmp('ProjectId').value;
var jobId = Ext.getCmp('JobId').value;
var partId = Ext.getCmp('PartId').value;
var clientGuid = Ext.getCmp('Clients').value;
var projectGuid = Ext.getCmp('Projects').value;
var jobGuid = Ext.getCmp('Jobs').value;
var partGuid = Ext.getCmp('Parts').value;
var form = Ext.getCmp('cutterForm');
Ext.Ajax.request({
method:'POST',
url:'/Cutter/ClientFinder',
params:{ ClientId:clientId, ClientGuid:clientGuid, ProjectId:projectId, ProjectGuid:projectGuid, JobId:jobId, JobGuid: jobGuid },
success:function (request) {
var data = Ext.decode(request.responseText);
if (data.ClientId != 0) Ext.getCmp('ClientId').setValue(data.ClientId);
if (data.ProjectId != 0) Ext.getCmp('ProjectId').setValue(data.ProjectId);
if (data.JobId != 0) Ext.getCmp('JobId').setValue(data.JobId);
if (data.PartId != 0) Ext.getCmp('PartId').setValue(data.PartId);
Ext.getCmp('Clients').setValue(data.ClientGuid);
Ext.getCmp('Projects').setValue(data.ProjectGuid);
Ext.getCmp('Jobs').setValue(data.JobGuid);
Ext.getCmp('Parts').setValue(data.PartGuid);
}
});
},
onCutterHistoryRemove: function(gridview, el, rowIndex, colIndex, e, rec, rowEl) {
var store = this.getCutterHistoriesStore();
Ext.Msg.confirm('Remove History', 'Are you sure?', function(btn, text){
if (btn == 'yes'){
rec.destroy({
success:function () {
store.remove(rec);
Ext.MessageBox.alert('Status', 'History removed.');
},
callback:function () {
},
failure:function () {
Ext.MessageBox.alert('Status', 'History cannot be removed as it has related items');
}
});
}
});
},
onCutterRemove:function (selection) {
var form = Ext.getCmp('cutterForm');
var record = form.getRecord();
var values = form.getValues();
record.set(values);
var cutterStore = this.getCuttersStore();
Ext.Msg.confirm('Remove Cutter', 'Are you sure?', function(btn, text){
if (btn == 'yes'){
record.destroy({
success:function () {
cutterStore.remove(record);
var view = Ext.widget('EditCutter');
view.close();
},
callback:function () {
},
failure:function () {
Ext.MessageBox.alert('Status', 'This cutter cannot be removed as it has related items');
}
});
}
});
},
onCutterSelectRow : function (item, td, cellIndex, rec, tr, rowIndex, e, eOpts ) {
if (rec != null) {
var view = Ext.widget('EditCutter');
var cutters = this.getCutterHistoriesStore();
cutterNumber = rec.data.CutterNumber;
cutters.load({
url: '/CutterHistory/Read/' + rec.data.Id,
scope: this
});
var form = Ext.getCmp('cutterForm');
form.loadRecord(rec);
/* Load client */
var clientStore = this.getClientsStore();
var clientCombo = Ext.getCmp("ClientDropdown");
var clientUrl = '/Client/Read/';
selectCombo(clientStore, clientCombo, rec.data.ClientGuid, clientUrl);
/* Load projects */
var projectsStore = this.getProjectsStore();
var projectCombo = Ext.getCmp("ProjectDropdown");
var projectUrl = '/Projects/ReadByClientId/' + rec.data.ClientGuid;
selectCombo(projectsStore, projectCombo, rec.data.ProjectGuid, projectUrl);
/* Load job */
var jobsStore = this.getJobsStore();
var jobCombo = Ext.getCmp("JobDropdown");
var jobUrl = '/Jobs/ReadByProject/' + rec.data.ProjectGuid;
selectCombo(jobsStore, jobCombo, rec.data.JobGuid, jobUrl);
/* Load part */
var partsStore = this.getPartsStore();
var partCombo = Ext.getCmp("PartDropdown");
var partUrl = '/Part/Read/' + rec.data.JobGuid;
selectCombo(partsStore, partCombo, rec.data.PartGuid, partUrl);
Ext.getCmp('cutterFieldset').setVisible(true);
Ext.getCmp('CutterSave').setVisible(true);
view.show()
}
},
onCutterCreate:function (selModel, selection) {
var r = Ext.ModelManager.create({
}, 'Mis.model.Cutter');
var view = Ext.widget('EditCutter');
var form = Ext.getCmp('cutterForm');
form.loadRecord(r);
Ext.getCmp('cutterFieldset').setVisible(true);
Ext.getCmp('CutterSave').setVisible(true);
view.show();
},
onCutterNumberCreate:function (selModel, selection) {
var form = Ext.getCmp('cutterForm');
var r = Ext.ModelManager.create({
CutterNumber: cutterNumber
}, 'Mis.model.Cutter');
form.loadRecord(r);
},
onSearch:function (selModel, selection) {
destroyed = Ext.getCmp('Destroyed').value;
var searchBox = Ext.getCmp('SearchTerm');
search = searchBox.getValue();
var cuttersStore = this.getCuttersStore();
cuttersStore.proxy.setExtraParam('sort', sortBy);
cuttersStore.proxy.setExtraParam('search', search);
cuttersStore.proxy.setExtraParam('destroyed', destroyed);
cuttersStore.load({params:{start:0, page:1}});
var url = Ext.String.format('/Cutter/Export/?sortBy={0}&search={1}&destroyed={2}', sortBy, search, destroyed);
Ext.getCmp('ExportCutter').el.down('a').dom.setAttribute('href', url);
},
onCutterUpdate:function (selection) {
var form = Ext.getCmp('cutterForm');
var record = form.getRecord();
var values = form.getValues();
record.set(values);
// var cutterNumbersStore = this.getCutterNumbersStore();
var cuttersStore = this.getCuttersStore();
if (form.getForm().isValid()) {
record.save({
success:function () {
Ext.MessageBox.alert('Status', 'Changes saved successfully.');
// cutterNumbersStore.insert(0, record);
// cuttersStore.load();
},
callback:function () {
},
failure:function () {
Ext.MessageBox.alert('Status', 'Changes could not be saved');
}
});
} else {
Ext.MessageBox.alert('Status', 'Please enter all fields');
}
}
});
function selectCombo(store, combo, selectedValue, url) {
store.load({
url: url,
callback: function(){
combo.setValue(selectedValue);
},
scope: this
});
}
Remove
Ext.Loader.require(['App.view.ViewCutter']);
Your controller App.view.ViewCutter should have line views: ['ViewCutter'] and this effectively would tell Sencha SDK to include App.view.ViewCutter.js file into bundle.
Related
Push nested json values to array using node js
I need to show my json results into nested array format: { "state": [ { "stateName": "tamilnadu" } ], "city": [ { "cityName": "chennai" } ] } This is my code. I'm new in node development exports.stateId = function (req, res) { state.find(req.body.countryId, function() { var query = N1qlQuery.fromString('SELECT stateId,stateName FROM travel _type='state''); myBucket.query(query, async function(err, result) { var state=[]; await result.forEach(ele => { var item= { stateName:ele.stateName } if(ele.stateName != undefined) state.push(item); }); res.send({state}); }); }); }; exports.cityId = function (req, res) { city.find(req.body.stateId, function() { var query = N1qlQuery.fromString('SELECT cityId,cityName FROM travel where _type="city"'); myCluster.query(query, async function(err, result) { var city=[]; await result.forEach(ele => { var item= { cityName:ele.cityName } if(ele.cityName != undefined) city.push(item); }); res.send({city}); }); }); }; Currently i will get results like two different array. i need to merge json results into single nested data
If you have the following data: const data_1 = { "state": [ { "stateName": "tamilnadu" } ] }; const data_2 = { "city": [ { "cityName": "chennai" } ] }; and your desired object is: { "state": [ { "stateName": "tamilnadu" } ], "city": [ { "cityName": "chennai" } ] } then you can use Object.assign method: let desired = Object.assign({}, data_1, data_2); console.log(`desired: `, desired)
AngularJS: mocking the service in a controller using Jasmine
Could you please help me to write down the Jasmine(2.0) test code for mock of the service in a Controller as below. readJsonFactory.js angular.module('myAssignmentTaskApp') .factory('readJsonFactory', function ($http) { var userExists = false; var responseData = []; return $http.get('../json/AutoTestDB1.json').then(function (response) { for (var i=0; i<response.data.StatusTable.length; i++){ responseData.push(response.data.StatusTable[i].RunId); } return response; }).catch(function (error) { // }) }); The Controller file readjson.js is as below. angular.module('myAssignmentTaskApp') .controller('ReadjsonctrlCtrl', function ($scope,readJsonFactory,$location) { var testCaseNameFromReadJsonFactory = []; readJsonFactory.then(function (response) { for (`var i=0;i<response.data.StatusTable.length;i++`){ testCaseNameFromReadJsonFactory.push(response.data.StatusTable[i].TestScenario); } } }) AutoTestDB1.json { "StatusTable": [ { "RunId": "bah_regression_alternateFlights", "TestScenario": "BAH - Change Default Search Options", "Area": "Yes", "TestCases": [ { "TestID": "", "TestName": "VerifyCarDepotPageIsDisplayed_Test", "Status": [ { "Release": " R301", "Runner": "yes", "Status": "Passed", "details": [ { "ResponseTime": "1m 26s 702ms", "Status": "Passed", "RecordData": 1511519114413 } ] } ] } ] } ] } Please post an apporopriate spac.js file. Thanks in advance.
You do use the following to mock your service beforeEach(function() { angular.mock.module('myAssignmentTaskApp', ($provide) => { const mockReadJsonFactory = { }; $provide.constant('readJsonFactory', mockReadJsonFactory); }); });
Unable to show JSON data injected using service inside the amchart directive dataprovider
I am using amcharts as a custom directive. Now I want to fetch the dataProvider of this AmChart from the output of the $http.get service using webservices. But I am unable to get this dynamically assigned to the dataprovider of the amChart. var app=angular.module('mainApp',[]); app.service('dataProviderService',function($http){ this.getData= function(){ return $http.get('jaxrs/WebService/getJSONData'); }; }); app.directive('myChart',['dataProviderService',function (dataProviderService) { return { restrict: 'E', replace:true, template: '<div id="chartdiv" style="min-width: 310px; height: 400px; margin: 0 auto"></div>', link: function (scope, element, attrs) { scope.data={}; dataProviderService.getData().then(function(response){ scope.data=response.data; },function(error){ scope.status="Show error"; }); var chart = false; var initChart = function() { if (chart) chart.destroy(); var config = scope.config || {}; chart = AmCharts.makeChart( "chartdiv", { "theme": "none", "type": "serial", "dataProvider": dataProviderService.newData(), "categoryField": "OT", "depth3D": 20, "angle": 30, "categoryAxis": { "labelRotation": 90, "gridPosition": "start" }, "valueAxes": [ { "title": "availability" } ], "graphs": [ { "valueField": "availability", "colorField": "color", "type": "column", "lineAlpha": 0.1, "fillAlphas": 1 } ], "chartCursor": { "cursorAlpha": 0, "zoomable": false, "categoryBalloonEnabled": false }, "export": { "enabled": true } } ); }; initChart(); }//end watch } }]) ;
Assuming your newData() method is an asynchronous $http.get() request like your getData() method, you need to either call makeChart after the request resolves itself or tell the chart to redraw itself by calling validateData() when the request resolves itself. Here's an example of doing this inside the chart's init event: chart = AmCharts.makeChart( "chartdiv", { // ... omitted ... "dataProvider": [], // ... omitted ... "listeners": [{ "event": "init", "method": function(e) { dataProviderService.newData().then(function(response) { e.chart.dataProvider = response; e.chart.validateData(); }, function(error) { // do something else }); } }] } );
update item of array of array in mongodb
I want to push an item to the array of items (root document > categories > subcategories > items) I am using NodeJS with MongoDB npm package My document structure should be like the following { "_id": "572a77641b24ed3404f43690" "categories": [ { "id": "572bbac072d7ee3026a69467" "Name": "Foods", "subcategories": [ { "id": "572a777c1b24ed3404f43691", "Name": "Pizza" "items": [ { "id": "572ba1666ca263303121acd4" "Name": "4 Seasons", "Price": "6.0" } ] } ] } ] } My current code is app.post("/item/:subcatid", function(req, res) { var subId = req.params.subcatid; var item = req.body; item.id = new ObjectId(); items.update({ "categories.subcategories.id": ObjectId(subId) }, { $push: { "categories.0.subcategories.$.items": item } }, function(err, result) { res.send(result); }); }); What can I do ?
Just found a solution, not clean one though but works properly ! app.post("/item/:subcatid", function(req, res) { var subId = req.params.subcatid; var item = req.body; item.id = new ObjectId(); items.findOne({ "categories.subcategories.id": ObjectId(subId) }, { "categories.subcategories.$": 1 }, function(err, doc) { for (var i = 0; i < doc.categories[0].subcategories.length; i++) { var elem = doc.categories[0].subcategories[i]; if (elem.id == subId) { items.update({ "categories.subcategories.id": ObjectId(subId) }, { $push: { ["categories." + i + ".subcategories.$.items"]: item } }, function(err, result) { res.send(result); }); break; } } }); });
Ace editor autocomplete uploads extra-records
I added ui-ace editor to the my application with angular. Instead of requesting words every time, I get a json 1 time, during application initiation. Example of json-file: [ { "Word": "Do {int} + {int}", "Meta": "Implemented" }, { "Word": "Line3", "Meta": "Not-implemented" }, { "Word": "Line2", "Meta": "Not-implemented" }, { "Word": "Line4", "Meta": "Not-implemented" }, { "Word": "444", "Meta": "Not-implemented" }, { "Word": "E1", "Meta": "Not-implemented" }, { "Word": "E2", "Meta": "Not-implemented" }, { "Word": "E1Try", "Meta": "Not-implemented" }, { "Word": "E3", "Meta": "Not-implemented" }, { "Word": "E4444", "Meta": "Not-implemented" } ] The issue is that some of words are listed in autocomplete more than ones, take a look on a screenshot: http://take.ms/N8BFZ . Here's how I load ace-editor, where ctrl.listStepLines is an object which contains json-response from API: $scope.aceLoaded = function(_editor){ // Editor part var _session = _editor.getSession(); var _renderer = _editor.renderer; _editor.$blockScrolling = Infinity; _editor.setOptions({ minLines: 10, maxLines: 40, wrap: true, firstLineNumber: 1, enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true }) var langTools = ace.require("ace/ext/language_tools"); var rhymeCompleter = { getCompletions: function (editor, session, pos, prefix, callback) { if (prefix.length === 0) { callback(null, []); return } callback(null, ctrl.listStepLines.map(function (ea) { return { name: ea.Word, value: ea.Word, meta: ea.Meta } })); } } langTools.addCompleter(rhymeCompleter); };
The issue was that angularjs loaded my function a lot of times and ace editor had 14 similar completers. I refactored my code and create a separate function for completer adding which is called only one time. ctrl.addAutoCompleter(); function init() { ctrl.addAutoCompleter = function () { var langTools = ace.require("ace/ext/language_tools"); var stepLineCompleter = { getCompletions: function (_editor, session, pos, prefix, callback) { if (prefix.length === 0) { callback(null, []); return } callback(null, ctrl.listStepLines.map(function (ea) { return { name: ea.Word, value: ea.Word, meta: ea.Meta } })); } } langTools.addCompleter(stepLineCompleter); } };