Skip to content

Commit

Permalink
Merge pull request #512 from DemocracyEarth/dating
Browse files Browse the repository at this point in the history
Date Search
  • Loading branch information
santisiri authored Jul 3, 2020
2 parents 9bb2102 + 62b9ea0 commit c3e7a53
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 15 deletions.
3 changes: 2 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -880,5 +880,6 @@
"search-contract": "📄 {{searchTerm}}",
"search-summon": "🔥 Summon of {{dao}}",
"search-ragequit": "💸 Ragequit of {{shares}} shares from {{dao}} by {{address}}",
"search-default": "🔍 {{searchTerm}}"
"search-default": "🔍 {{searchTerm}}",
"search-dates": "📅 {{searchTerm}}"
}
16 changes: 15 additions & 1 deletion imports/api/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,23 @@ Meteor.methods({
* @summary given a keyword returns contract id
* @param {keyword} keyword identify contract by given keyword
*/
getProposalContract(contractId) {
check(contractId, String);
log(`{ method: 'getProposalContract', user: ${logUser()}, _id: '${contractId}' }`);
const contract = Contracts.findOne({ _id: contractId });
if (contract.pollId) {
return Contracts.findOne({ _id: contract.pollId });
}
return contract;
},

/**
* @summary given a keyword returns contract id
* @param {keyword} keyword identify contract by given keyword
*/
getContractById(contractId) {
check(contractId, String);
log(`{ method: 'getContractById', user: ${logUser()}, _id: '${contractId}' }`);
log(`{ method: 'getProposalContract', user: ${logUser()}, _id: '${contractId}' }`);
return Contracts.findOne({ _id: contractId });
},

Expand Down
14 changes: 14 additions & 0 deletions imports/api/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ Meteor.publish('singleDao', function (daoQuery) {
return this.ready();
});

/**
* @summary gets information of proposals from a given date
* @return {Object} user data
*/
Meteor.publish('dateContracts', function (terms) {
check(terms, Object);
const parameters = query(terms);
const contracts = Contracts.find(parameters.find, parameters.options);
if (contracts.count() > 0) {
return contracts;
}
return this.ready();
});

/**
* @summary transactions between a user and a contract
* @return {Object} querying terms
Expand Down
29 changes: 29 additions & 0 deletions imports/startup/both/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,35 @@ Router.route('/dao/:dao', {
});


/**
* @summary loads a post using date in url
**/
Router.route('/date', {
name: 'date',
template: 'home',
loadingTemplate: 'load',
onBeforeAction() {
Session.set('sidebarMenuSelectedId', 999);
_reset();
this.next();
},
waitOn() {
return Meteor.subscribe('dateContracts', { view: 'dateRange', from: this.params.query.from, until: this.params.query.until });
},
data() {
if (this.ready()) {
return {
options: { view: 'dateRange', from: this.params.query.from, until: this.params.query.until },
};
}
return {};
},
onAfterAction() {
_boilerPlate();
},
});


/**
* @summary loads a post using date in url
**/
Expand Down
15 changes: 13 additions & 2 deletions imports/ui/modules/chronos.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ const _timeCompressed = (date, micro) => {
return buildSentence(seconds, 'compressed', micro);
};

const _timeComplete = (date) => {
const _timeDateOnly = (date) => {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return `${_timeAgo(date)} &#183; ${date.toLocaleDateString('en', options)} &#183; ${(date.getHours() < 10) ? `0${(date.getHours())}` : date.getHours()}:${(date.getMinutes() < 10) ? `0${(date.getMinutes())}` : date.getMinutes()}`;
return `${date.toLocaleDateString('en', options)}`;
};

const _hourOnly = (date) => {
return `${(date.getHours() < 10) ? `0${(date.getHours())}` : date.getHours()}:${(date.getMinutes() < 10) ? `0${(date.getMinutes())}` : date.getMinutes()}`;
};

const _timeComplete = (date) => {
return `${_timeAgo(date)} &#183; ${_timeDateOnly(date)} &#183; ${_hourOnly(date)}`;
};


const timeLeft = (date) => {
const seconds = Math.floor((date - new Date()) / 1000);
if (seconds > 0) {
Expand All @@ -50,6 +59,8 @@ const timeLeft = (date) => {
return false;
};

export const hourOnly = _hourOnly;
export const timeDateOnly = _timeDateOnly;
export const timeCompressed = _timeCompressed;
export const timeSince = _timeAgo;
export const timeComplete = _timeComplete;
Expand Down
3 changes: 3 additions & 0 deletions imports/ui/templates/components/decision/ledger/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const _convertQuery = (instance) => {
case 'search':
tally.options.view = 'transactionsSearch';
break;
case 'dateRange':
tally.options.view = 'transactionsDate';
break;
default:
}
return tally;
Expand Down
1 change: 1 addition & 0 deletions imports/ui/templates/widgets/feed/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const _isIndexFeed = (instance) => {
|| instance.options.view === 'token'
|| instance.options.view === 'transactionsToken'
|| instance.options.view === 'transactionsPeer'
|| instance.options.view === 'transactionsDate'
|| instance.options.view === 'transactionsGeo'
|| instance.options.view === 'peer'
|| instance.options.view === 'threadVotes'
Expand Down
6 changes: 3 additions & 3 deletions imports/ui/templates/widgets/feed/feedItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
{{#if summon}}
{{> warning label="moloch-summon-dao" style='summon'}}
<div class="date-info">
<div class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</div>
<a href="{{dateURL}}" class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</a>
</div>
<div class="smart-contract">
<div class="parameter">
Expand Down Expand Up @@ -116,7 +116,7 @@
{{#if ragequit}}
{{> warning label="moloch-contract-ragequit" style='summon ragequit'}}
<div class="date-info">
<div class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</div>
<a href="{{dateURL}}" class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</a>
</div>
<div class="smart-contract">
<div class="parameter-line">
Expand All @@ -135,7 +135,7 @@
{{else}}
{{{description}}}
<div class="date-info">
<div class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</div>
<a href="{{dateURL}}" class="verifier verifier-live verifier-feed">{{{sinceDate createdAt}}}</a>
</div>
<div class="smart-contract">
<div class="parameter">
Expand Down
13 changes: 10 additions & 3 deletions imports/ui/templates/widgets/feed/feedItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { $ } from 'meteor/jquery';
import { Router } from 'meteor/iron:router';
import { ReactiveVar } from 'meteor/reactive-var';

import { getProfileFromUsername, getAnonymous } from '/imports/startup/both/modules/User';
import { getAnonymous } from '/imports/startup/both/modules/User';
import { removeContract } from '/imports/startup/both/modules/Contract';
import { getProfileName, stripHTMLfromText } from '/imports/ui/modules/utils';
import { stripHTMLfromText } from '/imports/ui/modules/utils';
import { timeComplete } from '/imports/ui/modules/chronos';
import { displayModal } from '/imports/ui/modules/modal';
import { animationSettings } from '/imports/ui/modules/animation';
Expand All @@ -19,9 +19,9 @@ import { templetize, getImage } from '/imports/ui/templates/layout/templater';
import { tokenWeb } from '/lib/token';
import { wrapURLs } from '/lib/utils';
import { Collectives } from '/imports/api/collectives/Collectives';
import { createDateQuery } from '/imports/ui/templates/widgets/transaction/transaction';

import '/imports/ui/templates/widgets/feed/feedItem.html';
import '/imports/ui/templates/widgets/transaction/transaction.js';
import '/imports/ui/templates/widgets/spinner/spinner.js';
import '/imports/ui/templates/components/identity/avatar/avatar.js';
import '/imports/ui/templates/components/decision/countdown/countdown.js';
Expand Down Expand Up @@ -695,6 +695,13 @@ Template.feedItem.helpers({
style: this.period ? `period period-${this.period.toLowerCase()}` : '',
};
},
dateURL() {
const from = this.timestamp;
const fromQuery = createDateQuery(from);
const until = new Date(this.timestamp.getTime() + (60 * 60 * 24 * 1000));
const untilQuery = createDateQuery(until);
return `/date?from=${fromQuery}&until=${untilQuery}`;
},
});

Template.feedItem.events({
Expand Down
29 changes: 27 additions & 2 deletions imports/ui/templates/widgets/preview/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { $ } from 'meteor/jquery';
import { stripHTMLfromText } from '/imports/ui/modules/utils';
import { Contracts } from '/imports/api/contracts/Contracts';
import { templetize, getImage } from '/imports/ui/templates/layout/templater';
import { getProposalDescription } from '/imports/ui/templates/widgets/feed/feedItem';

import '/imports/ui/templates/widgets/preview/preview.html';

Expand All @@ -23,20 +24,40 @@ const _getCharLength = (id) => {
Template.preview.onCreated(function () {
Template.instance().feed = new ReactiveVar();
Template.instance().contract = new ReactiveVar();
Template.instance().proposal = new ReactiveVar();

const instance = this;
const _id = Template.currentData().contractId;
if (_id) {
const contract = Contracts.findOne({ _id });
if (!contract) {
if (contract && contract.pollId) {
instance.contract.set(contract);
Meteor.call('getProposalContract', Template.currentData().contractId, function (error, result) {
if (result) {
instance.proposal.set(result);
} else if (error) {
console.log(error);
}
});
} else if (!contract) {
Meteor.call('getContractById', Template.currentData().contractId, function (error, result) {
if (result) {
instance.contract.set(result);

if (result.pollId) {
Meteor.call('getProposalContract', result._id, function (err, res) {
if (res) {
instance.proposal.set(res);
} else if (err) {
console.log(err);
}
});
}
} else if (error) {
console.log(error);
}
});
} else {
} else if (contract) {
instance.contract.set(contract);
}
}
Expand Down Expand Up @@ -69,6 +90,10 @@ Template.preview.helpers({
return title;
},
fullTitle() {
const proposal = Template.instance().proposal.get();
if (proposal && proposal.title) {
return `${getProposalDescription(proposal.title, true).substring(0, 45)}...`;
}
return stripHTMLfromText(Template.instance().contract.get().title);
},
url() {
Expand Down
8 changes: 8 additions & 0 deletions imports/ui/templates/widgets/search/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TAPi18n } from 'meteor/tap:i18n';
import { Contracts } from '/imports/api/contracts/Contracts';
import { Collectives } from '/imports/api/collectives/Collectives';
import { getProposalDescription } from '/imports/ui/templates/widgets/feed/feedItem';
import { timeDateOnly } from '/imports/ui/modules/chronos';

import web3 from 'web3';

Expand Down Expand Up @@ -64,6 +65,13 @@ const _setTags = () => {
text: TAPi18n.__('search-contract').replace('{{searchTerm}}', _dynamicTitle(getProposalDescription(contract.title, true))),
},
];
} else if (params.query.from) {
query = [
{
id: Router.current().params.query.from,
text: TAPi18n.__('search-dates').replace('{{searchTerm}}', timeDateOnly(new Date(Router.current().params.query.from))),
},
];
}
}

Expand Down
1 change: 1 addition & 0 deletions imports/ui/templates/widgets/tally/tally.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const _defaultTally = (view) => {
view === 'periodVotes' ||
view === 'transactionsToken' ||
view === 'transactionsPeer' ||
view === 'transactionsDate' ||
view === 'transactionsGeo' ||
view === 'transactionsDao' ||
view === 'transactionsSearch'
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/templates/widgets/transaction/transaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<div class="verifier verifier-live verifier-feed verifier-mini verifier-pending">{{_ 'pending'}}</div>
{{else}}
<img src="{{getImage 'clock'}}" class="clock-icon">
<div class="verifier verifier-live verifier-feed verifier-mini">{{sinceDate}}</div>
<a href="{{dateLink}}" title="{{dateDescription}}" class="verifier verifier-live verifier-feed verifier-mini">{{sinceDate}}</a>
{{/if}}
</div>
</div>
Expand Down
23 changes: 21 additions & 2 deletions imports/ui/templates/widgets/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Session } from 'meteor/session';
import { Meteor } from 'meteor/meteor';

import { getVotes } from '/imports/api/transactions/transaction';
import { timeCompressed } from '/imports/ui/modules/chronos';
import { timeCompressed, timeDateOnly, hourOnly } from '/imports/ui/modules/chronos';
import { token } from '/lib/token';
import { Transactions } from '/imports/api/transactions/Transactions';
import { syncBlockchain } from '/imports/startup/both/modules/metamask';
Expand Down Expand Up @@ -91,6 +91,15 @@ const _getContractToken = (transaction) => {
return coin;
};


/**
* @summary creates string of date for URL
* @return {string} uri
*/
const _createDateQuery = (date) => {
return `${date.getFullYear()}-${(date.getMonth() < 9) ? `0${parseInt(date.getMonth() + 1, 10)}` : parseInt(date.getMonth() + 1, 10)}-${(date.getDate() < 10) ? `0${date.getDate()}` : date.getDate()}`;
};

Template.transaction.onCreated(function () {
Template.instance().totalVotes = new ReactiveVar(0);
Template.instance().loading = new ReactiveVar(false);
Expand Down Expand Up @@ -216,6 +225,16 @@ Template.transaction.helpers({
sinceDate() {
return `${timeCompressed(this.contract.timestamp, true)}`;
},
dateLink() {
const from = this.contract.timestamp;
const fromQuery = _createDateQuery(from);
const until = new Date(this.contract.timestamp.getTime() + (60 * 60 * 24 * 1000));
const untilQuery = _createDateQuery(until);
return `/date?from=${fromQuery}&until=${untilQuery}`;
},
dateDescription() {
return `${timeDateOnly(this.contract.timestamp)} · ${hourOnly(this.contract.timestamp)}`;
},
ragequit() {
return this.isRagequit;
},
Expand Down Expand Up @@ -321,9 +340,9 @@ Template.collectivePreview.helpers({
return Template.instance().collective.name;
},
url() {
// console.log(Template.instance().collective);
return `/dao/${Template.instance().collective.uri}`;
},
});

export const getContractToken = _getContractToken;
export const createDateQuery = _createDateQuery;
Loading

0 comments on commit c3e7a53

Please sign in to comment.