I'm new to AngularJS, and I've been trying this for a while but really cant solve my problem.
When I was using ui-calendar for Angular, it has the
"TypeError: undefined is not a function"
problem, and the calendar wont even show up.
I solved it by wrapping the scope.calendar to $(scope.calendar) in the calendar.js.
I saw other saying its because the dependency, but when the page is running I can find the js sources in the page like the following:
<script src="/assets/angular.min.js?body=1"></script>
<script src="/assets/fullcalendar.js?body=1"></script>
<script src="/assets/calendar.js?body=1"></script>
<script src="/assets/angular-resource.min.js?body=1"></script>
So is this a problem of dependency or?
The second problem I have is loading events from rails-generated json into my calendar.
$scope.events are events I wrote in javescript, $scope.eventjson are events from json, and only the $scope.events are loading into the calendar
I have this code in my rails controller:
respond_to do |format|
format.json { render :json => {:title=> "event", :start => "2014-04-08 10:00:00" }.to_json }
end
And this is my Angular Controller:
controller('myCtrl', ['$log', '$scope','$q', '$resource', '$http'].concat(function($log, $scope, $q, $resource, $http){
var date, d, m, y, Event;
date = new Date();
d = date.getDate();
m = date.getMonth();
y = date.getFullYear();
Event = $resource("/calendar.json");
$scope.eventjson = Event.get();
$scope.eventjson.$promise.then(function(result){
$scope.eventjson = result;
});
$scope.events = [
{
title: 'All Day Event',
start: "2014-4-10 10:00:00",
allDay: false
}, {
title: 'All Day Event',
start: "2014-4-11 10:00:00",
allDay: false
}
];
$scope.uiConfig = {
calendar: {
height: 350,
editable: true,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
defaultView: 'agendaWeek',
dayClick: $scope.dayClick,
eventDrop: $scope.alertOnDrop,
eventResize: $scope.alertOnResize,
eventClick: $scope.eventClick,
viewRender: $scope.renderView
}
};
$scope.eventSources = [$scope.events] //this one works
//$scope.eventSources = [$scope.events, $scope.eventjson] //got Error: $interpolate:interr
//$scope.eventSources = [$scope.eventjson] //this one shows nothing
}));
And my view:
<div ui-calendar="uiConfig.calendar" ng-model="eventSources">
I personally think its related with angular's promise, but I think that shouldn't be because there is $scope.watch in the calendar.js which means it should be watching $scope.eventSources changes. But when using break points I can see $scope.eventsources are not loading value for $scope.eventSources = [$scope.eventjson].
I've been working on this for two days, really appreciate if someone can give some help.
Related
Goal: display data in calendar on days specified by a datepicker.
Problem: I am unable to assign data to specific dates- all calendar dates display the same data.
The calendar component is rendered by passing a function to its dateCellRender prop which generates the content to be displayed in the cell. The function passed to dateCellRender accepts a moment object as its sole argument, which is generated by the datepicker form. I inspected the Moment object and everything looks good there, i.e. calling moment.date() returns a number.
I tried to mimic the pattern in the documentation, but I keep running into the same issue.
What I'm really confused about is where the filtering is supposed to happen and what's going on behind the scenes. Is dateCellRender being called for every single cell in the calendar and displaying content only when a conditional is met?
Thanks.
The documentation example Calendar displays the list data on 8th, 10th, and 15th of every month. I'm putting it here for convenience. My code is below.
function getListData(value) {
let listData;
switch (value.date()) {
case 8:
listData = [
{ type: 'warning', content: 'This is warning event.' },
{ type: 'normal', content: 'This is usual event.' },
]; break;
case 10:
listData = [
{ type: 'warning', content: 'This is warning event.' },
{ type: 'normal', content: 'This is usual event.' },
{ type: 'error', content: 'This is error event.' },
]; break;
case 15:
listData = [
{ type: 'warning', content: 'This is warning event' },
{ type: 'normal', content: 'This is very long usual event。。....' },
{ type: 'error', content: 'This is error event 1.' },
{ type: 'error', content: 'This is error event 2.' },
{ type: 'error', content: 'This is error event 3.' },
{ type: 'error', content: 'This is error event 4.' },
]; break;
default:
}
return listData || [];
}
function dateCellRender(value) {
const listData = getListData(value);
return (
<ul className="events">
{
listData.map(item => (
<li key={item.content}>
<span className={`event-${item.type}`}>●</span>
{item.content}
</li>
))
}
</ul>
);
}
ReactDOM.render(
<Calendar dateCellRender={dateCellRender} />
, mountNode);
My exploratory code. "test" is displayed on every day of every month when the 3rd is chosen from datepicker.
testDate = () => {
console.log("in testDate", moment.date());
if (moment.date() === 3) {
return "foo";
};
render() {
return <Calendar dateCellRender={this.testDate} />
}
I expect 'foo' to be displayed on the third of every month when moment.date() === 3, but it's displayed instead on every date.
There are no error messages.
I am fighting with the timezone option of fullCalendar plugin. It doesn't matter what I set: none, UTC or a specific location, everything is ignored by the plugin. All given times are shown as UTC+2 (Thats my location). What i do:
First creating some events according following code:
if(!newsCalendarEvent){
var newsCalendarEvent = [];
}
newsCalendarEvent["Event_1"] = {
events: [
{
title: 'my first news',
start: '2015-08-02T17:46:00Z',
end: '2015-08-10T17:46:00Z',
className: 'Event_1'
}
],
color: '',
textColor: ''
}
Then creating the calendar and looping through these events:
newsCalendar = $('#calendar').fullCalendar({
lang: 'de',
buttonIcons: false, // show the prev/next text
weekNumbers: true,
timezone : 'none',
timeFormat: 'H(:mm)'
})
for (var key in newsCalendarEvent) {
if (newsCalendarEvent.hasOwnProperty(key)) {
newsCalendar.fullCalendar( 'addEventSource', newsCalendarEvent[key] )
}
}
Solved. The problem had nothing to do with this plugin. It has been a qustion of timesetting in my php code.
I'm using the gem fullcalendar-rails.
I'm using ajax for the data and a modal for the event input.
After the event modal has added the new record, I use the fullcalendar refectchevents to show the new event on the calendar. This works in every browser I've tested except IE 9.
Here is the code:
$('#calendar').fullCalendar
ignoreTimezone: true,
editable: true,
defaultView: 'month',
height: 500,
slotMinutes: 30,
selectable: true,
selectHelper: true,
editable: false,
select: (start, end, allDay) ->
title = $("#title")
description = $("#description")
hours = $("#hours")
workorder = $("#workorder_id")
actcode = $("#actcode_id")
$("#dialog-form").dialog
autoOpen: true
height: 500
width: 400
modal: true
buttons:
"Create Labor": ->
$.create "/events/",
event:
workorder_id: workorder.val(),
actcode_id: actcode.val(),
title: title.val(),
description: description.val(),
hours: hours.val(),
starts_at: "" + start,
ends_at: "" + end,
all_day: allDay,
maxsynch: "N",
employee_id: $('#calendar').data('employeeid'),
overtime: "TRUE" if $("#overtime").is(":checked")
$(this).dialog "close"
$('#calendar').fullCalendar('refetchEvents')
UPDATE1
I changed the following - but, it didn't fix it.
eventSources: [{
url: '/events',
cache: false,
}],
UPDATE2
This worked:
...
employee_id: $('#calendar').data('employeeid'),
overtime: "TRUE" if $("#overtime").is(":checked")
complete: ->
$('#calendar').fullCalendar('refetchEvents')
I faced similar problem but i haven't used fullcalendar with rails.
IE caches the data So each time you call refetch events it shows cached events.
I have used events_function to fetch events.
In that I set cache: false option in ajax request to get events.
It worked in my case.
I'm playing around with FLOT with Ruby and I'm having a hard time passing the code to javascript; I know my javascript isn't reading the data correctly from Ruby. I need some syntax help.
o={};
o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i, x.num]}}
render :text => o.to_json
I have successfully rendered the output as such:
{"label":"A","data":[[1281225600,1.31],[1281225600,1.31],[1281225600,1.25]]}
The HTML outputs this data only.
My javascript is as follows:
var obj = jQuery.parseJSON(text);
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time", timeformat: "%m/%d/%y", minTickSize: [1, "day"]}
};
var data = obj;
$.plot(placeholder,[data],options);
}
What you are missing is that Ruby puts out timestamps in the Unix format (i.e. seconds since the epoch 1281225600). Flot requires javascript timestamps, which count the milliseconds since the epoch, i.e. 1281225600*1000.
So in your Ruby code, your best bet is to do something like this:
o={};
o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i*1000, x.num]}}
render :text => o.to_json
Or if you prefer, you could loop over the obj.data and do the multiplication on the Javascript side:
for (i=0;i<obj.data.length;i++){
obj.data[i] = obj.data[i]*1000;
}
Ok I got it....
Ruby code:
#o={};
#o= {'label' => "A", 'data' => #example.collect{|x| [Time.utc(x.date).to_i, x.num]}}
Java code:
$(function () {
var obj = <%= #o.to_json %>;
var options = {
lines: { show: true },
points: { show: true },
xaxis: { mode: "time", timeformat: "%m/%d/%y", minTickSize: [1, "day"]}
};
var data = obj;
$.plot(placeholder,[data],options);
});
I am trying to integratae my Grails application with extJS.
Below is the code in my edit.gsp file.
<%# page import="tune.Music"%>
<script type="text/javascript">
var ds = new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'http://localhost:8080/tune/music/listData'}),
reader: new Ext.data.JsonReader({
results: 'total',
root:'items',
id:'id'
},
[
{name: 'playerId'},
{name: 'playerPrice'}
]
)
});
var cm = new Ext.grid.ColumnModel([
{header: "Player Id", width: 70, sortable:true, dataIndex: 'playerId'},
{header: "Player Price", width: 90, dataIndex: 'playerPrice'}
]);
//cm.defaultSortable = true;
// create the grid
var grid = new Ext.grid.GridPanel({
ds: ds,
cm: cm,
renderTo:'grid-example',
width:1300,
height:300
});
</script>
</head>
<body>
<div class="body">
<!--<g:javascript library="examples"/>-->
<!-- EXAMPLES -->
<h1>Ext Grid</h1>
<div id="grid-example"></div>
</div>
</body>
My controller action:
def list={
}
def listData = { def session = sessionFactory.getCurrentSession()
def result = session.createSQLQuery("select player_id from w.music where player_id=('530AS')").list();
def tuneInstanceList = new ArrayList()
result.each
{ def tune = new Tune()
tune.playerId = it
tune.playerPrice = "100"
tuneInstanceList.add(tune) }
def listResult = [total: tunInstanceList.size(), items: tunInstanceList]
render listResult as JSON;
}
The above code works for me.
However, This works in my development environment.
If I run this in another env it doesnt work because of the url that I have hardcoded here viz url: 'http://localhost:8080/tune/music/listData'.
One of the options is to use gsparse. However, i would like to mention a relative urlPath here if thats possible.
What do I replace my urlPath with so that the right action is called even in other environments.
Thanks!
replaced the HttpProxy url as
url: '/tune/music/listData' and it worked.
Thanks!