I am trying to parse a JSON object that comes in from mongodb but am unable to use it for some reason after parsing.
Here is the piece of javascript function that I am using
-function check(category) {
-var temp = JSON.stringify(category);
-return JSON.parse(temp);
-}
.row.wow.fadeInRight.animated(data-wow-offset='30', data-wow-duration='1.5s', data-wow-delay='0.15s')
.col-md-12
if(articles)
#client-feedbacks.owl-carousel.owl-theme
each article in articles
-var category = article.categories
.feedback-box
.client-image.hidden-xs
img(src=article._.image.fit(250,250), alt='article image')
// MESSAGE OF THE CLIENT
h6.article-title
a(href='/blog/post/' + article.slug, itemprop='url')!= article.title
br
.message!= article.content.brief
// CLIENT INFORMATION
.client
.quote.red-text
i.icon-fontawesome-webfont-294
.client-info
a.client-namea(href='/blog/post/' + article.slug, itemprop='url')!= prettyDate(article.publishedDate)
-var categories = check(category)
.client-company(itemtype="http://schema.org/BlogPosting") #{category[0].name}
Here is what the object looks like when i use json .stringify
{ updatedBy: 5498631c5cbfa2d03f4570e6,
updatedAt: Mon Feb 09 2015 00:30:48 GMT+0530 (IST),
createdBy: 5498631c5cbfa2d03f4570e6,
createdAt: Mon Feb 09 2015 00:30:48 GMT+0530 (IST),
key: 'mongoose',
name: 'Mongoose',
_id: 54d7b2601d88fc4f69d0e081,
__v: 0 },{ updatedBy: 5498631c5cbfa2d03f4570e6,
updatedAt: Mon Feb 09 2015 00:31:44 GMT+0530 (IST),
createdBy: 5498631c5cbfa2d03f4570e6,
createdAt: Mon Feb 09 2015 00:31:44 GMT+0530 (IST),
key: 'green-berrets',
name: 'Green Berrets',
_id: 54d7b298fe85a1c4698b2ec3,
__v: 0 }
I am confused on how to parse it as most of the things i tried did not work
Related
I am using daterangepicker to select the start and the end date.
This is my JsFiddle example
The date is working and I can select the start and the end date.
<input type="text" class="date" ng-model="selectDate" />
But how can I pass the selectDate model to the filters so that only those events will be selected where selectDate will match the eventStartDateTime
$scope.data=[{'eventStartDateTime': 'Tue, 02 April 2019, 12:30 PM','eventName': 'ANew Event','itemCreatedDateTime': '3/04/2019 5:17:10 AM',},{'eventStartDateTime': 'Tue, 02 April 2019, 02:43 PM','eventName': 'AFeatured Event 3','itemCreatedDateTime': '2/04/2019 1:54:10 AM',},{'eventStartDateTime': 'Tue, 02 April 2019, 12:30 PM','eventName': 'Event 9','itemCreatedDateTime': '2/04/2019 1:29:56 AM',},{'eventStartDateTime': 'Thu, 28 March 2019, 04:30 AM','eventName': 'Featured Event 2','itemCreatedDateTime': '28/03/2019 4:59:13 AM',},{'eventStartDateTime': 'Tue, 02 April 2019, 12:55 PM','eventName': 'Featured Event 4','itemCreatedDateTime': '28/03/2019 4:58:54 AM',},{'eventStartDateTime': 'Thu, 28 March 2019, 04:30 AM','eventName': 'Avent 5','itemCreatedDateTime': '28/03/2019 1:29:06 AM',},{'eventStartDateTime': 'Thu, 28 March 2019, 05:30 AM','eventName': 'Event 4','itemCreatedDateTime': '28/03/2019 1:29:00 AM',},{'eventStartDateTime': 'Fri, 29 March 2019, 04:00 AM','eventName': 'Event 3','itemCreatedDateTime': '28/03/2019 1:28:54 AM',},{'eventStartDateTime': 'Thu, 21 March 2019, 04:30 AM','eventName': 'Event 2','itemCreatedDateTime': '28/03/2019 1:28:41 AM',},{'eventStartDateTime': 'Thu, 28 March 2019, 04:00 AM','eventName': 'Event 1','itemCreatedDateTime': '28/03/2019 1:28:36 AM',}];
Any help or suggestion would be appreciated.
Thanks in advance
You can use the Angular.js directive for daterangepicker
Install it then add daterangepicker to your angular.module and initialize your variables:
var app = angular.module("myApp", ["daterangepicker"]);
app.controller("myCtrl", function($scope, $window) {
...
$scope.showFreeEvent = false;
$scope.selectDate = { date: { startDate: null, endDate: null } };
...
Then in your HTML add attribute date-range-picker to any input and bind it to model:
<input
date-range-picker
class="form-control date-picker"
type="text"
ng-model="selectDate.date"
/>
And to filter your events you can use moment().isBefore() and moment().isAfter():
if (!$scope.showFreeEvent) {
return true;
}
if (
$scope.selectDate.date.startDate.isAfter(el.eventStartDateTime) ||
$scope.selectDate.date.endDate.isBefore(el.eventStartDateTime)
) {
return false;
}
Demo: https://codesandbox.io/s/l29yqywx9m
add ng-onchange="filterfunction(dateModelInput)"
this will detect a change in your html,call your filter function. this will update your DOM.
make sure you include the filter into the html that needs the filtering.
<div>{{ctrl.data | filterResult }}</div>
I'm currently trying to save a mail object () I'm getting back from an API into our Mongo database.
This is all fine for all values being passed accept the field 'attachments'. The attachments are supposed to be an array of objects, but this is wrapped in a string. My question now is: how do I get the array out of that string?
Example of the req.body which I'm getting from the POST request:
{ timestamp: '1538728432', token:
'0a1336769443d5a593d0ef7c1c817d29ef64ba422fc3cc45f1', signature:
'c44c67660f0ad97bbb5ece92c733302d4511d4607b5787ae6aa8f2203b0e2e3e',
domain: 'karaton.uk', From: '',
'X-Envelope-From': '', To: '',
'Dkim-Signature': 'v=1; a=rsa-sha256;
c=relaxed/relaxed;\td=karaton.be;
s=20140924;\th=content-type:subject:reply-to:from:to:message-id:mime-version:date:from;\tbh=Xfm+LiX4NVMKTRaQB7gNUXf6z8yVjUqn23aenMee/q4=;\tb=JEslFgXEsO3/kW3khZFF6F4HEo9Mwx+oXJH5DGsXALaGa98ki9o5tLddmEcClqhZ8IJLR0+vrMJ3x\t
zU5ThqHNElHpt6VE9MX5ZSHJHnI2kiEXq7MN5BUWfStlS2stYwooZcuZKOkbZXRaUHODewUQbhvZQD\t
5/eA5RltbAOqwIaA=', from: '', 'User-Agent':
'One.com webmail 27.8.5', Date: 'Fri, 05 Oct 2018 10:21:49 +0200',
'Message-Id': '<1538727709180.51726.8212#webmail12>',
'Mime-Version': '1.0', Received: [ 'from
mailrelay4-2.pub.mailoutpod1-cph3.one.com
(mailrelay4-2.pub.mailoutpod1-cph3.one.com [46.30.212.3]) by
mxa.mailgun.org with ESMTP id 5bb71f1f.7f030c2a1580-smtp-in-n02; Fri,
05 Oct 2018 08:21:51 -0000 (UTC)',
'from onecom-webmail2 94.143.189.242 (unknown [46.30.211.130])\tby mailrelay4.pub.mailoutpod1-cph3.one.com (Halon)
with ESMTPSA\tid b4d6415f-c877-11e8-86b7-d0431ea8bb10;\tFri, 05 Oct
2018 08:21:49 +0000 (UTC)' ], 'X-Halone-Cookie':
'c9ea0f7e80128b5bfaf5bf8d8aca6fced5bcb162', subject: '2
attachments', 'message-url':
'https://se.api.mailgun.net/v3/domains/karaton.uk/messages/eyJwIjpmYWxzZSwiayI6IjEyNzQ1ZmViLTM4OTItNDdkZC04MTJiLWJlYzU4ZjNjYTI4MCIsInMiOiI1NDE1ODQ0ZjIyIiwiYyI6InRhbmtiIn0=',
'Reply-To': '', recipient: 'tho#karaton.uk',
sender: 'thomas.l#karaton.be', 'X-Mailgun-Incoming': 'Yes',
'message-headers': '[["X-Mailgun-Incoming", "Yes"],
["X-Envelope-From", ""], ["Received", "from
mailrelay4-2.pub.mailoutpod1-cph3.one.com
(mailrelay4-2.pub.mailoutpod1-cph3.one.com [46.30.212.3]) by
mxa.mailgun.org with ESMTP id 5bb71f1f.7f030c2a1580-smtp-in-n02; Fri,
05 Oct 2018 08:21:51 -0000 (UTC)"], ["Dkim-Signature", "v=1;
a=rsa-sha256; c=relaxed/relaxed;\td=karaton.be;
s=20140924;\th=content-type:subject:reply-to:from:to:message-id:mime-version:date:from;\tbh=Xfm+LiX4NVMKTRaQB7gNUXf6z8yVjUqn23aenMee/q4=;\tb=JEslFgXEsO3/kW3khZFF6F4HEo9Mwx+oXJH5DGsXALaGa98ki9o5tLddmEcClqhZ8IJLR0+vrMJ3x\t
zU5ThqHNElHpt6VE9MX5ZSHJHnI2kiEXq7MN5BUWfStlS2stYwooZcuZKOkbZXRaUHODewUQbhvZQD\t
5/eA5RltbAOqwIaA="], ["X-Halone-Cookie",
"c9ea0f7e80128b5bfaf5bf8d8aca6fced5bcb162"], ["X-Halone-Id",
"b4d6415f-c877-11e8-86b7-d0431ea8bb10"], ["Received", "from
onecom-webmail2 94.143.189.242 (unknown [46.30.211.130])\tby
mailrelay4.pub.mailoutpod1-cph3.one.com (Halon) with ESMTPSA\tid
b4d6415f-c877-11e8-86b7-d0431ea8bb10;\tFri, 05 Oct 2018 08:21:49
+0000 (UTC)"], ["X-Originating-Ip", "94.143.189.242"], ["User-Agent", "One.com webmail 27.8.5"], ["Date", "Fri, 05 Oct 2018 10:21:49
+0200"], ["Mime-Version", "1.0"], ["Message-Id", "<1538727709180.51726.8212#webmail12>"], ["To", ""],
["From", ""], ["Reply-To",
""], ["Subject", "2 attachments"],
["Content-Type", "multipart/mixed;
boundary=\"----------8210-1538727709180-1\""]]', 'X-Halone-Id':
'b4d6415f-c877-11e8-86b7-d0431ea8bb10', 'Content-Type':
'multipart/mixed; boundary="----------8210-1538727709180-1"',
'X-Originating-Ip': '94.143.189.242', Subject: '2 attachments',
attachments: '[{"url":
"https://se.api.mailgun.net/v3/domains/karaton.uk/messages/eyJwIjpmYWxzZSwiayI6IjEyNzQ1ZmViLTM4OTItNDdkZC04MTJiLWJlYzU4ZjNjYTI4MCIsInMiOiI1NDE1ODQ0ZjIyIiwiYyI6InRhbmtiIn0=/attachments/0",
"content-type": "application/pdf", "name": "WOORDZOEKER maken _ Online
_ Met oplossing2 copy.pdf", "size": 53398}, {"url": "https://se.api.mailgun.net/v3/domains/karaton.uk/messages/eyJwIjpmYWxzZSwiayI6IjEyNzQ1ZmViLTM4OTItNDdkZC04MTJiLWJlYzU4ZjNjYTI4MCIsInMiOiI1NDE1ODQ0ZjIyIiwiYyI6InRhbmtiIn0=/attachments/1",
"content-type":
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"name": "Geschatte uren.xlsx", "size": 44210}]', 'body-plain':
'\r\n\r\n', 'body-html': '\r\n', 'stripped-html':
'\n', 'stripped-text': '', 'stripped-signature': ''
}
Use the built-in JSON.parse() function, it'll return an array of objects as it should. It's opposed to JSON.stringify(), which does the opposite. So, basically,
JSON.parse(req.body.attachments) should do the trick.
JSON.parse should do the trick
const response = {
timestamp: '1538728432',
token: '0a1336769443d5a593d0ef7c1c817d29ef64ba422fc3cc45f1',
Subject: '2 attachments',
attachments: '[{"url": "https://se.api.mailgun.net/v3/domains/karaton.uk/messages/eyJwIjpmYWxzZSwiayI6IjEyNzQ1ZmViLTM4OTItNDdkZC04MTJiLWJlYzU4ZjNjYTI4MCIsInMiOiI1NDE1ODQ0ZjIyIiwiYyI6InRhbmtiIn0=/attachments/0", "content-type": "application/pdf", "name": "WOORDZOEKER maken _ Online _ Met oplossing2 copy.pdf", "size": 53398}, {"url": "https://se.api.mailgun.net/v3/domains/karaton.uk/messages/eyJwIjpmYWxzZSwiayI6IjEyNzQ1ZmViLTM4OTItNDdkZC04MTJiLWJlYzU4ZjNjYTI4MCIsInMiOiI1NDE1ODQ0ZjIyIiwiYyI6InRhbmtiIn0=/attachments/1", "content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "name": "Geschatte uren.xlsx", "size": 44210}]'
}
const attachments = JSON.parse(response.attachments);
console.log(attachments[0]);
console.log(attachments[1]);
Ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
I'm using moment.js for my react-native project datetime formater. I want to remove the timezone from utc date. For my timezone is GMT+8000, so for utc offset is correct, when when I add format('YYYY/MM/DD 00:00'), result subtract one day.
console.log(moment.utc());
-> Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Jul 11 2018 11:08:57 GMT+0800 (Malaysia Time), …}
console.log(moment.utc().utcOffset(new Date().getTimezoneOffset()));
->Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Jul 11 2018 03:08:57 GMT+0800 (Malaysia Time), …}
console.log(moment.utc().utcOffset(new Date().getTimezoneOffset()).format('YYYY/MM/DD 00:00'));
->"2018/07/10 00:00"
Any idea how ? Or maybe I doing it wrong ?
I'm trying to create an ICS file on click of buttons inside each of my divs.
This works fine in Chrome and Firefox. However, it fails to work on IE.
What's wrong with the code in 'window.open'?
Also, how do I change the name of th file based on the event ID?
Here's the code
angular.module('myApp', []).controller('myCtrl', function($scope){
$scope.card = [{
Name: "New Year Celebration",
Description: "",
Venue: "",
StartDate: "Fri Dec 29 2017 23:30:00 GMT+0530",
EndDate: "Sat Dec 30 2017 00:30:00 GMT+0530",
EventID: "1"
}, {
Name: "25th Anniversary Celebration",
Description: "25th Anniversary Celebration of organization",
Venue: "Auditorium",
StartDate: "Wed May 31 2017 17:30:00 GMT+0530",
EndDate: "Wed May 31 2017 20:30:00 GMT+0530",
EventID: "2"
}, {
Name: "Annual Day",
Description: "",
Venue: "",
StartDate: "Fri Oct 13 2017 14:30:00 GMT+0530",
EndDate: "Fri Oct 13 2017 17:30:00 GMT+0530",
EventID: "3"
}];
$scope.add = function(eventObj) {
$scope.eventID= this.eventObj.EventID;
$scope.startDate= this.eventObj.StartDate;
$scope.endDate= this.eventObj.EndDate;
$scope.venue= this.eventObj.Venue;
$scope.subject= this.eventObj.Name;
$scope.result= this.eventObj.Description;
//console.log(this);
$scope.icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nDTSTART:" + $scope.startDate +"\nDTEND:" + $scope.endDate +"\nLOCATION:" + $scope.venue + "\nSUMMARY:" + $scope.subject + "\nDESCRIPTION:"+ $scope.result +"\nEND:VEVENT\nEND:VCALENDAR";
window.open("data:text/calendar;charset=utf8," + escape($scope.icsMSG),"_self");
};
});
.event {
height: 150px;
width: 250px;
border: 1px solid lightgrey;
background-color: skyblue;
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="eventObj in card" class="event">
Subject: <span>{{eventObj.Name}}</span>
<br /><br />
Venue:<span>{{eventObj.Venue}}</span>
<br /><br />
Date:<span>{{eventObj.StartDate | date:'fullDate'}}</span>
<br /><br />
<button ng-click="add(eventObj.EventID)">Add to Outlook</button>
</div>
</div>
Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements in IE.
The solution is to use navigator.msSaveBlob to generate the file and prompt the user to save it. Refer this answer
You could also use something like downloadify instead of data URLs (would work for IE as well) as mentioned here
I have an object
{
YHOO: [
{
date: Fri Apr 12 1996 00:00:00 GMT-0400 (EDT),
open: 25.25,
high: 43,
low: 24.5,
close: 33,
volume: 408720000,
adjClose: 1.38,
symbol: 'YHOO'
},
...
{
date: Thu Nov 14 2013 00:00:00 GMT-0500 (EST),
open: 35.07,
high: 35.89,
low: 34.76,
close: 35.69,
volume: 21368600,
adjClose: 35.69,
symbol: 'YHOO'
}
],
GOOGL: [
{
date: Thu Aug 19 2004 00:00:00 GMT-0400 (EDT),
open: 100,
high: 104.06,
low: 95.96,
close: 100.34,
volume: 22351900,
adjClose: 100.34,
symbol: 'GOOGL'
},
...
{
date: Thu Nov 14 2013 00:00:00 GMT-0500 (EST),
open: 1033.92,
high: 1039.75,
low: 1030.35,
close: 1035.23,
volume: 1166700,
adjClose: 1035.23,
symbol: 'GOOGL'
}
],
...
}
How do I alter this object so it becomes an array with
[
{
date: Fri Apr 12 1996 00:00:00 GMT-0400 (EDT),
YHOO: 33,
GOOG: 100.34
},
...
]
I know it can become a problem that they potentially not have the same dates, so I guess I should just say that one of the companies have the right dates, and then merge the other companies to these dates and omit those dates that are not in the already selected company.
I guess I should do something like
var data = [];
obj.YHOO.forEach((quote) => {
data.push({
date: quote.date,
YHOO: quote.price,
GOOG: ?
});
});
and instead of the question mark, I can loop through all the objects in array.GOOG and check if the date matches quote.date.
The big problem is that this seems quite computational heavy and the names of the companies can vary, so I cannot guarantee that YHOO and GOOG are present.