mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
tweaks
This commit is contained in:
@ -10,6 +10,10 @@ html(lang="en", ng-app="biomed", ng-controller="biomed.PageCtrl")
|
|||||||
a.brand(href='/', target='_self') Atlantic Biomedical
|
a.brand(href='/', target='_self') Atlantic Biomedical
|
||||||
progress-panel
|
progress-panel
|
||||||
ul.nav.pull-right(ng-controller='biomed.AccountCtrl')
|
ul.nav.pull-right(ng-controller='biomed.AccountCtrl')
|
||||||
|
li
|
||||||
|
a(href='https://docs.google.com/a/atlanticbiomedical.com/forms/d/16tPHoTkEQB7fqXxBDZk_7s-WLz6a3eXVBWiUyA0fntM/viewform', target='_blank')
|
||||||
|
i.icon-thumbs-down
|
||||||
|
| Incident
|
||||||
li
|
li
|
||||||
a(href='http://atlanticbiomedical.com/ticket/', target='_blank')
|
a(href='http://atlanticbiomedical.com/ticket/', target='_blank')
|
||||||
i.icon-fire
|
i.icon-fire
|
||||||
@ -47,4 +51,4 @@ html(lang="en", ng-app="biomed", ng-controller="biomed.PageCtrl")
|
|||||||
| Workorders
|
| Workorders
|
||||||
.container-fluid
|
.container-fluid
|
||||||
ng-view
|
ng-view
|
||||||
!{js}
|
!{js}
|
||||||
|
@ -2,6 +2,7 @@ var googleapis = require('googleapis'),
|
|||||||
sprintf = require('sprintf'),
|
sprintf = require('sprintf'),
|
||||||
OAuth2Client = googleapis.OAuth2Client;
|
OAuth2Client = googleapis.OAuth2Client;
|
||||||
|
|
||||||
|
var apiClient;
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
|
|
||||||
@ -15,14 +16,15 @@ module.exports = function(config) {
|
|||||||
|
|
||||||
var opts = { baseDiscoveryUrl: 'https://www.googleapis.com/discovery/v1/apis/' };
|
var opts = { baseDiscoveryUrl: 'https://www.googleapis.com/discovery/v1/apis/' };
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
scheduleEvent: function(event, callback) {
|
scheduleEvent: function(event, callback) {
|
||||||
console.log("schedule event");
|
console.log("schedule event");
|
||||||
|
|
||||||
api(function(client, callback) {
|
api(function(client, callback) {
|
||||||
|
|
||||||
var resource = buildResource(event);
|
var resource = buildResource(event, {});
|
||||||
|
console.log("Insert Google Calendar");
|
||||||
|
console.log(resource);
|
||||||
|
|
||||||
var request = client.calendar.events.insert({
|
var request = client.calendar.events.insert({
|
||||||
calendarId: 'primary',
|
calendarId: 'primary',
|
||||||
@ -38,34 +40,47 @@ module.exports = function(config) {
|
|||||||
updateEvent: function(event, callback) {
|
updateEvent: function(event, callback) {
|
||||||
api(function(client, callback) {
|
api(function(client, callback) {
|
||||||
|
|
||||||
var resource = buildResource(event);
|
var getRequest = client.calendar.events.get({
|
||||||
|
|
||||||
var request = client.calendar.events.update({
|
|
||||||
calendarId: 'primary',
|
calendarId: 'primary',
|
||||||
eventId: event.eventId,
|
eventId: event.eventId
|
||||||
resource: resource
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getRequest.withAuthClient(oauth2Client).execute(function(err, result) {
|
||||||
|
console.log("get result");
|
||||||
|
console.log(err);
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
request.withAuthClient(oauth2Client).execute(function(err, result) {
|
var resource = buildResource(event, result);
|
||||||
callback(err, result);
|
if ('sequence' in resource) {
|
||||||
|
resource.sequence += 1;
|
||||||
|
} else {
|
||||||
|
resource.sequence = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateRequest = client.calendar.events.update({
|
||||||
|
calendarId: 'primary',
|
||||||
|
eventId: event.eventId,
|
||||||
|
resource: buildResource(event, result)
|
||||||
|
});
|
||||||
|
|
||||||
|
updateRequest.withAuthClient(oauth2Client).execute(function(err, result) {
|
||||||
|
callback(err, result);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildResource(event) {
|
function buildResource(event, resource) {
|
||||||
var resource = {
|
console.log(event.start);
|
||||||
summary: event.summary,
|
console.log(event.end);
|
||||||
description: event.description,
|
|
||||||
location: event.location,
|
resource.summary = event.summary;
|
||||||
start: {
|
resource.description = event.description;
|
||||||
dateTime: event.start
|
resource.location = event.location;
|
||||||
},
|
resource.start = { dateTime: event.start };
|
||||||
end: {
|
resource.end = { dateTime: event.end };
|
||||||
dateTime: event.end
|
resource.attendees = [];
|
||||||
},
|
|
||||||
attendees: []
|
|
||||||
};
|
|
||||||
|
|
||||||
event.attendees.forEach(function(attendee) {
|
event.attendees.forEach(function(attendee) {
|
||||||
resource.attendees.push({
|
resource.attendees.push({
|
||||||
@ -77,20 +92,30 @@ module.exports = function(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function api(workorder, callback) {
|
function api(workorder, callback) {
|
||||||
googleapis
|
var handler = function(client) {
|
||||||
.discover('calendar', 'v3')
|
workorder(client, function(err, result) {
|
||||||
.execute(function(err, client) {
|
if (oauth2Client.credentials.access_token != config.auth.accessToken) {
|
||||||
if (err) return callback(err);
|
console.log("Updating access token");
|
||||||
|
config.auth.accessToken = oauth2Client.credentials.access_token;
|
||||||
|
}
|
||||||
|
|
||||||
workorder(client, function(err, result) {
|
callback(err, result);
|
||||||
if (oauth2Client.credentials.access_token != config.auth.accessToken) {
|
|
||||||
console.log("Updating access token");
|
|
||||||
config.auth.accessToken = oauth2Client.credentials.access_token;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(err, result);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
console.log(apiClient);
|
||||||
|
if (apiClient) {
|
||||||
|
console.log("Using cached api client");
|
||||||
|
handler(apiClient);
|
||||||
|
} else {
|
||||||
|
console.log("Getting api client");
|
||||||
|
googleapis.discover('calendar', 'v3').execute(function(err, client) {
|
||||||
|
if (err) return callback(err);
|
||||||
|
apiClient = client;
|
||||||
|
|
||||||
|
handler(apiClient);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<option value="scheduled">Scheduled</option>
|
<option value="scheduled">Scheduled</option>
|
||||||
<option value="invoiced">Invoiced</option>
|
<option value="invoiced">Invoiced</option>
|
||||||
<option value="paid">Paid</option>
|
<option value="paid">Paid</option>
|
||||||
|
<option value="submitted">Submitted</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -204,4 +205,4 @@
|
|||||||
No history is currently available.
|
No history is currently available.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user