Skip to content

Commit

Permalink
database check fixes, search function fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturnine-Softworks committed Mar 28, 2024
1 parent 6c2733a commit d42d80f
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 67 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lexicanter",
"productName": "Lexicanter",
"version": "2.1.14",
"version": "2.1.15",
"description": "A lexicon management tool for constructed languages.",
"main": "src/index.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/app/layouts/Changelog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@

<br><hr/><br>

<p><u>Patch 2.1.15</u></p>
<p style="width: 70%; margin: auto; text-align: left; line-height: 1.6">
• Fixed a reported bug which caused the search fields in the lexicon and phrasebook to find no matches in certain cases. <br>
• Changed the way that the app recognizes when changes have been made to the version of your file in the database. <br>
• A few quality of life features related to the previous change, including the ability to see the local and online file version numbers in Settings. <br>
</p>
<br>
<p><u>Patch 2.1.14</u></p>
<p style="width: 70%; margin: auto; text-align: left; line-height: 1.6">
• Fixed a bug with the orthography pattern replacement features which caused it to only replace the first instance of a pattern in each word.<br>
• Added the ability to use <code>^</code> or <code>#</code> as word-end characters in the orthography pattern replacement fields. <br>
• Fixed a reported bug with the Illegals field of the Advanced Phonotactics word generator which caused that field not to save its contents. <br>
• Fixed a bug with database syncing which caused the setting to not save for files.
• Files should now automatically detect when you have changes in the database on loading, and will prompt you to download the changes.
• Fixed a bug with database syncing which caused the setting to not save for files. <br>
• Files should now automatically detect when you have changes in the database on loading, and will prompt you to download the changes.<br>
</p>
<br>
<p><u>Patch 2.1.13</u></p>
Expand Down
19 changes: 17 additions & 2 deletions src/app/layouts/File.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
if (contents.hasOwnProperty('SaveLocation')) {
$Language.SaveLocation = contents.SaveLocation;
}
if (contents.hasOwnProperty('FileVersion')) {
$Language.FileVersion = contents.FileVersion
}
errorMessage = 'There was a problem loading the alphabet from the file.'
$Language.Alphabet = contents.Alphabet;
Expand Down Expand Up @@ -155,9 +158,21 @@
if (verifyHash($dbid, $dbkey)) {
const queryResult = await retrieveFromDatabase(contents.Name);
if (queryResult !== false) {
if (JSON.stringify($Language.Lexicon) !== JSON.stringify(queryResult.Lexicon)) {
if (queryResult.FileVersion === undefined) {
vex.dialog.confirm({
message: `The file in the database has no FileVersion number. Would you like to overwrite it with your local version?`,
yesText: 'Upload Local Version',
callback: (proceed) => {
if (proceed) {
saveFile();
vex.dialog.alert('Saved and uploaded local file.')
}
}
})
} else if ( parseInt($Language.FileVersion, 36) < parseInt(queryResult.FileVersion, 36) ) {
vex.dialog.confirm({
message: 'Detected changes to the file in the database. Would you like to download them?',
message: `Detected a newer version of the file in the database (local: ${$Language.FileVersion} | online: ${queryResult.FileVersion}). Would you like to download the changes?`,
yesText: 'Download Changes',
callback: (proceed, download = queryResult) => {
if (proceed) {
$Language = download;
Expand Down
100 changes: 49 additions & 51 deletions src/app/layouts/Lexicon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -191,77 +191,75 @@
* or end of a word. Searches are combinative, and only
* results which match all search input fields will be
* selected as matches.
* @returns {any}
*/
function search_lex(): void {
let words_search = $Language.CaseSensitive? searchWords.trim() : searchWords.toLowerCase().trim();
let definitions_search = searchDefinitions.toLowerCase().trim();
let tags_search = searchTags.toLowerCase().trim()? searchTags.toLowerCase().trim().split(/\s+/g) : [];
let tags_search = searchTags.toLowerCase().trim();
keys = [];
if (!!words_search || !!definitions_search || !!tags_search[0] || !!lectFilter) {
// Turn l into a list of [search by word terms, search by def terms
let l = [[...words_search.split('|')], [...definitions_search.split('|')]];
if (!!words_search || !!definitions_search || !!tags_search || !!lectFilter) { // if there is at least one search term
for (let word in $Language.Lexicon) {
const w = '^' + word.replaceAll(/\s+/g, '^') + '^';
let match = lectFilter? $Language.Lexicon[word].Senses.some(sense => sense.lects.includes(lectFilter)) : true;
if (!match) continue;
for (let a of l[0]) {
// words
if (!w.includes(a)) {
let entry = $Language.Lexicon[word];
let match = true;
// check lect filter
if ( !!lectFilter ) {
if ( !entry.Senses.some(sense => sense.lects.includes(lectFilter)) ) {
match = false;
continue;
}
}
for (let a of l[1]) {
// definitions
let needs_exact_match = a[0] === '!';
if (needs_exact_match) {
let pattern = `\\b${a.split('!')[1]}\\b`;
$Language.Lexicon[word].Senses.forEach(sense => {
if (!sense.definition.toLowerCase().match(pattern)) {
// no exact word match
match = false;
}
});
} else if (!$Language.Lexicon[word].Senses.some(sense => sense.definition.toLowerCase().includes(a))) {
// no partial match
// check word
if ( !!words_search ) {
if ( words_search[0] === '!') { // requires exact match
if (word !== words_search.split('!')[1]) {
match = false;
continue;
}
} else if ( !('^' + word.replaceAll(/\s+/g, '^') + '^').includes(words_search.replaceAll(/\s+/g, '^')) ) {
// searches for inexact match
match = false;
continue;
}
}
if (!!$Language.Lexicon[word].Senses.some(sense => !!sense.tags[0])) {
// has at least one tag
let partial_tag_match = false;
let needs_exact_match = false;
let has_exact_match = false;
for (let tag of $Language.Lexicon[word].Senses.map(sense => sense.tags).flat()) {
for (let a of tags_search) {
// debug.log('`a` | `tag` : ' + a + ' | ' + tag, false)
// tags
if (a[0] === '!') {
needs_exact_match = true;
if (`!${tag}` === a) {
has_exact_match = true;
partial_tag_match = true;
}
}
if (`^${tag}^`.includes(a)) {
partial_tag_match = true;
}
// check definitions
if ( !!definitions_search ) {
if ( definitions_search[0] === '!' ) { // requires exact match
if (!entry.Senses.some(sense => sense.definition === definitions_search.split('!')[1])) {
match = false;
continue;
}
}
if (!!tags_search[0] && ((!partial_tag_match) || (needs_exact_match && !has_exact_match))) {
} else if (!entry.Senses.some(sense => sense.definition.replaceAll(/\s+/g, '^').toLowerCase().includes(definitions_search.replaceAll(/\s+/g, '^')))) {
// searches for inexact match
match = false;
continue;
}
} else {
// has no tags
if (!!tags_search[0]) {
match = false; // at least one tag as search term
}
// check tags
if ( !!tags_search ) {
let tag_search_array = tags_search.split(/\s+/);
for (let tag_search of tag_search_array) {
if (tag_search[0] === '!') { // requires exact match (per tag basis)
if (!entry.Senses.some(sense => sense.tags.some(tag => tag.toLowerCase() === tag_search.split('!')[1]))) {
match = false;
continue;
}
} else if ( !entry.Senses.some(sense => sense.tags.some(tag => `^${tag.toLowerCase()}^`.includes(tag_search))) ) {
// searches for inexact match (per tag basis)
match = false;
continue;
}
}
}
if (match) {
if ( match ) {
keys = [...keys, word];
}
}
if (!keys.length) keys = [null]; // Search was attempted, no results
if (!keys.length) {keys = [null]}; // Search was attempted, no results
}
}
</script>
Expand Down
7 changes: 3 additions & 4 deletions src/app/layouts/Phrasebook.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@
let tagMatch = !tagsSearch
const filterLect = lectFilter? !lectFilter : scope[entry].lects.includes(lectFilter);
if (term.includes(phrase_search))
if (term.toLowerCase().includes(phrase_search.toLowerCase()))
phraseMatch = true;
if (scope[entry].description.toLowerCase().includes(descript_search))
if (scope[entry].description.toLowerCase().includes(descript_search.toLowerCase()))
descriptMatch = true;
if (!!tagsSearch) {
if (scope[entry].tags.some(tag => tagsSearch.includes(tag)))
if (scope[entry].tags.some(tag => tagsSearch.includes(tag.toLowerCase())))
tagMatch = true;
}
for (let variant in scope[entry].variants) {
let v_term = '^' + variant + '^';
if (v_term.includes(phrase_search))
Expand Down
22 changes: 21 additions & 1 deletion src/app/layouts/Settings.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { theme, autosave, pronunciations, wordInput, dbid, dbkey } from '../stores';
import { theme, autosave, pronunciations, wordInput, dbid, dbkey, fileLoadIncrement } from '../stores';
import { userData, saveFile, showOpenDialog, retrieveFromDatabase } from '../utils/files';
import { Language } from '../stores';
import * as Lexc from '../types';
Expand All @@ -12,6 +12,21 @@
import { verifyHash } from '../utils/verification';
let tag: string = '';
let onlineFileVersion: string = '';
let localFileVersion: string = $Language.FileVersion;
async function getOnlineFileVersion() {
if (verifyHash($dbid, $dbkey)) {
let file = await retrieveFromDatabase();
if (file) {
return file.FileVersion;
} else return null;
}
}
async function setFileVersions() {
onlineFileVersion = await getOnlineFileVersion();
localFileVersion = $Language.FileVersion;
}
$: $fileLoadIncrement, setFileVersions();
userData(user_path => {
let settings = {
Expand Down Expand Up @@ -440,6 +455,11 @@
<span>Uploading is {$Language.UploadToDatabase? 'On' : 'Off'} for this file.
<input type=checkbox bind:checked={$Language.UploadToDatabase}/>
</span>
{#if $Language.UploadToDatabase && verifyHash($dbid, $dbkey)}
Local File Version: {localFileVersion} <br>
Online File Version: {onlineFileVersion} <br>
<button class='hover-highlight hover-shadow' on:click={setFileVersions}>Refresh</button>
{/if}
<span>User ID: <input class:pronunciation={disabledDatabase} type=text bind:value={inputID} disabled={disabledDatabase}/></span>
<br>
<span>Key: <input class:pronunciation={disabledDatabase} type=text bind:value={inputKey} disabled={disabledDatabase}/></span>
Expand Down
3 changes: 2 additions & 1 deletion src/app/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import EditorJS, { type OutputData } from '@editorjs/editorjs';
import type * as Lexc from './types';

const Default: Lexc.Language = {
Version: '2.1.0',
Version: '2.1.15',
FileVersion: '0',
Name: 'Unnamed Language',
CaseSensitive: false,
IgnoreDiacritics: true,
Expand Down
1 change: 1 addition & 0 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export type Orthography = {
*/
export type Language = {
Version: string;
FileVersion: string; // base 36 number
Name: string;
Lexicon: Lexicon;
Etymologies: Etymologies;
Expand Down
5 changes: 3 additions & 2 deletions src/app/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function collectExportData (): Promise<string> {
console.log('No save function found for docs editor.', get(docsEditor));
}
Lang().Version = await ipcRenderer.invoke('getVersion');
Lang().FileVersion = (parseInt(Lang().FileVersion, 36) + 1).toString(36);
return JSON.stringify(Lang());
}

Expand Down Expand Up @@ -146,10 +147,10 @@ export async function saveFile () {
new Notification(`The ${Lang().Name} file has been saved.`);
}
} catch (err) {
console.log(err);
vex.dialog.alert(
'There was a problem saving your file. Please contact the developer.'
'There was a problem saving your file. The error has been printed to the console. Please contact the developer.'
);
console.log(err);
}

// Save to database
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bundle/bundle.js.map

Large diffs are not rendered by default.

0 comments on commit d42d80f

Please sign in to comment.