I have a a few views: mobilepage1, mobilepage2, mobilepage3, mobilepage4 en 5.
First you go to mobilepage1 then hit button "next" and go to mobilepage2 etc.
In mobilepage2 i have a form where the user has to select a few options. Then a controller does a calculation and some variables are shared:
View::share('waarschijnlijkheid',$waarschijnlijkheid);
View::share('effect',$effect);
View::share('blootstellingsfreq',$blootstellingsfreq);
View::share('risico',$risico);
In mobilepage3 then these variables are displayed and that is done correctly.
After that you get mobilepage 4 and 5. In mobilepage5 i also want to show the same variables again. I get the error:
{"error":{"type":"ErrorException","message":"Undefined variable: waarschijnlijkheid (View: C:\\Google Drive\\htdocs\\laravel4_test4\\app\\views\\mobilepages\\mobilepage5.blade.php)","file":"C:\\Google Drive\\htdocs\\laravel4_test4\\app\\storage\\views\\49e12d376740da5fc90b17627351022b","line":25}}
I read here: Laravel 4 - understanding View::share()
that shared variables are accessable troughout the whole application. So why not in my final mobilepage5? Just to test this i made both views exactly the same.
This is the mobilepage5 and 3 snippet.
<td>{{$effect}}</td>
<td>x</td>
<td>{{$blootstellingsfreq}}</td>
<td>x</td>
<td>{{$waarschijnlijkheid}}</td>
<td>=</td>
<td>{{$risico}}</td>
<td>{{ '->'}}</td>
<td>{{$risicoklasse}}</td>
This is my route file:
Route::get('/', function(){
return View::make('mobilepages.login');
});
Route::post('login','MobileController#login');
Route::get('gotomobilepage1', function()
{
return View::make('mobilepages.mobilepage1', array('errormessages' => 'no messages'));
});
Route::get('mobilepage2', 'MobileController#save_firstpageform');
Route::post('gotomobilepage3', 'MobileController#save_andcalculaterisc');
Route::post('gotomobilepage4', function(){
return View::make('mobilepages.mobilepage4');
});
Route::post('gotomobilepage5', 'MobileController#gotomobilepage5function');
In my "save_andcalculaterisc" function calculate i share the variables.
public function save_andcalculaterisc()
{
$input = Input::all();
$waarschijnlijkheid = $input['radio_waarschijnlijkheid'];
$blootstellingsfreq = $input['radio_blootstellingsfreq'];
$effect = $input['radio_effect'];
$risico = $blootstellingsfreq*$effect*$waarschijnlijkheid;
View::share('waarschijnlijkheid',$waarschijnlijkheid);
View::share('effect',$effect);
View::share('blootstellingsfreq',$blootstellingsfreq);
View::share('risico',$risico);
//$safetyreport = Users::find(1)->safetyreports;
if($risico<=20){
$risicoklasse = "Risico wellicht aanvaardbaar: Aandacht dagelijks overleg";
} else if ($risico>20 && $risico <= 70){
$risicoklasse = "Mogelijk risico: Aandacht vereist";
} else if ($risico>70 && $risico <= 200) {
$risicoklasse = "Belangrijk risico: Maatregelen vereist";
}else if ($risico>200 && $risico <= 400) {
$risicoklasse = "Hoog risico: Direct verbetering vereist";
}else if ($risico >= 400) {
$risicoklasse = "Zeer hoog risico: Werkzaamheden stoppen";
}
else {
$risicoklasse = "Error risicoklasse";
}
View::share('risicoklasse',$risicoklasse);
// }
return View::make('mobilepages.mobilepage3');
}
Change this
View::share('waarschijnlijkheid',$waarschijnlijkheid);
View::share('effect',$effect);
View::share('blootstellingsfreq',$blootstellingsfreq);
View::share('risico',$risico);
To:
View::share(array('risico' => $risico, 'waarschijnlijkheid' => $waarschijnlijkheid, 'effect' => $effect, 'blootstellingsfreq' => $blootstellingsfreq ));
I think the issue is that you're using , instead of =>
Related
I have this in my template
And this is my class component
ngOnInit(): void {
this.route.queryParamMap
.pipe(
concatMap(
params => {
this.añoUrl = Number(params.get('year'));
this.mesUrl = Number(params.get('mes'));
return this.generalService.getFestivosMes('leioa', this.añoUrl, this.mesUrl)
}
)
)
.subscribe(festivos => {
this.festivos = festivos;
}
)
}
colorColumna(columna: string): string {
var dia = new Date(this.añoUrl, this.mesUrl - 1, +columna.slice(1));
if (columna.slice(0, 1) == 'S' || columna.slice(0, 1) == 'D') {
return 'red'
}
if (this.festivos.find(f => new Date(f.fecha) == dia)) {
return 'red';
}
return 'green';
}
The problem is that when the function colorColumn() is executed this.festivos is empty.
But when the component is finished loading I have this.festivos
I don't know at what point in the component's life cycle I can access the service in order to have the return values available when the angular material table is rendered.
Any idea, please?
Thanks
I noticed the below happen upon the execution of my call of the sever, what is the wrong thing here!
getItems(){
print('getItems');
request = new HttpRequest();
request.onReadyStateChange.listen(onData_getItems);
request.open('POST', host+'/getItems');
request.send(' ');
}
onData_getItems(_){
print('call'); // --> printed 4 times!!
if (request.readyState == HttpRequest.DONE && request.status == 200) {
print('Data loaded successfully..';
print(request.responseText); // --> printed 1 time!!
for(Map item in JSON.decode(request.responseText)){
LineItem..children.add(new OptionElement(value: item['Code'], data: item['Name']));
}
}
else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
print("could not connect to server, contact your admin");
}
else print('something else'); // --> printed 3 times
}
the above is executed in my custom element:
class getPurchaseLines extends HtmlElement {
static final tag = 'get-POlines';
factory getPurchaseLines() => new Element.tag(tag);
var shadow, LineItem, LineQty, Lineprice, clsBtn;
getPurchaseLines.created() : super.created() {
shadow = this.createShadowRoot();
LineItem = new SelectElement()
..children.add(new OptionElement(value: '0', data:'Stock Code'));
LineQty = new InputElement()..type='number'..placeholder='Qty'..style.width='50px';
Lineprice = new InputElement()..type='number'..placeholder='price'..style.width='50px';
LineQty.onKeyUp.listen((e){if(LineQty.checkValidity() == false)LineQty.value='0';});
Lineprice.onKeyUp.listen((e){if(Lineprice.checkValidity() == false)Lineprice.value='0';});
shadow.host
..style.position='relative'
..style.display='inline-block'
..style.verticalAlign = 'top'
..style.backgroundColor = '#ffffff'
..style.boxShadow = '1px 1px 5px #333333'
..style.boxSizing = 'border-box'
..style.marginTop='2px'
..style.padding = '4px'
..style.paddingRight='30px'
..style.borderRadius='2px'
..style.fontSize='14px'
..style.transition = 'all 0.2s ease-in';
clsBtn
..onClick.listen((e)=> this.remove())
..style.position='absolute'
..style.right = '5px'
..style.top = '5px'
..style.color = 'black'
..style.cursor = 'pointer'
..style.zIndex = '1'
..style.fontSize = '16px'
..style.fontWeight = 'solid'
..classes.add('ion-close-circled')
..text='x'
;
shadow.nodes..add(LineItem)..add(LineQty)..add(Lineprice)..add(clsBtn);
}
which is called in my function as below:
Future fonixFuture() => new Future.value(true);
for (var line in orderLines){
fonixFuture()
.then((_)=> LineDisplay = new getPurchaseLines())
.then((_)=> LineDisplay.getItems())
.then((_)=> this.parent.nodes.add(LineDisplay))
.then((_)=>print(this.parent.nodes));
}
and only the last element (LineDisplay) shows the correct getItem() results. for example if I've 4 lines, the LineDisplay is:
printed "call" 16 times in the counsle
display the element LineDisplay 4 times in the browser
the items field in the first 3 'LineDisplay' is null, while the last one shows the items executed correctly.
Attached illustration of the issue.
Update
After receiving answer, the 4 responses issue had been fixed, but still the output received in the last element only! the updated code is:
return Future.forEach(orderLines, (ol) {
return fonixFuture()
.then((_)=>print(ol))
.then((_)=> LineDisplay = new getPurchaseLines())
.then((_)=> LineDisplay..getItems())
.then((_)=> this.parent.nodes.add(LineDisplay))
.then((_)=>print(this.parent.nodes));
});
the custom element is:
part of fonix_client_library;
class getPurchaseLines extends HtmlElement {
static final tag = 'get-POlines';
factory getPurchaseLines() => new Element.tag(tag);
var shadow, LineItem, LineQty, Lineprice;
getPurchaseLines.created() : super.created() {
shadow = this.createShadowRoot();
LineItem = new SelectElement()
..children.add(new OptionElement(value: '0', data:'Stock Code'));
LineQty = new InputElement()..type='number'..placeholder='Qty'..style.width='50px';
Lineprice = new InputElement()..type='number'..placeholder='price'..style.width='50px';
LineQty.onKeyUp.listen((e){if(LineQty.checkValidity() == false)LineQty.value='0';});
Lineprice.onKeyUp.listen((e){if(Lineprice.checkValidity() == false)Lineprice.value='0';});
shadow.host
..style.position='relative'
..style.display='inline-block'
..style.verticalAlign = 'top'
..style.backgroundColor = '#ffffff'
..style.boxShadow = '1px 1px 5px #333333'
..style.boxSizing = 'border-box'
..style.marginTop='2px'
..style.padding = '4px'
..style.paddingRight='30px'
..style.borderRadius='2px'
..style.fontSize='14px'
..style.transition = 'all 0.2s ease-in';
shadow.nodes..add(LineItem)..add(LineQty)..add(Lineprice);
}
getItems(){
print('getItems');
request = new HttpRequest();
request.onReadyStateChange.listen(onData_getItems);
request.open('POST', host+'/getItems');
request.send(' ');
}
onData_getItems(_){
if (request.readyState != HttpRequest.DONE) return;
else
print('responce recieved..: ${request.responseText}');
if (request.readyState == HttpRequest.DONE && request.status == 200) {
fonixFooter.innerHtml='Items retreived..';
print('responce after checking ifItemsretrieved..: ${request.responseText}');
for(Map item in JSON.decode(request.responseText)){
LineItem..children.add(new OptionElement(value: item['Code'], data: item['Name']));
}
}
else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
print('no server..');
}
}
}
the second screen shoots shows the updated output
You listen to a stream, there it is expected to get more than one event.
http://www.w3schools.com/jsref/prop_doc_readystate.asp says
This property returns one of four values:
uninitialized - Has not started loading yet
loading - Is loading
interactive - Has loaded enough and the user can interact with it
complete - Fully loaded
If you are not interested in uninitialized, loading, interactive you can just check
onData_getItems(_){
if (request.readyState != HttpRequest.DONE) return;
print('call'); // --> printed 1 time
Update (2nd issue)
Executing async functions in a forEach doesn't work as you probably expect
instead of
for (var line in orderLines){
use
return Future.forEach(orderlines, (ol) {
return fonixFuture()
.then((_)=> LineDisplay = new getPurchaseLines())
.then((_)=> LineDisplay.getItems())
.then((_)=> this.parent.nodes.add(LineDisplay))
.then((_)=>print(this.parent.nodes));
});
It looks a bit weird that you artifically introduce async execution without an obvious reason
Future fonixFuture() => new Future.value(true);
therefore it's hard for me to tell how to integrate the above code snippet in your app code.
I suggest you create a new question if issues remain.
Update
return Future.forEach(orderLines, (ol) {
print(ol);
LineDisplay = new getPurchaseLines();
return LineDisplay.getItems()
.then((success) {
if(success) {
parent.nodes.add(LineDisplay);
print(this.parent.nodes);
} else {
print('getItems() failed!');
} // <== added
});
});
Future getItems(){
print('getItems');
request = new HttpRequest();
Completer completer = new Completer();
request.onReadyStateChange.listen((_) => onData_getItems(completer)); // <== changed
request.open('POST', host+'/getItems');
request.send(' ');
return completer.future;
}
onData_getItems(Completer completer) {
if (request.readyState != HttpRequest.DONE) {
return;
} else {
print('responce recieved..: ${request.responseText}');
}
if (request.status == 200) {
fonixFooter.innerHtml='Items retreived..';
print('responce after checking ifItemsretrieved..: ${request.responseText}');
for(Map item in JSON.decode(request.responseText)){
LineItem..children.add(new OptionElement(value: item['Code'], data: item['Name']));
}
completer.complete(true);
} else if (request.readyState == HttpRequest.DONE && request.status == 0) {
print('no server..');
completer.complete(false);
// or completer.completeError('failed');
}
}
Below is my method of searching using predicate builder there is no error showing in visual studio but the problem is that the below code is not executing.
public JsonResult GetSearchedGraph(string searchItem, string itemTypeEnum)
{
var pre = PredicateBuilder.True<Graph>();
pre.And(m => m.isHidden == false && m.ItemType!="FOLDER");
if (!String.IsNullOrEmpty(searchItem))
{
pre.And(m => m.GraphItemTitle.ToUpper().Contains(searchItem.ToUpper()));
}
if (!String.IsNullOrEmpty(itemTypeEnum))
{
pre.And(m => m.ItemType == itemTypeEnum);
}
var searchGraph = from m in db.Graphs.AsQueryable() select m;
searchGraph = db.Graphs.Where(pre);
return Json(searchGraph.ToList(), JsonRequestBehavior.AllowGet);
}
I am not getting any search result by using this method what it is wrong with this code?
well, you just have to do correct assignments.
because pre.And() doesn't impact pre
var pre = PredicateBuilder.True<Graph>();
//assign result of pre.And(xxx) to pre
pre = pre.And(m => m.isHidden == false && m.ItemType!="FOLDER");
if (!String.IsNullOrEmpty(searchItem))
{
//same
pre = pre.And(m => m.GraphItemTitle.ToUpper().Contains(searchItem.ToUpper()));
}
if (!String.IsNullOrEmpty(itemTypeEnum))
{
//same
pre = pre.And(m => m.ItemType == itemTypeEnum);
}
I am trying to do a simple CRUD app using Ember + Rails and I'm getting the following error when trying to go to the /workouts route.
Error while loading route: TypeError {} ember.js?body=1:415
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = meta(this), proto = m.proto;
m.proto = this;
if (initMixins) {
// capture locally so we can clear the closed over variable
var mixins = initMixins;
initMixins = null;
this.reopen.apply(this, mixins);
}
if (initProperties) {
// capture locally so we can clear the closed over variable
var props = initProperties;
initProperties = null;
var concatenatedProperties = this.concatenatedProperties;
for (var i = 0, l = props.length; i < l; i++) {
var properties = props[i];
Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));
for (var keyName in properties) {
if (!properties.hasOwnProperty(keyName)) { continue; }
var value = properties[keyName],
IS_BINDING = Ember.IS_BINDING;
if (IS_BINDING.test(keyName)) {
var bindings = m.bindings;
if (!bindings) {
bindings = m.bindings = {};
} else if (!m.hasOwnProperty('bindings')) {
bindings = m.bindings = o_create(m.bindings);
}
bindings[keyName] = value;
}
var desc = m.descs[keyName];
Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));
Ember.assert("`actions` must be provided at extend time, not at create time, when Ember.ActionHandler is used (i.e. views, controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this)));
if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
var baseValue = this[keyName];
if (baseValue) {
if ('function' === typeof baseValue.concat) {
value = baseValue.concat(value);
} else {
value = Ember.makeArray(baseValue).concat(value);
}
} else {
value = Ember.makeArray(value);
}
}
if (desc) {
desc.set(this, keyName, value);
} else {
if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
this.setUnknownProperty(keyName, value);
} else if (MANDATORY_SETTER) {
Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
} else {
this[keyName] = value;
}
}
}
}
}
finishPartial(this, m);
this.init.apply(this, arguments);
m.proto = proto;
finishChains(this);
sendEvent(this, "init");
} has no method 'find'
My code is located here: https://github.com/ecl1pse/ember-workouts
What am I doing wrong?
Edit: Upon further investigation I believe the culprit is
EmberWorkouts.WorkoutsRoute = Ember.Route.extend(
model: -> EmberWorkouts.Workout.find()
This doesn't actually return anything. How do I debug from there?
If I replace that with this
EmberWorkouts.WorkoutsRoute = Ember.Route.extend
model: -> [{title: 'hi'}, {title: 'damn'}]
The view actually renders content.
How do I get the model to collect from Rails properly?
Ember Data's interface has changed a little with the current release:
You can clear out the store.js file entirely. Ember Data will automatically set up a data store for you using the REST Adapter (unless you tell it otherwise).
Use model: -> #store.find('workout') instead.
I tested this with your app and it works.
If you haven't read through the Ember Data Guide in the last week or two (it's changed a lot), I would spend a few minutes on it.
The fix for this error (as of ember-data 1.0.0.beta.6) for me was to make sure that the JSON returned from the server included an "id" field for each model, BUT not to explicitly declare the id when setting up the Ember DS.Model.
jbuilder template:
json.scans do
json.array! #scans do |scan|
json.id scan.id # This prop has to be there
json.name scan.name
end
end
Ember model:
EmberApp.Scan = DS.Model.extend(
// Don't include the id prop here
name: DS.attr("string")
)
I'm hoping to get a little bit of insight on show / hide functionality in gmaps4rails.
example functionality
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(true);
}
}
// == check the checkbox ==
document.getElementById(category+"box").checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].mycategory == category) {
gmarkers[i].setVisible(false);
}
}
// == clear the checkbox ==
document.getElementById(category+"box").checked = false;
// == close the info window, in case its open on a marker that we just hid
infowindow.close();
}
// == a checkbox has been clicked ==
function boxclick(box,category) {
if (box.checked) {
show(category);
} else {
hide(category);
}
// == rebuild the side bar
makeSidebar();
}
function myclick(i) {
google.maps.event.trigger(gmarkers[i],"click");
}
// == rebuilds the sidebar to match the markers currently displayed ==
function makeSidebar() {
var html = "";
for (var i=0; i<gmarkers.length; i++) {
if (gmarkers[i].getVisible()) {
html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>';
}
}
document.getElementById("side_bar").innerHTML = html;
}
So, in my controller, I'm building a list of markers, and including their categories as json.
#markersLoc = #locSearch.to_gmaps4rails do |loc, marker|
letter.next!
marker_image = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{letter}|82ABDD|000000"
marker.infowindow render_to_string(partial: '/events/info',
locals: {object: loc})
marker.picture({picture: marker_image,
width: 32,
height: 32,
marker_anchor: [11,30],
shadow_picture: "http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
shadow_width: 110,
shadow_height: 110,
shadow_anchor: [12,34]})
marker.title loc.what
marker.sidebar render_to_string(partial: '/events/sidebar',
locals: {object: loc, letter: marker_image})
marker.json({cat: loc.category})
end
I'm kind of stuck, here. I know the :cat string is available (ex: 1,3,4), but I'm not sure how to use it to achieve what I'm after.
Was able to pretty much use what was there, with some modification. This gave me functionality to have 9 categories (could be more or less), and only view what I want. Awesome.
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(category) {
var regEx = new RegExp("[" + category + "]")
for (var i=0; i<Gmaps.map.markers.length; i++) {
if (Gmaps.map.markers[i].cat) {
if (Gmaps.map.markers[i].cat.match(regEx)) {
Gmaps.map.showMarker(Gmaps.map.markers[i]);
}
}
}
// == check the checkbox ==
document.getElementById(category+"box").checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(category) {
var regEx = new RegExp("[" + category + "]")
for (var i=0; i<Gmaps.map.markers.length; i++) {
if (Gmaps.map.markers[i].cat) {
if (Gmaps.map.markers[i].cat.match(regEx)) {
Gmaps.map.hideMarker(Gmaps.map.markers[i]);
}
}
}
// == clear the checkbox ==
document.getElementById(category+"box").checked = false;
// == close the info window, in case its open on a marker that we just hid
// Gmaps.map.infowindow.close();
}
// == a checkbox has been clicked ==
function boxclick(box,category) {
if (box.checked) {
show(category);
} else {
hide(category);
}
}