diff --git a/data/io.github.brainstormtrooper.facteur.appdata.xml.in b/data/io.github.brainstormtrooper.facteur.appdata.xml.in index d46fca5..d91a930 100644 --- a/data/io.github.brainstormtrooper.facteur.appdata.xml.in +++ b/data/io.github.brainstormtrooper.facteur.appdata.xml.in @@ -24,7 +24,7 @@ https://www.github.com/brainstormtrooper/facteur brainstormtrooper_AT_free.fr - + diff --git a/data/resultsMain.ui b/data/resultsMain.ui index b27e4bb..e21ece6 100644 --- a/data/resultsMain.ui +++ b/data/resultsMain.ui @@ -19,23 +19,80 @@ true true - + + + + horizontal + false + true + end + + + + + Save send report + + + + + Save + + + + + + + + true true + vertical + + + true + true + + + + + + + - + true true - - false + + true + true + + + false + + + + + + horizontal false diff --git a/io.github.brainstormtrooper.facteur.json b/io.github.brainstormtrooper.facteur.json index 3599eed..b52367d 100644 --- a/io.github.brainstormtrooper.facteur.json +++ b/io.github.brainstormtrooper.facteur.json @@ -32,7 +32,7 @@ { "type" : "git", "url" : "https://github.com/brainstormtrooper/facteur", - "tag": "0.14.0" + "tag": "0.15.0" } ] } diff --git a/meson.build b/meson.build index fa9fa04..3958966 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('facteur', 'c', - version: '0.14.0', + version: '0.15.0', meson_version: '>= 0.63.0' ) diff --git a/src/UI/Results.js b/src/UI/Results.js index aaff6e5..63c87ae 100644 --- a/src/UI/Results.js +++ b/src/UI/Results.js @@ -2,6 +2,7 @@ const Gtk = imports.gi.Gtk; const Gio = imports.gi.Gio; const Gettext = imports.gettext; const myMessage = imports.object.Message; +const myFile = imports.lib.file; const GObject = imports.gi.GObject; const Message = new myMessage.Message(); @@ -14,7 +15,7 @@ var resultsMain = GObject.registerClass( // eslint-disable-line GTypeName: 'resultsMain', Template: 'resource:///io/github/brainstormtrooper/facteur/resultsMain.ui', // Children: [], - InternalChildren: ['textView', 'sentLabel', 'sendButton'] + InternalChildren: ['textView', 'mTreeView', 'sentLabel', 'sendButton', 'saveButton'] }, class resultsMain extends Gtk.Box { _init () { @@ -34,23 +35,70 @@ var UIresults = GObject.registerClass( // eslint-disable-line this.defSentStr = Gettext.gettext('Not yet sent'); } + report () { + this._listStore = new Gtk.ListStore(); + const coltypes = [GObject.TYPE_STRING, GObject.TYPE_STRING]; + this._listStore.set_column_types(coltypes); + this.mTreeView.set_model(this._listStore); + const normal = new Gtk.CellRendererText(); + const colTo = new Gtk.TreeViewColumn({ + title: 'To' + }); + colTo.pack_start(normal, true); + colTo.add_attribute(normal, 'text', 0); + this.mTreeView.insert_column(colTo, 0); + const colRes = new Gtk.TreeViewColumn({ + title: 'Result' + }); + + colRes.pack_start(normal, true); + colRes.add_attribute(normal, 'text', 1); + this.mTreeView.insert_column(colRes, 1); + + let i; + for (i = 0; i < Message.results.length; i++) { + const row = Message.results[i]; + const iter = this._listStore.append(); + + this._listStore.set(iter, [0, 1], row); + } + } + _buildUI () { this.resultsMain = new resultsMain(); // this.textBuffer = ''; this.textView = this.resultsMain._textView; + this.mTreeView = this.resultsMain._mTreeView; this.sentLabel = this.resultsMain._sentLabel; this.sendButton = this.resultsMain._sendButton; + this.saveButton = this.resultsMain._saveButton; this.textView.set_buffer(this.textBuffer); + this.saveButton.connect('clicked', () => { + const data = myFile.csvFromArray(Message.results); + const props = { + title: 'Save Send Report', + data + }; + + myFile.fileSave(props, (res) => { + return res; + }); + }); this.sendButton.connect('clicked', async () => { try { const res = await Message.compile(); if (res) { - Message.sendAll(); + const r = Message.sendAll(); + Promise.all(r).then(() => { + this.report(); + }).catch((r) => { + log(r); + }); } else { const e = new Error('Failed to compile template'); log(e); diff --git a/src/lib/file.js b/src/lib/file.js index aa9254e..9ad5aa4 100644 --- a/src/lib/file.js +++ b/src/lib/file.js @@ -208,3 +208,12 @@ async function open (path) { function nameFromPath (path) { return path.split('/')[-1]; } + +function csvFromArray (rows = []) { + let work = []; + rows.forEach((row) => { + work.push(row.map((cell) => `"${cell.replace('"', '\"')}"`).join(',')); + }); + const res = work.join('\n'); + return res; +} \ No newline at end of file diff --git a/src/object/Message.js b/src/object/Message.js index ac83d66..8b70440 100644 --- a/src/object/Message.js +++ b/src/object/Message.js @@ -49,6 +49,20 @@ var Message = GObject.registerClass( // eslint-disable-line } + success (str) { + let res = 'ok'; + const lines = str.split("\n"); + lines.forEach(line => { + if (line[0] == '<' && line.substring(2,5) > 400) { + // < 250 2.0.0 Ok: queued + res = line; + + } + }); + + return res; + } + sleep (milliseconds) { const timeStart = new Date().getTime(); // eslint-disable-next-line @@ -61,6 +75,8 @@ var Message = GObject.registerClass( // eslint-disable-line } sendAll () { + let res = []; + this.results = []; this.App = Gio.Application.get_default(); this.curConn = Config.getConnection(appData.get('CONN')); const delay = this.curConn.DELAY; @@ -68,7 +84,7 @@ var Message = GObject.registerClass( // eslint-disable-line // eslint-disable-next-line max-len const mobj = this.build(mailing); try { - this.send(mobj, mailing.to); + res.push(this.send(mobj, mailing.to)); } catch (error) { logError(error); } @@ -77,6 +93,7 @@ var Message = GObject.registerClass( // eslint-disable-line }); appData.set('SENT', time.now()); this.App.emit('Sent', true); + return res; } build (mailing) { @@ -274,8 +291,9 @@ var Message = GObject.registerClass( // eslint-disable-line ); }); // log(`>>> RES >>> : ${stdout}`); + this.results.push([to, this.success(stdout)]); this.App.emit('Logger', `>>> RES >>> : ${stdout}`); - // return stdout; + return Date.now().toLocaleString(); } catch (e) { // This could be any number of errors, but probably it will be a // GError in which case it will have `code` property carrying a