Displaying a report with JS: How to check if a report exist? - iccube

Is there a convenient was to check if a report with the given report name exists using JavaScript?
Following this official guide on how to display a report I managed to display a report with the name given in the URL. If the given report name does not match a report I get a error:
Could not open successfully the report 'fake-name' (The report '/shared/fake-name.icc-report (null)' does not exists.)
So I want to redirect the user if the report does not exists and for that I need something like a function that gives me true or false based on the report name.
Is there any way this can be done?
Thanks. :)

I suggest using these options to have access to openReport callback:
var options = {
root: ic3root,
rootLocal: ic3rootLocal,
imagesPath: 'images',
//librariesMode:'dev',
callback: function () {
$('#intro').remove();
var ic3reporting = new ic3.Reporting(
{
noticesLevel: ic3.NoticeLevel.ERROR,
dsSettings: {
url: "http://<your_domain>/icCube/gvi"
}
});
ic3reporting.setupGVIConfiguration(function () {
ic3reporting.setupApplication(
{
mode: ic3.MainReportMode.REPORTING,
hideTopPanel: true,
noticesLevel: ic3.NoticeLevel.ERROR,
container: $("#container")
});
ic3reporting.openReport({
report: {
name: 'shared/report23'
}
}, function (reportState) {
var reportExists = _.isEmpty(ic3reporting.reportName());
})
});
}
};
ic3ready(options);
You may want to redirect user in case "reportExists" equals to false

Related

Meteor, creating update form and filling fields

