Skip to content

Commit

Permalink
shows results report. can save report as csv file (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
brainstormtrooper committed Jul 30, 2023
1 parent 4d44383 commit 68abda8
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 11 deletions.
2 changes: 1 addition & 1 deletion data/io.github.brainstormtrooper.facteur.appdata.xml.in
Expand Up @@ -24,7 +24,7 @@
<url type="homepage">https://www.github.com/brainstormtrooper/facteur</url>
<updatecontact>brainstormtrooper_AT_free.fr</updatecontact>
<releases>
<release version="0.14.0" type="stable" date="2023-07-25"/>
<release version="0.15.0" type="stable" date="2023-07-25"/>
</releases>
<content_rating type="oars-1.0" />
</component>
65 changes: 61 additions & 4 deletions data/resultsMain.ui
Expand Up @@ -19,23 +19,80 @@
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkBox" id="consoleBox">


<object class="GtkBox" id="rportSaveBox">
<property name="orientation">horizontal</property>
<property name="vexpand">false</property>
<property name="hexpand">true</property>
<property name="halign">end</property>
<style>
<class name="formelementgroup" />
<class name="formrow" />
</style>
<child>
<object class="GtkLabel" id="saveLabel">
<style>
<class name="formelement" />
<class name="formlabel" />
</style>
<property name="label" translatable="yes">Save send report</property>
</object>
</child>
<child>
<object class="GtkButton" id="saveButton">
<property name="label" translatable="yes">Save</property>
<style>
<class name="formelement" />
<class name="forminput" />
<class name="button" />
<class name="new" />
</style>
</object>
</child>

</object>
</child>
<child>
<object class="GtkPaned" id="panedBox">
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrollText2">
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkTreeView" id="mTreeView">

</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="scrollText">
<object class="GtkBox" id="consoleBox">
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkTextView" id="textView">
<property name="editable">false</property>
<object class="GtkScrolledWindow" id="scrollText">
<property name="vexpand">true</property>
<property name="hexpand">true</property>
<child>
<object class="GtkTextView" id="textView">
<property name="editable">false</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>


<child>


<object class="GtkBox" id="mailingImportBox">
<property name="orientation">horizontal</property>
<property name="vexpand">false</property>
Expand Down
2 changes: 1 addition & 1 deletion io.github.brainstormtrooper.facteur.json
Expand Up @@ -32,7 +32,7 @@
{
"type" : "git",
"url" : "https://github.com/brainstormtrooper/facteur",
"tag": "0.14.0"
"tag": "0.15.0"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion meson.build
@@ -1,5 +1,5 @@
project('facteur', 'c',
version: '0.14.0',
version: '0.15.0',
meson_version: '>= 0.63.0'
)

Expand Down
52 changes: 50 additions & 2 deletions src/UI/Results.js
Expand Up @@ -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();
Expand All @@ -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 () {
Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/file.js
Expand Up @@ -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;
}
22 changes: 20 additions & 2 deletions src/object/Message.js
Expand Up @@ -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
Expand All @@ -61,14 +75,16 @@ 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;
appData.get('MAILINGS').forEach((mailing) => {
// 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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68abda8

Please sign in to comment.