gotoDate() not functioning - fullcalendar

I'm struggling to understand how to implement gotoDate properly. The documentation specifies a string based command structure (like so: .fullCalendar( 'gotoDate', date )), but does not specify an appropriate approach when the constructor contains variable flags. This is my current approach:
$('#eventCalendar').fullCalendar({
height: "parent"
});
Simply adding .gotoDate(date) to the end of this structure does not yield any result at all. Do I need to remove the height flag in order to achieve this?
Notes:
* date is a moment as specified
* Height is specified by an external div element
* The date is supplied by a C# backend in the format yyyy-MM-dd

$('#eventCalendar').fullCalendar({
height: "parent"
});
(or similar, with whatever options you decide to use) initialises the calendar.
Then, after that you can call methods on it, e.g.
$('#eventCalendar').fullCalendar("gotoDate", date);
Calling a method requires a separate command, you can't do it in the same command as where you set the initial options.
N.B. It's not entirely clear if this is your intention, but if you just want to set the date which the calendar first starts, you can set the "defaultDate" option during initialisation:
$('#eventCalendar').fullCalendar({
height: "parent",
defaultDate: date
});

Related

Is there a way to test events from the test fixture directly without using expectEvents?

Im trying to test an Aggregate and would like to assert the events outside of the fixture and perhaps even use Hamcrest to evaluate?
An example of using timestamps
fixture.given()
.when(new UserCreateCommand("1","test#bob.com"))
.expectEvents(new UserCreatedEvent("1","test#bob.com");
The fixture allows me to easily test equality, e.g. the command produces exactly this event, its not so easy if I wanted to say introduce a Timestamp of when the event was created for example
fixture.given()
.when(new UserCreateCommand("1","test#bob.com"))
.expectEvents(new UserCreatedEvent("1","test#bob.com", LocalDateTime.now());
This expectation will never work as the LocalDateTime.now() will never be precisely equal to the timestamp generated in the aggregate.
I could simply include the Timestamp in the command payload, but feel a preference to handle inside the Aggregate to ensure a consistent way of generating this timestamps.
Is there a way to retrieve the Event out of the fixture to assert independently of the fixture e.g.
UserCreatedEvent uce = fixture.given()
.when(new UserCreateCommand("1","test#bob.com"))
.extractEvent(UserCreatedEvent.class)
This would then allow me to use other assertion libraries also like hamcrest for example:
e.g.
assertThat(uce.getCreatedAt(), is(greaterThanOrEqualto(LocalDateTime.now().minusSeconds(1);
Reasonable question #vcetinick!
You should actually be able to use matchers with Axon's Aggregate Test Fixtures really. The result validation part of the AggregateTestFixture provides the expectEventsMatching(Matcher<? extends List<? super EventMessage<?>>> matcher) method. You can find the code for this here by the way.
On top of this Axon Framework provides a set of reasonable matchers you can use for messages in general, grouped under the utility class Matchers (which you can find here).
With all this in place, you should be able to do something like this:
#Test
void sampleTest() {
FixtureConfiguration<SampleAggregate> fixture =
new AggregateTestFixture<>(SampleAggregate.class);
fixture.givenNoPriorActivity()
.when(new UserCreateCommand("1","test#bob.com"))
.expectEventsMatching(
Matchers.exactSequenceOf(
Matchers.messageWithPayload(
Matchers.matches(payload -> {
// Your UserCreatedEvent validation
// disregarding the time stamp here
})
)
)
);
}
You can essentially pair any number of Matchers methods in their if you desire.
Hoping this answers your question #vcetinick!
Despite being an old post, for those stumbling upon the same issue, an alternative approach can be used by using
fixture = new AggregateTestFixture<>(YourAggregate.class);
fixture.registerFieldFilter(new IgnoreField(YourEvent.class, "date"));
In this example, YourEvent could be an event implementation class of a base class for all events containing a timestamp field date.
#NotNull(message = "The event date cannot be null")
#Past(message = "The event date cannot be in the future")
#JsonProperty(value = EVENT_DATE_TAG, required = true)
private ZonedDateTime date;
Using this approach, all calls to expectXXXX test-methods ignore the date field.

Google Tag Manager - Parse Dynamic Data Layer Variable

I want to parse a 'pushed' data layer string. I intend to use it to track click events and setup the appropiate funnels in Google Analytics, it looks as follows: products.view.19|view recent product|19
The first part (products.view.19) is the unique page identifier.
The second part (view recent product) is the action.
The last part is (19) is the action identifier, this way actions may be grouped and compared more easily.
So I did the following, I first created a trigger (it fires when a link has the tag 'data-trackclick' in it) which pushes the data value to a variable (variable for datalayer). However, now I want to split that variable in to 3 new variables, as described above. I selected 'javascript macro' for this but somehow it returns 'undefined'. The macro looks as follows:
function() {
var data = {{TrackClickData}};
var pieces = data.split('|');
if (pieces[0].length()) {
return pieces[0];
} else {
return data;
}
}
Obviously this didnt work since it would only run on the initial load and not (like I thought) when the macro was requested, so it should somehow be fired on the 'click' and then set the variables accordingly.
Is this possible to do? Or do I really have to add the dataLayer.push() in script tags?
A few things:
.length() is wrong, the property for array length is .length without the ()
if it exists, pieces[0] is not an array, then .length would return the string length, see How do you check for an empty string in JavaScript? for more standard way of checking for empty strings
Is this possible to do? There's virtually nothing you can't do with GTM, since you can write JavaScript code, you can do whathever you code allows you to do, and splitting a string to use parts of it as variables is certainly within the realm of possibilities.
My advise is to make your code work outside GTM first (eg test it in the browser console), then once it's all working, port it to GTM.

Update shiny input from java script

I've looked around and tried a few things but I can't seem to get it to work. I want to be able to update the value stored in input$someVar from a bit of js code. What I need to on a certain element click, I need to update the input$someVar value. I know there are functions like "updateSelectInput()" but those are called from the server.
I can physically change the value of the data in the HTML that is used int he data attribute and that is displayed, but the server doesnt see this as a change and the input$someVar stays the same.
I have tried
var selectBind = Shiny.inputBindings.bindings[5];
selectBind.binding.setValue('#loc', newValue);
within an event handler, where #loc is the id of the input element, in hope that I could do it that way but this gives me an error.
Is there a way to do the functionality of "updateSelectInput()" within java script in the ui?
Yes, there is a way. Use the JavaScript function Shiny.onInputChange.
// change the value of an input
document.getElementById("id").value = "value";
// report the change to shiny
Shiny.onInputChange("id", "value");

Two Way Binding an Input with RactiveJs

I'm just starting out with RactiveJs and having a few troubles with observing an input tag, which is initially rendered with a value.
I'm observing a the input field below.
{{#invoices:i}}
<input class="text-center" type="date"" value="{{***date_modified***}}">
{{/invoices}}
Using the below
ractive.observe({
'*.*.date_modified': function(newValue, ***oldValue***, keyPath) {
// some function
};
});
The challenge is the first time "date_modified" is the changed "oldValue" is undefined. The second time "date_modified" is changed "oldValue" correctly returns the old value.
The "date_modified" is initially rendered with a value (e.g., 22/11/2014), which I suspect might be the issue as all of the examples leave the input blank when the template I
Any thoughts?
Thanks
By default, observers 'initialise' with an undefined oldValue - the idea is that it's often easier to write a single function that does something with the current state of the app, regardless of how that state came to be, rather than some initial setup logic plus a separate change handler of some kind.
But you can disable that first call by passing an init: false option, like so:
ractive.observe('foo', handler, { init: false });
However there's a bit more to it than that in this case. It turns out you've uncovered a bug - pattern observers can't have a * as the first key. You'd need to use invoices.*.date_modified instead of *.*.date_modified. An issue has been raised on GitHub - thanks!

How to add a property to a map dynamically in velocity?

I have the following code
$pageName = "test";
$Container = {};
I like to set a property of $Container by a variable. I tried $Container.set("test", $pageName);. It didn't raise any errors, but $Container.test or $Container.get("test"); display nothing.
How do I fix it?
The problem is that set is the wrong method. You need to do a put. Remember - Velocity is calling the Java methods. There is no "set" method on a Map object.
Specifically, you can do
$Container.put("test", $pageName)
Now, one weird thing is that this will print "true" or "false" in the page, since the Map.put() method returns a boolean. So I always do
#set($dummy = $Container.put("test", $pageName))
which does the put and stores the result in another reference (which you can then ignore) instead of rendering it to the page.
Hey I ran into the same problem is the "true" or "false" printed on the page, and there is a simpler way to handle it. What I did is a little weird, and I did it Confluence, which of course uses Velocity under the covers. I mention that because I understand Velocity can be used in may different applications.
With a Confluence user macro, I check for a previously created attribute on the req variable, the request variable, i.e. "myPageVars". Then I use the put method to put a new key-value pair, based on the macro parameters. By using the $! prefix, rather than just $, the output isn't sent to the screen.
...
$!req.getAttribute("myPageVars").put( $paramKey, $paramValue )
...
I'm somewhat new to Velocity, so I can't guarantee this will work in every context, but it seems syntactically easier than the whole #set ($dummy etc. line.

Resources