I have the following structure:
{
id: 23423-dsfsdf-32423,
name: Proj1,
services: [
{
id:sdfs-24423-sdf,
name:P1_Service1,
products:[{},{},{}]
},
{
id:sdfs-24jhh-sdf,
name:P1_Service2,
products:[{},{},{}]
},
{
id:sdfs-2jnbn3-sdf,
name:P1_Service3,
products:[{},{},{}]
}
]
},
{
id: 23423-cxcvx-32423,
name: Proj2,
services: [
{
id:sdfs-xvxcv-sdf,
name:P2_Service1,
characteristics:[{},{},{}]
},
{
id:sdfs-xvwqw-sdf,
name:P2_Service2,
characteristics:[{},{},{}]
},
{
id:sdfs-erdfd-sdf,
name:P2_Service3,
characteristics:[{},{},{}]
}
]
}
I have no problem creating a form this schema an insert form with quickForm.
But I cant figure out (and tried to read every tutorial and instruction and nothing worked) how to create an update form with all fields filled and (need to expand and fill the services and the characteristics arrays also:
of course, as i said, in update i need the services and characteristics to expend to the right size with all the fields.
But if i could understand how to fill the form fields i could understand myself how to expend the arrays...
i've tried:
{{> quickForm collection="Projects" id="updateProjectForm" collection="Projects" type="method" class="update-project-form" doc=project }}
with:
import SimpleSchema from 'simpl-schema';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
// Attaching the subscription to the template so we can reuse it
Template.ProjectSingle.onCreated(function(){
var self = this;
self.autorun(function(){
var id = FlowRouter.getParam('id');
self.subscribe('projectSingle', id);
});
});
Template.ProjectSingle.helpers({
project: ()=> {
var id = FlowRouter.getParam('id');
console.log(Projects.findOne({_id: id}));
return Projects.findOne({_id: id});
}
});
I can't even see the console.log() printing.
This solution at list didn't crash the meteor server... everything else i've tried crashed the server on many errors
Maybe i need to mention that i'm using partials so maybe there is a problem with the JS files but i don't think so as the onCreated method is being read.
10x.
EDIT:
I've removed the partial for the update template and it is now in the root Template with its own JS with the method:
projectDoc: ()=> {
var id = FlowRouter.getParam('id');
console.log("Update: " + Projects.findOne({_id: id}));
return Projects.findOne({_id: id});
}
Now i can see this method is being called but for some reason it is being called twice. First with the correct data and then getting undefined so i've still not getting the fields showing anything but if i could find why it is being called twice i will solve the first level form (no services and so on)
Solved it (Not sure this is the best way as i'm still having two calls to the method but this is working for now:
projectDoc: ()=> {
var id = FlowRouter.getParam('id');
if(Projects.findOne({_id: id}) != null){
console.log(Projects.findOne({_id: id}));
thisProject = Projects.findOne({_id: id});
return Projects.findOne({_id: id});
} else {
return thisProject;
}
}

Meteor-down load testing

I am trying to make load/stress test to my website. I am using meteor-down. I wrote the test file my_load_test.js
meteorDown.init(function(Meteor) {
var title = "question"
var description = "description"
var tags = ["javascript"]
let data = {
title,
description,
tags
}
Meteor.call('createQuestion', data, function(err, result) {
Meteor.kill();
});
});
meteorDown.run({
concurrency: 10,
url: "http://localhost:3000/discussions",
key: 'mykey',
auth: {
userIds: ['fL6pirusvokposvwX', 'P4DNubMrEQsEQvNX2', 'AN3xqZHaQNmJ4nghe', 'v9XWPKQ7BapnNGY2F']
}
});
But when i run in the terminal, only a time stamp is printed timestamp
or some times an error occurs even though I dont change the test file
error

In Meteor how can I load the page links without subscribing to all the page content?

I want to load all the links to my pages. What I did it, created a seperate subscription with only the slug and title fields. Used this data in my navigation and it worked. But now I need to subscribe on every single page with all the fields. The problem is, it's showing only the slug and title fields. I think the two subscriptions are conflicting. Here's my subscriptions :
Meteor.publish("pageLinks", function() {
return Pages.find({}, {
fields: {
title: 1,
slug: 1
}
});
});
Meteor.publish("page", function(slug) {
check(slug, String);
return Pages.findOne({
slug: slug
});
});
And my subscriptions in the route for the single page :
FlowRouter.route('/page/:slug', {
name: 'pageSingle',
subscriptions: function(params, queryParams) {
this.register('page', Meteor.subscribe('page', params.slug));
},
action() {
BlazeLayout.render('panelLayout', {
content: 'pageSingle'
});
setTitle('Page');
}
});
For the links, I subscribed in the template like this :
Template.panelLinks.onCreated(function() {
this.autorun(function() {
Meteor.subscribe('pageLinks');
});
});
Template.panelLinks.helpers({
pageLinks: function() {
return Pages.find({});
}
});
Here's how I display the links :
{{#each pageLinks}}
{{> pageLink}}
{{/each}}
What is the best way to solve this conflict and load all the fields of a page only in that page's route?
First, there is mistake in your publish function:
Meteor.publish("page", function(slug) {
check(slug, String);
return Pages.findOne({
slug: slug
});
});
You should see in console error :
Error: Publish function can only return a Cursor or an array of Cursors
Replace Pages.findOne with Pages.find
If you correct mistake then you should be able to use different subscriptions of the same collection (Pages) and receive correct data.

Meteor SimpleSchema with user dropdown

I have an app in Meteor and the idea is that an admin user can add a document and assign it to one of its customers (customers are stored in the user collection). So I would like to present a dropdownbox with customers on the document insert view. The relevant code of the schema is below:
customer: {
type: [String],
label: "Customers",
allowedValues: function () {
return Meteor.users.find().map(function (user) {
return user._id
});
},
autoform: {
options: function () {
return Meteor.users.find({}).map(function(user) {
return {
value: user._id,
label: user.profile.name
}
})
}
},
optional: true
}
When I put a type: String (instead of [String]) it shows the current user only in a dropdownbox. If I use [String] (as it should be), the dropdownbox actually turns in a text box (it does not have the typical dropdown behaviour) with 3 fields (for all the users it found), yet it only shows the first one again but leaves placeholders for the other 2.
The view uses:
{{> afQuickField name='customer'}}
IMPORTANT: The account package, by default doest not publish the users collection. You will have to write a new publication method in your server and corresponding subscription in your client for this to work.
No read on..
Well.. This is a bit tricky. Look at the code below and edit your 'autoform' section accordingly.
autoform: {
options: function () {
var options = [];
Meteor.users.find().forEach(function (element) {
options.push({
label: element.profile.name, value: element._id
})
});
return options;
}
}
the required syntax for selection box 'options' is:
options:{[label,value],...}
The above code reads all the rows from the user collection, and pushes each row to an array called 'options' as an array.
Hope this helps or gives you some insights.
Please note that the above only works if your collection subscription/publication are proper.
Look at the following code to get a simple idea.
if (Meteor.isClient) {
Meteor.subscribe('allUsers')
}
if (Meteor.isServer) {
Meteor.publish('allUsers', function() {
return Meteor.users.find({}, {fields:{username:1,emails:1}})
})
}

Ext JS 4 direct store how to *prevent* loading mask?

I have found many references on how to create a 'loading' message or mask when loading data in to a grid in Ext JS 4 via a data store / proxy (I am using direct type).
So I had added this in my controller at one point (because I was NOT getting a loading message previously) :
init: function() {
var store = this.getEncountersStore();
store.on({
beforeload: function(store,operation,eopts) {
Ext.getBody().mask('Loading...');
},
load: function(store,records,success,operation,eopts) {
Ext.getBody().unmask();
}
});
}
That seems to work for me in my MVC application, however, next I added a task manager timer to automatically refresh the grid data every 10 seconds:
this.runningTask = Ext.TaskManager.start ({
run: this.loadEncounterData,
interval: 10000,
scope: this
});
loadEncounterData: function() {
var store = this.getEncountersStore();
store.load({
params: {
},
callback: function(r,options,success) {
if(success == true)
...
} //callback
}); //store.load
I noticed that there were now TWO 'loading' mask messages on the screen!
So, I removed my 'store.on' code block above from my controller init, and now I have only one message.
So where does the other message come from?
Is it part of a Grid?:
Ext.define('ESDB.view.encounter.List', {
extend: 'Ext.grid.Panel',
...
I found a page that seems to asking the same question, though I was not able to figure out how to get it to work, or how to do it according to ExtJS 4 / MVC.
loadMask is not a config in Grid panel.
You can add as a config in gridpanel
viewConfig : {
loadMask: false
}
The loadMask is part of the gridView.
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.View-cfg-loadMask
GridPanel components all have a gridView component that defines various things to do with the table view in the panel.
To prevent a loadMask on a grid, you set config for loadMask to false, IE:
Ext.define('ESDB.view.encounter.List', {
extend: 'Ext.grid.Panel',
loadMask : false,
...
You could change your load function to just load the store:
loadEncounterData: function() {
var store = this.getEncountersStore();
store.load();
...
Then you could use the following approach to automatically handle the loadMask whenever the grid store loads.
Using Ext.util.DelayedTask is handy to prevent the loadMask from appearing if the load takes less than 500ms.
Ext.define('ESDB.view.encounter.List', {
extend: 'Ext.grid.Panel',
...
initComponent: function() {
var me = this;
me._mask = new Ext.LoadMask(me, {msg: 'Loading...'});
me._maskd = new Ext.util.DelayedTask(function() {
me._mask.show();
});
me.store = Ext.create('Ext.data.Store', {
...
listeners: {
beforeload: function() {
me._maskd.delay(500);
...
},
load: function() {
me._maskd.cancel();
me._mask.hide();
...
}
}
});
...

Resources