arangojs: keepNull not an option for collection.save? - javascript

I'm going through the documentation for arangojs and looking at the function collection.update(), keepNull is one of the options that can be added. https://github.com/arangodb/arangojs/blob/master/docs/Drivers/JS/Reference/Collection/DocumentManipulation.md
When going through the same documentation for the function collection.save() (https://github.com/arangodb/arangojs/blob/master/docs/Drivers/JS/Reference/Collection/DocumentCollection.md) we find no such option. Why? Do I first need to have an original file, then update that one with keepNull: false before I get it to clean up my documents from any null valued keys? Or is this a lack in the documentation? I think it's correct since I haven't managed to set keepNull to false using collection.save myself.

The driver hands the query options over to the server, so this is the relevant documentation to look at:
https://www.arangodb.com/docs/stable/http/document-working-with-documents.html#create-document
The API does not support keepNull as option when creating a document. It is only available for UPDATE/REPLACE queries to mark attributes for removal. So it's up to you to do this on the client-side. You may open a feature request nonetheless.
BTW. In AQL, UPDATE doc WITH {} OPTIONS { keepNull: false } will not remove any attributes with a null value! It only removes attributes you set explicitly to null in the WITH {} part. This may apply to the driver as well.

Related

Event Object property "source" returns [object Object]

I would like to render events differently based on the source of the Event Object, but even though the fullcalendar documentation states
source "Event Source Object. Automatically populated. A reference to
the event source that this event came from."
I am unable to query the "source" property of the Event Object.
console.log(event.source); results in [object Object]
I am using multiple Google Calendar eventSources, but nothing in the documentation seems to indicate that I shouldn't be able to do this.
I initially planned to render events based on filtered eventSources (triggered by a custom button which invokes a modal containing checkboxes), but I spent way to long reading up docs, code samples and numerous suggestions before I finally decided to throw in the towel on this idea. In the end I removed all eventSources using 'removeEventSources' before adding each source one by one using 'addEventSource' (depending on what filter options are selected).
It seems that there is no built in mechanism or straight forward functionality to filter eventSources (especially Google Calendars) and I suspect the ability to query the "sources" property of the Event Object would allow us a different approach to accomplish such functionality and improve load times.
Other use case example:
If want to determine the "source" at eventClick or render to decide whether to use certain fields e.g.
if event source == Holiday Cal do not display event.start & event.end
or
if source == eventSource1 use Modal1 else use Modal2
etc
So my question is:
Does anyone know why I cannot query the "source" property of the Event Object as documented in the following link?
https://fullcalendar.io/docs/event-object
Fullcalendar documentation screen shot:
The message you're seeing tells you that event.source is an Object, so console.log() won't show you much. But console.dir() will, including:
...
calendar: t {loadingLevel: 0, ignoreUpdateViewSize: 0, freezeContentHeightDepth: 0, el: w.fn.init(1), viewsByType: {…}, …}
className: ["TestCase"]
googleCalendarId: "e0kujgeepc0ev00eojborllms8#group.calendar.google.com"
... etc
You can use any of those properties to test which source you're looking at, for eg (not sure why className is an array but that's not relevant to this problem):
$target = (event.source.className[0] === 'HolidaysUK') ? $modal1 : $modal2;
Here's a much simplified Codepen which opens your events on click in different modals, depending on source, which is what I understand is one of the things you are trying to do.
Side note - you'll make it much easier for ppl to help if you try to create a minimal, complete, and verifiable example of your problem. Your Codepen includes loads of stuff entirely unrelated to the problem, which we have to wade through and evaluate and discard while looking at the problem.

.deny Meteor use.. can't get it to work

I'm trying to deny a question to be submitted if it has a length of 0. But I don't quite understand Meteor deny.
Here's what's going on.
I am updating the question. It is currently set at "yes"
I update it to "yessir"
I console log it as follows:
Questions.deny({
update: function(userId, question) {
console.log(question.question.length);
}
});
but the result is 3. It seems to console log the field being updated, not what I am updating it TO.
This is a problem because how can I check the length of an input if this thing won't check it when it's being submitted.
Can someone enlighten me?
Have a look at the docs and you'll see that the 2nd argument to update is doc:
doc is the current version of the document from the database, without the proposed update
The only way to validate the length of question is to look at the 4th argument - modifier. The problem with this approach is that you must check the modifier for every possible way it could be modified. Fundamentally, this is why allow/deny is really hard to implement in all but the most simple cases.
Instead, I'd strongly suggest either using collection2 to enforce your schema or using methods to modify your documents.
Recommended reading:
Meteor method vs. deny/allow rules
Allow & Deny: A Security Primer
Collection.deny Function either returns true or flase.
If you want to deny update on certain criteria here goes your code like this
Questions.deny({
update: function(userId, question, fields, modifier) {
// check for critera
if(fields.question.length < 0)
return true // denys update for question length less than 0
else
return false // deny = false means allow = true
}
});

Jade : New warning on multiple attributes

I have updated jade to latest version, and started seeing this message in console
You should not have jade tags with multiple attributes
It is mentioned as feature, here
0.33.0 / 2013-07-12
Hugely more powerful error reporting (especially with compileDebug set explicitly to true)
Add a warning for tags with multiple attributes
and I see it in the code.
https://github.com/visionmedia/jade/blob/a38aa552f6f53554ac5605299b6b8c7e07cbdf1f/lib/parser.js#L662
But, what does it really signify. When will I get this warning. For example, when will I get error based on the below code (It works without warning, but to like to know when will I get error so that I can compare with my code)
mixin link(href, name)
a(class=attributes.class, href=href)= name
a(href=href, attributes)= name
+link('/foo', 'foo')(class="btn")
Multiple "attributes" doesn't mean what you probably think it means. It's not an HTML attribute as we know it, but a token of type "attribute".
Example:
a(href="#WAT").some-class(title="WAT")
Note how I have two attribute sections, each with one attribute.
Better put them in one attribute section:
a(href="#WAT", title="WAT").some-class
(I found this question through googleing this warning as one of the first results because I wanted to get rid of it ...)
The accepted answer above did not help me in the following case, but it shows how one can get rid of the warning without loosing the attributes functionality
(it does not provide an answer to why it works this way):
// using mixins similar to +link(param1,param2) above where 'data' and 'class'
// below are not named mixin params
// OK (without a warning):
+link("foo", data="true")(class="bar")
// WARNING is shown:
+link("foo")(class="bar")(data="true")
// ERROR on compiling:
+link("foo", class="bar", data="true")
(I'm sorry to create so much misunderstandings as shown in the comments below and hope my last edit here clarifies it to be a valid, although slightly more general, answer/help for those docpad warnings)

Firefox 5 gives all CSS when running getComputedStyle

Using firefox 5 when i run
window.getComputedStyle(document.getElementsByTagName("img")[0], null);
I get the complete css file, instead of the styles applied onto the "img" tag.
I ran this on https://developer.mozilla.org/en/DOM/window.getComputedStyle
Anyone knows of a workaround?
I know this is an older post, but for anyone landing here.
Basic idea: you need to call the getPropertyValue() method on the object returned by window.getComputedStyle().
See this fiddle: http://jsfiddle.net/zupa/jyyt9/
MDN states you don't need to call document.defaultView.getComputedStyle() but window.getComputedStyle
Note that window.getComputedStyle() returns used values not computed values. (See previous link.)
Compatibility tables: MDN, quirksmode
It should give you an object of type ComputedCSSStyleDeclaration that includes all styles that have been set. This includes all possible styles and not only those styles that have been manipulated by you in some way.
In order to get a specific rule, use for example:
window.getComputedStyle(document.getElementsByTagName("img")[0], null)['borderLeftColor'];
This gives the left border color without distinguishing how the value as specified / calculated.
To get a list of the available entries print the object to Firebug's console:
console.dir(window.getComputedStyle(document.getElementsByTagName("img")[0], null));
Use this :
document.defaultView.getComputedStyle(document.getElementsByTagName("img")[0], "");

Setting the value (selected option) of a dijit.form.Select widget

I have a dijit.form.Select widget. It's tied to a data store, if that matters. It's filled with several options already. All I want to do is programmatically set its value. I can get its value using myWidget.attr('value') but if I try to do myWidget.attr('value', 5) for example (where 5 is one of the valid values), all it does is reset the widget to select the very first option, no matter what value I give it.
This seems to be a bug, and there aren't any tests or documentation which show how to accomplish what I want to. But is there some way, even if it's a dirty hack?
I'm using Dojo 1.4.0. Note that dijit.form.Select is the new name for dojox.form.DropDownSelect.
edit: I even tried resetting the widget with all new options, but it ignores the option which has selected = true and just selects the first option. There must still be a way though.
Even if your values are ints, if you set your integer to a string then this will work.
dijit.byId( 'my_select' ).attr( 'value', String( 5 ) );
Turns out it's a bug - if the option values aren't strings, it won't work (mine were integers).
Repost of my comment:
There is a test page here: dojo archive that you can mess with. Using fire-bug I used dijit.byId('s9').attr('value', 'CO') successfully on that page. That will set the "store-based" Select on that page.
But as you said I set it using a string and you were using integers so I didn't see the bug. Good catch.

Categories

Resources