Commit cf7ddef6 authored by Nacim Goura's avatar Nacim Goura

add notif and cron

parent 7e376fb8
...@@ -47,7 +47,7 @@ html-tools@1.0.11 ...@@ -47,7 +47,7 @@ html-tools@1.0.11
htmljs@1.0.11 htmljs@1.0.11
http@1.2.12 http@1.2.12
id-map@1.0.9 id-map@1.0.9
johanbrook:publication-collector@1.0.8 johanbrook:publication-collector@1.0.9
jquery@1.11.10 jquery@1.11.10
kadira:blaze-layout@2.3.0 kadira:blaze-layout@2.3.0
kadira:flow-router@2.12.1 kadira:flow-router@2.12.1
......
...@@ -3,33 +3,37 @@ import { check } from 'meteor/check'; ...@@ -3,33 +3,37 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import configCollection from '/imports/api/config/configCollection'; import configCollection from '/imports/api/config/configCollection';
export function defineConfig(config) {
check(config, Object);
const oldConfig = configCollection.find({ userId: Meteor.userId() }).fetch();
if (config.forbiddenWord) {
config.forbiddenWord = config.forbiddenWord.split(',');
}
if (config.domain) {
config.domain = config.domain.replace('https', 'http');
}
// if config already exist, replace old value with new
if (oldConfig && oldConfig.length) {
configCollection.update(oldConfig[0]._id, {
$set: {
domain: config.domain || oldConfig.domain,
forbiddenWord: config.forbiddenWord || oldConfig.forbiddenWord,
breadcrumb: config.breadcrumb || oldConfig.breadcrumb,
},
});
} else {
// else insert
config.userId = Meteor.userId();
configCollection.insert(config);
}
}
export function getConfig() {
return configCollection.findOne({ userId: Meteor.userId() });
}
Meteor.methods({ Meteor.methods({
// define config // define config
defineConfig(config) { defineConfig,
check(config, Object); getConfig,
const oldConfig = configCollection.find({ userId: Meteor.userId() }).fetch();
if (config.forbiddenWord) {
config.forbiddenWord = config.forbiddenWord.split(',');
}
if (config.domain) {
config.domain = config.domain.replace('https', 'http');
}
// if config already exist, replace old value with new
if (oldConfig && oldConfig.length) {
configCollection.update(oldConfig[0]._id, {
$set: {
domain: config.domain || oldConfig.domain,
forbiddenWord: config.forbiddenWord || oldConfig.forbiddenWord,
breadcrumb: config.breadcrumb || oldConfig.breadcrumb,
},
});
} else {
// else insert
config.userId = Meteor.userId();
configCollection.insert(config);
}
},
getConfig() {
return configCollection.findOne({ userId: Meteor.userId() });
},
}); });
import { AutoForm } from 'meteor/aldeed:autoform'; import { AutoForm } from 'meteor/aldeed:autoform';
import displayNotif from '/imports/ui/components/notifs/notifs.js'; import displayNotif from '/imports/api/notif/notif.js';
const hooksFormApiCrawl = { const hooksFormApiCrawl = {
onSuccess(formType, result) { onSuccess(formType, result) {
......
import { AutoForm } from 'meteor/aldeed:autoform'; import { AutoForm } from 'meteor/aldeed:autoform';
import displayNotif from '/imports/ui/components/notifs/notifs.js'; import displayNotif from '/imports/api/notif/notif.js';
const hooksFormWebsiteCrawl = { const hooksFormWebsiteCrawl = {
onSuccess(formType, result) { onSuccess(formType, result) {
......
...@@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor'; ...@@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
import Crawler from 'crawler'; import Crawler from 'crawler';
import Sitemapper from 'sitemapper'; import Sitemapper from 'sitemapper';
import checkData from '/imports/utils/checkData'; import checkData from '/imports/utils/checkData';
import { getConfig } from '/imports/api/config/methods';
export default class crawlWebsite { export default class crawlWebsite {
...@@ -18,13 +19,9 @@ export default class crawlWebsite { ...@@ -18,13 +19,9 @@ export default class crawlWebsite {
domain: url.parse(urlWebsite).hostname, domain: url.parse(urlWebsite).hostname,
forbiddenWord: [], forbiddenWord: [],
}; };
try { if (getConfig()) {
const syncFunc = Meteor.wrapAsync(Meteor.call); this.config = getConfig();
this.config = syncFunc('getConfig');
} catch (err) {
console.error(err);
} }
console.log(this.config);
return this.start(); return this.start();
} }
......
...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform'; ...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import displayNotif from '../../ui/components/notifs/notifs.js'; import displayNotif from '../notif/notif.js';
const hooksFormLogin = { const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => { onSubmit: (insertDoc, updateDoc, currentDoc) => {
...@@ -33,6 +33,6 @@ const hooksFormLogin = { ...@@ -33,6 +33,6 @@ const hooksFormLogin = {
}; };
AutoForm.hooks({ AutoForm.hooks({
formApiCrawl: hooksFormLogin, formLogin: hooksFormLogin,
}); });
import { Meteor } from 'meteor/meteor';
import notifsCollection from './notifsCollection';
export function addNotif(notif) {
notif.userId = this.userId;
notifsCollection.insert(notif);
}
Meteor.methods({
addNotif,
});
import { Meteor } from 'meteor/meteor';
import iziToast from 'izitoast'; import iziToast from 'izitoast';
import alertsCollections from '../../../api/notif/notifsCollection';
export default function (options) { export default function (options) {
this.options = { this.options = {
...@@ -13,13 +13,13 @@ export default function (options) { ...@@ -13,13 +13,13 @@ export default function (options) {
Object.assign(this.options, options); Object.assign(this.options, options);
if (options.save === true) { iziToast[options.type](this.options);
alertsCollections.insert({
type: options.type, if (this.options.type === 'error') {
title: options.title, this.options.type = 'danger';
message: options.message,
});
} }
iziToast[options.type](this.options); if (this.options.save === true) {
Meteor.call('addNotif', this.options);
}
} }
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this local collection keep tracks of all notification of this application * this collection keep tracks of all notification of this application
* @type {Mongo.Collection} * @type {Mongo.Collection}
*/ */
const notifsCollection = new Mongo.Collection('notifs'); const notifsCollection = new Mongo.Collection('notifs');
...@@ -12,7 +12,7 @@ const notifsCollection = new Mongo.Collection('notifs'); ...@@ -12,7 +12,7 @@ const notifsCollection = new Mongo.Collection('notifs');
SimpleSchema.notifsCollection = new SimpleSchema({ SimpleSchema.notifsCollection = new SimpleSchema({
type: { type: {
type: String, type: String,
allowedValues: ['info', 'success', 'warning', 'error'], allowedValues: ['info', 'success', 'warning', 'danger'],
}, },
title: { title: {
type: String, type: String,
...@@ -22,17 +22,13 @@ SimpleSchema.notifsCollection = new SimpleSchema({ ...@@ -22,17 +22,13 @@ SimpleSchema.notifsCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
user: { userId: {
type: String, type: String,
defaultValue: Meteor.userId(),
}, },
}); });
notifsCollection.attachSchema(SimpleSchema.notifsCollection); notifsCollection.attachSchema(SimpleSchema.notifsCollection);
// publish notif for available by client
// Meteor.publish('notifs', () => notifsCollection.find({ user: Meteor.userId() }).fetch());
export default notifsCollection; export default notifsCollection;
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this local collection keep tracks of all tabs of this application * this local collection keep tracks of all tabs of this application
...@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({ ...@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
}); });
......
...@@ -2,54 +2,57 @@ ...@@ -2,54 +2,57 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection'; import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
Meteor.methods({ export function addTest(test) {
addTest(test) { // test data
// test data check(test, Object);
check(test, Object); testSearchCollection.simpleSchema().namedContext().validate(test);
testSearchCollection.simpleSchema().namedContext().validate(test);
// replace https by http // replace https by http
test.urlExpected = decodeURI(_.replace(test.urlExpected, 'https', 'http')); test.urlExpected = decodeURI(_.replace(test.urlExpected, 'https', 'http'));
// call search // call search
Meteor.call('searchByTerm', test.term, Meteor.bindEnvironment((err, results) => { Meteor.call('searchByTerm', test.term, Meteor.bindEnvironment((err, results) => {
if (err) { if (err) {
console.log(err); console.log(err);
throw new Meteor.Error('Error', 'Erreur lors de la recherche'); throw new Meteor.Error('Error', 'Erreur lors de la recherche');
} else { } else {
_.forEach(results.list, (result, index) => { _.forEach(results.list, (result, index) => {
if (test.urlExpected === result.url) { if (test.urlExpected === result.url) {
test.urlPosition = index + 1; test.urlPosition = index + 1;
}
});
const oldTest = testSearchCollection.find({ term: test.term }).fetch();
if (oldTest && oldTest.length) {
testSearchCollection.update(oldTest[0]._id, {
$set: {
urlPosition: test.urlPosition,
createdAt: new Date(),
},
});
} else {
testSearchCollection.insert(test);
} }
});
const oldTest = testSearchCollection.find({ term: test.term }).fetch();
if (oldTest && oldTest.length) {
testSearchCollection.update(oldTest[0]._id, {
$set: {
urlPosition: test.urlPosition,
createdAt: moment().toDate(),
},
});
} else {
testSearchCollection.insert(test);
} }
})); }
}, }));
deleteTest(id) { }
check(id, String);
testSearchCollection.remove({ _id: id }); export function deleteTest(id) {
}, check(id, String);
launchTest() { testSearchCollection.remove({ _id: id });
const tests = testSearchCollection.find({}).fetch(); }
_.each(tests, (test) => {
Meteor.call('addTest', test, Meteor.bindEnvironment((err) => { export function launchTest() {
if (err) { const tests = testSearchCollection.find({}).fetch();
throw new Meteor.Error('Error', 'Erreur lors de la relance des tests'); _.each(tests, (test) => {
} addTest(test);
})); });
}); }
},
Meteor.methods({
addTest,
deleteTest,
launchTest,
}); });
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/** /**
* this collection is temporaire for testsearch * this collection is temporaire for testsearch
...@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({ ...@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
}, },
createdAt: { createdAt: {
type: Date, type: Date,
defaultValue: new Date(), defaultValue: moment().toDate(),
}, },
}); });
......
// Import client startup through a single index entry point // Import client startup through a single index entry point
import moment from 'moment';
import 'moment/locale/fr';
import 'bootstrap-sass'; import 'bootstrap-sass';
import './routes'; import './routes';
moment.locale('fr');
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout'; import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import displayNotif from '../../ui/components/notifs/notifs'; import displayNotif from '../../api/notif/notif';
// Import layout templates // Import layout templates
import '../../ui/layouts/main/main'; import '../../ui/layouts/main/main';
......
import { SyncedCron } from 'meteor/percolate:synced-cron';
import moment from 'moment';
import 'moment/locale/fr';
import notifsCollection from '/imports/api/notif/notifsCollection';
moment.locale('fr');
SyncedCron.add({
name: 'Remove old notifications',
schedule(parser) {
// parser is a later.parse object
return parser.text('every 1 day');
},
job() {
notifsCollection.remove({ createdAt: moment().subtract(1, 'days').toDate() });
},
});
// Import server startup through a single index entry point // Import server startup through a single index entry point
// add data on startup
import './fixtures'; import './fixtures';
import './register-api';
import('meteor/percolate:synced-cron').then(({ SyncedCron }) => { // list of api (methods, publications, tabular...)
const numberCron = Object.keys(SyncedCron._entries); import './register-api';
if (numberCron > 0) { // task of cron
console.log(`Nombre de cron à exécuter : ${numberCron}`); import './cron';
SyncedCron.start();
}
});
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
import '/imports/api/indexation/methods'; import '/imports/api/indexation/methods';
import '/imports/api/account/methods'; import '/imports/api/account/methods';
import '/imports/api/config/methods'; import '/imports/api/config/methods';
import '/imports/api/notif/methods';
import '/imports/api/testSearch/methods'; import '/imports/api/testSearch/methods';
import '/imports/tabular/tabularUser'; import '/imports/tabular/tabularUser';
import '/imports/tabular/tabularTestSearch'; import '/imports/tabular/tabularTestSearch';
import '/imports/tabular/tabularNotif';
...@@ -5,5 +5,6 @@ import 'datatables.net-bs/css/dataTables.bootstrap.css'; ...@@ -5,5 +5,6 @@ import 'datatables.net-bs/css/dataTables.bootstrap.css';
import './buttonTabular.html'; import './buttonTabular.html';
import './tabularUser'; import './tabularUser';
import './tabularTestSearch'; import './tabularTestSearch';
import './tabularNotif';
dataTablesBootstrap(window, $); dataTablesBootstrap(window, $);
import Tabular from 'meteor/aldeed:tabular';
import moment from 'moment';
import $ from 'jquery';
import notifsCollection from '/imports/api/notif/notifsCollection';
new Tabular.Table({
name: 'Notifs',
collection: notifsCollection,
columns: [
{
data: 'type', title: 'Type',
},
{
data: 'title', title: 'Titre',
},
{
data: 'message', title: 'Message',
},
{
data: 'createdAt',
title: 'Date',
render(val, type, doc) {
return moment(val).format('LLL');
},
},
],
createdRow(row, data, dataIndex) {
if (data.type) {
$(row).addClass(data.type);
}
},
pageLength: 20,
language: {
sProcessing: 'Traitement en cours...',
sSearch: 'Rechercher :',
sLengthMenu: 'Afficher _MENU_ éléments',
sInfo: "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
sInfoEmpty: "Affichage de l'élément 0 à 0 sur 0 élément",
sInfoFiltered: '(filtré de _MAX_ éléments au total)',
sInfoPostFix: '',
sLoadingRecords: 'Chargement en cours...',
sZeroRecords: 'Aucun élément à afficher',
sEmptyTable: 'Aucune donnée disponible dans le tableau',
oPaginate: {
sFirst: 'Premier',
sPrevious: 'Précédent',
sNext: 'Suivant',
sLast: 'Dernier',
},
oAria: {
sSortAscending: ': activer pour trier la colonne par ordre croissant',
sSortDescending: ': activer pour trier la colonne par ordre décroissant',
},
},
});
import Tabular from 'meteor/aldeed:tabular'; import Tabular from 'meteor/aldeed:tabular';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import testSearchCollection from '../api/testSearch/testSearchCollection'; import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
new Tabular.Table({ new Tabular.Table({
name: 'testSearch', name: 'testSearch',
...@@ -17,7 +18,11 @@ new Tabular.Table({ ...@@ -17,7 +18,11 @@ new Tabular.Table({
data: 'urlPosition', title: 'Position', data: 'urlPosition', title: 'Position',
}, },
{ {
data: 'createdAt', title: 'Date', data: 'createdAt',
title: 'Date',
render(val, type, doc) {
return moment(val).format('LLL');
},
}, },
{ {
tmpl: Meteor.isClient && Template.testSearchActionTable, tmpl: Meteor.isClient && Template.testSearchActionTable,
......
import Tabular from 'meteor/aldeed:tabular'; import Tabular from 'meteor/aldeed:tabular';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import moment from 'moment';
new Tabular.Table({ new Tabular.Table({
name: 'Accounts', name: 'Accounts',
...@@ -12,6 +13,13 @@ new Tabular.Table({ ...@@ -12,6 +13,13 @@ new Tabular.Table({
{ {
data: 'emails[0].address', title: 'Email', data: 'emails[0].address', title: 'Email',
}, },
{
data: 'createdAt',
title: 'Date',
render(val, type, doc) {
return moment(val).format('LLL');
},
},
{ {
tmpl: Meteor.isClient && Template.accountActionTable, tmpl: Meteor.isClient && Template.accountActionTable,
}, },
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import displayNotif from '../../components/notifs/notifs'; import displayNotif from '../../../api/notif/notif';
import './result/result'; import './result/result';
...@@ -26,6 +26,7 @@ Template.searchTpl.events({ ...@@ -26,6 +26,7 @@ Template.searchTpl.events({
type: 'error', type: 'error',
title: 'Recherche : ', title: 'Recherche : ',
message: error.reason ? error.reason : error, message: error.reason ? error.reason : error,
save: true,
}); });
}); });
}, },
......
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import displayNotif from '../../../../components/notifs/notifs'; import displayNotif from '../../../../../api/notif/notif';
import './add.html'; import './add.html';
...@@ -25,7 +25,8 @@ Template.addAccountTpl.events({ ...@@ -25,7 +25,8 @@ Template.addAccountTpl.events({
displayNotif({ displayNotif({
type: 'success', type: 'success',
title: 'Succès : ', title: 'Succès : ',
message: 'Compte ajouté avec succès!', message: `Compte ajouté avec succès pour ${user.username}!`,
save: true,
}); });
}) })
.catch((err) => { .catch((err) => {
...@@ -33,6 +34,7 @@ Template.addAccountTpl.events({ ...@@ -33,6 +34,7 @@ Template.addAccountTpl.events({
type: 'error', type: 'error',
title: 'Erreur : ', title: 'Erreur : ',
message: err.message, message: err.message,
save: true,
}); });
});