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
htmljs@1.0.11
http@1.2.12
id-map@1.0.9
johanbrook:publication-collector@1.0.8
johanbrook:publication-collector@1.0.9
jquery@1.11.10
kadira:blaze-layout@2.3.0
kadira:flow-router@2.12.1
......
......@@ -3,9 +3,7 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import configCollection from '/imports/api/config/configCollection';
Meteor.methods({
// define config
defineConfig(config) {
export function defineConfig(config) {
check(config, Object);
const oldConfig = configCollection.find({ userId: Meteor.userId() }).fetch();
if (config.forbiddenWord) {
......@@ -28,8 +26,14 @@ Meteor.methods({
config.userId = Meteor.userId();
configCollection.insert(config);
}
},
getConfig() {
}
export function getConfig() {
return configCollection.findOne({ userId: Meteor.userId() });
},
}
Meteor.methods({
// define config
defineConfig,
getConfig,
});
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 = {
onSuccess(formType, result) {
......
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 = {
onSuccess(formType, result) {
......
......@@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
import Crawler from 'crawler';
import Sitemapper from 'sitemapper';
import checkData from '/imports/utils/checkData';
import { getConfig } from '/imports/api/config/methods';
export default class crawlWebsite {
......@@ -18,13 +19,9 @@ export default class crawlWebsite {
domain: url.parse(urlWebsite).hostname,
forbiddenWord: [],
};
try {
const syncFunc = Meteor.wrapAsync(Meteor.call);
this.config = syncFunc('getConfig');
} catch (err) {
console.error(err);
if (getConfig()) {
this.config = getConfig();
}
console.log(this.config);
return this.start();
}
......
......@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router';
import displayNotif from '../../ui/components/notifs/notifs.js';
import displayNotif from '../notif/notif.js';
const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => {
......@@ -33,6 +33,6 @@ const hooksFormLogin = {
};
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 alertsCollections from '../../../api/notif/notifsCollection';
export default function (options) {
this.options = {
......@@ -13,13 +13,13 @@ export default function (options) {
Object.assign(this.options, options);
if (options.save === true) {
alertsCollections.insert({
type: options.type,
title: options.title,
message: options.message,
});
iziToast[options.type](this.options);
if (this.options.type === 'error') {
this.options.type = 'danger';
}
iziToast[options.type](this.options);
if (this.options.save === true) {
Meteor.call('addNotif', this.options);
}
}
import SimpleSchema from 'simpl-schema';
import { Meteor } from 'meteor/meteor';
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}
*/
const notifsCollection = new Mongo.Collection('notifs');
......@@ -12,7 +12,7 @@ const notifsCollection = new Mongo.Collection('notifs');
SimpleSchema.notifsCollection = new SimpleSchema({
type: {
type: String,
allowedValues: ['info', 'success', 'warning', 'error'],
allowedValues: ['info', 'success', 'warning', 'danger'],
},
title: {
type: String,
......@@ -22,17 +22,13 @@ SimpleSchema.notifsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
user: {
userId: {
type: String,
defaultValue: Meteor.userId(),
},
});
notifsCollection.attachSchema(SimpleSchema.notifsCollection);
// publish notif for available by client
// Meteor.publish('notifs', () => notifsCollection.find({ user: Meteor.userId() }).fetch());
export default notifsCollection;
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this local collection keep tracks of all tabs of this application
......@@ -37,7 +38,7 @@ SimpleSchema.TabsCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
});
......
......@@ -2,10 +2,10 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import _ from 'lodash';
import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
Meteor.methods({
addTest(test) {
export function addTest(test) {
// test data
check(test, Object);
testSearchCollection.simpleSchema().namedContext().validate(test);
......@@ -29,7 +29,7 @@ Meteor.methods({
testSearchCollection.update(oldTest[0]._id, {
$set: {
urlPosition: test.urlPosition,
createdAt: new Date(),
createdAt: moment().toDate(),
},
});
} else {
......@@ -37,19 +37,22 @@ Meteor.methods({
}
}
}));
},
deleteTest(id) {
}
export function deleteTest(id) {
check(id, String);
testSearchCollection.remove({ _id: id });
},
launchTest() {
}
export function launchTest() {
const tests = testSearchCollection.find({}).fetch();
_.each(tests, (test) => {
Meteor.call('addTest', test, Meteor.bindEnvironment((err) => {
if (err) {
throw new Meteor.Error('Error', 'Erreur lors de la relance des tests');
}
}));
addTest(test);
});
},
}
Meteor.methods({
addTest,
deleteTest,
launchTest,
});
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';
import moment from 'moment';
/**
* this collection is temporaire for testsearch
......@@ -25,7 +26,7 @@ SimpleSchema.testSearchCollection = new SimpleSchema({
},
createdAt: {
type: Date,
defaultValue: new Date(),
defaultValue: moment().toDate(),
},
});
......
// Import client startup through a single index entry point
import moment from 'moment';
import 'moment/locale/fr';
import 'bootstrap-sass';
import './routes';
moment.locale('fr');
......@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import displayNotif from '../../ui/components/notifs/notifs';
import displayNotif from '../../api/notif/notif';
// Import layout templates
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
// add data on startup
import './fixtures';
import './register-api';
import('meteor/percolate:synced-cron').then(({ SyncedCron }) => {
const numberCron = Object.keys(SyncedCron._entries);
// list of api (methods, publications, tabular...)
import './register-api';
if (numberCron > 0) {
console.log(`Nombre de cron à exécuter : ${numberCron}`);
SyncedCron.start();
}
});
// task of cron
import './cron';
......@@ -3,6 +3,8 @@
import '/imports/api/indexation/methods';
import '/imports/api/account/methods';
import '/imports/api/config/methods';
import '/imports/api/notif/methods';
import '/imports/api/testSearch/methods';
import '/imports/tabular/tabularUser';
import '/imports/tabular/tabularTestSearch';
import '/imports/tabular/tabularNotif';
......@@ -5,5 +5,6 @@ import 'datatables.net-bs/css/dataTables.bootstrap.css';
import './buttonTabular.html';
import './tabularUser';
import './tabularTestSearch';
import './tabularNotif';
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 { Meteor } from 'meteor/meteor';
import testSearchCollection from '../api/testSearch/testSearchCollection';
import moment from 'moment';
import testSearchCollection from '/imports/api/testSearch/testSearchCollection';
new Tabular.Table({
name: 'testSearch',
......@@ -17,7 +18,11 @@ new Tabular.Table({
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,
......
import Tabular from 'meteor/aldeed:tabular';
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
new Tabular.Table({
name: 'Accounts',
......@@ -12,6 +13,13 @@ new Tabular.Table({
{
data: 'emails[0].address', title: 'Email',
},
{
data: 'createdAt',
title: 'Date',
render(val, type, doc) {
return moment(val).format('LLL');
},
},
{
tmpl: Meteor.isClient && Template.accountActionTable,
},
......
......@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Session } from 'meteor/session';
import displayNotif from '../../components/notifs/notifs';
import displayNotif from '../../../api/notif/notif';
import './result/result';
......@@ -26,6 +26,7 @@ Template.searchTpl.events({
type: 'error',
title: 'Recherche : ',
message: error.reason ? error.reason : error,
save: true,
});
});
},
......
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import displayNotif from '../../../../components/notifs/notifs';
import displayNotif from '../../../../../api/notif/notif';
import './add.html';
......@@ -25,7 +25,8 @@ Template.addAccountTpl.events({
displayNotif({
type: 'success',
title: 'Succès : ',
message: 'Compte ajouté avec succès!',
message: `Compte ajouté avec succès pour ${user.username}!`,
save: true,
});
})
.catch((err) => {
......@@ -33,6 +34,7 @@ Template.addAccountTpl.events({
type: 'error',
title: 'Erreur : ',
message: err.message,
save: true,
});
});
},
......
......@@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import displayNotif from '../../../../components/notifs/notifs';
import displayNotif from '../../../../../api/notif/notif';
import '../../../../../tabular/configClient';
import './list.html';
......@@ -22,6 +22,7 @@ Template.accountActionTable.events({
type: 'error',
title: 'Erreur : ',
message: err.message,
save: true,
});
});
},
......
......@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import swal from 'sweetalert2';
import displayNotif from '../../../../components/notifs/notifs.js';
import displayNotif from '../../../../../api/notif/notif.js';
import './main.html';
......@@ -24,12 +24,14 @@ Template.mainIndexationTpl.events({
type: 'success',
title: 'Indexation : ',
message: 'ElasticSearch à été initialisé correctement!',
save: true,
});
}).catch((error) => {
displayNotif({
type: 'error',
title: 'Indexation : ',
message: error.reason ? error.reason : error,
save: true,
});
});
});
......
......@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import $ from 'jquery';
import displayNotif from '/imports/ui/components/notifs/notifs.js';
import displayNotif from '/imports/api/notif/notif.js';
import formWebsiteCrawlSchema from '/imports/api/crawl/website/formWebsiteCrawlSchema';
import '/imports/api/crawl/website/formWebsiteCrawlHooks';
......@@ -74,7 +74,6 @@ Template.siteIndexationTpl.events({
type: 'success',
title: 'Configuration : ',
message: 'Configuration ajouté avec succès!',
save: true,
});
}).catch((error) => {
displayNotif({
......
......@@ -2,15 +2,13 @@
<div class="row">
<h3 class="text-center">Liste des dernières notifications</h3>
{{#if getNotifs.length}}
<ul>
{{#each getNotifs}}
<li>{{title}} - {{message}} le {{createdAt}}</li>
{{/each}}
</ul>
{{else}}
<h4 class="text-center">Aucune notification trouvé!</h4>
{{/if}}
<div class="panel panel-default">
<div class="panel-body">
{{> tabular table=TabularTables.Notifs class="table table-bordered table-condensed text-center"}}
</div>
</div>
</div>
</template>
......
import { Template } from 'meteor/templating';
import notifCollection from '/imports/api/notif/notifsCollection';
import '/imports/tabular/configClient';
import './notif.html';
Template.notifTpl.helpers({
getNotifs() {
console.log(Meteor.subscribe('tasks'));
return notifCollection.find({}).fetch();
},
});
......@@ -3,7 +3,7 @@
<!-- template loginTpl -->
<div class="row">
<div class="col-md-6 col-md-offset-3">
{{#autoForm id="formLogin" schema=formLoginSchema}}
{{#autoForm id="formLogin" schema=formLoginSchema method="post"}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="text-center">Connectez-vous</h3>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment