Skip to content

Commit

Permalink
feat: add button to reload file in log viewer (#862j4vqdt)
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed Jan 26, 2023
1 parent 3a098ce commit 92d6161
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/back-end/builddata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.41.1","build":16041}
{"version":"0.41.1","build":16047}
11 changes: 11 additions & 0 deletions app/back-end/events/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ class AppEvents {
* Load specific log file
*/
ipcMain.on('app-log-file-load', function(event, filename) {
let logPath = appInstance.app.getPath('logs');
let logFiles = fs.readdirSync(logPath).filter(function(file) {
return file.substr(-4) === '.txt' || file.substr(-4) === '.log';
});

if (logFiles.indexOf(filename) === -1) {
event.sender.send('app-log-file-loaded', {
fileContent: 'File not found!'
});
}

let filePath = path.join(appInstance.app.getPath('logs'), filename);
let fileContent = fs.readFileSync(filePath, 'utf8');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@
"publiiOnGithub": "View Publii on Github",
"publishAndClose": "Publish and close",
"publishPost": "Publish post",
"reloadFile": "Reload file",
"renderFrontPageOnly": "Render front page only",
"renderFullWebsite": "Render full website",
"reportBugInSupportDesk": "Report a bug via our support desk",
Expand Down
1 change: 1 addition & 0 deletions app/default-files/default-languages/pl/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@
"publiiOnGithub": "Zobacz Publii na Github",
"publishAndClose": "Opublikuj i zamknij",
"publishPost": "Opublikuj wpis",
"reloadFile": "Wczytaj ponownie plik",
"renderFrontPageOnly": "Renderuj tylko stronę główną",
"renderFullWebsite": "Renderuj całą stronę",
"reportBugInSupportDesk": "Zgłoś błąd w naszym naszj pomocy technicznej",
Expand Down
26 changes: 22 additions & 4 deletions app/src/components/LogViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
:items="files"
selected=""
:onChange="loadFile"></dropdown>

<p-button
:onClick="loadSelectedFile"
type="primary">
{{ $t('ui.reloadFile') }}
</p-button>
</div>

<codemirror-editor
Expand All @@ -34,16 +40,16 @@ export default {
mixins: [
BackToTools
],
data: function() {
data () {
return {
files: {}
};
},
mounted: function() {
mounted () {
this.loadFilesList();
},
methods: {
loadFilesList: function() {
loadFilesList () {
mainProcessAPI.send('app-log-files-load');
mainProcessAPI.receiveOnce('app-log-files-loaded', (data) => {
Expand All @@ -59,7 +65,7 @@ export default {
this.files = items;
});
},
loadFile: function(filename) {
loadFile (filename) {
if (filename === '') {
this.$refs.codemirror.editor.setValue('');
return;
Expand All @@ -78,11 +84,23 @@ export default {
this.$refs.codemirror.editor.refresh();
});
},
loadSelectedFile () {
let filename = this.$refs['selectedFile'].selectedValue;
this.loadFile(filename);
}
}
}
</script>

<style lang="scss" scoped>
@import '../scss/variables.scss';
.tools-log-viewer-selector {
display: flex;
.button {
margin-left: 1rem;
}
}
</style>

0 comments on commit 92d6161

Please sign in to comment.