79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dora
2 |
3 | Local drive, AI assisted deep search.
4 |
5 | **For a cloud managed version with agentic capabilities, please see [Dora](https://dorafiles.com)**
6 |
7 | 
8 |
9 |
10 | ## About
11 | Dora is a local search tool that allows you to search files on your local drive using natural language.
12 |
13 | ## Installation
14 |
15 | ### Pull Repo
16 | ```bash
17 | git clone https://github.com/space0blaster/dora.git
18 | cd dora
19 | ```
20 |
21 | ### With Docker
22 | I have provided a `compose.yaml` file so you have everything you need (services) to run Dora.
23 | The `compose.yaml` file includes Ollama and ChromaDB, that's all you need for Dora search.
24 |
25 | There is a start script called `start.sh`. This script is contains all the steps you need to run the `compose.yaml` and the electron app.
26 | The `start.sh` will do the following:
27 | 1. Spin up images with the `compose.yaml` file.
28 | 2. Pull the default models `nomic-embed-text` for embeddings and `artifish/llama3.2-uncensored` for chat search.
29 | 3. Install the Electron app dependencies.
30 | 4. Run the Electron app.
31 |
32 | **Important**: If you already have Ollama and/or ChromaDB running, please spin them down first. If not, the ports will have conflicts and it will not work. If you'd rather use your existing Ollama and/or ChromaDB services, see the Without Docker section below.
33 |
34 | To run the `start.sh` script:
35 | ```bash
36 | sh start.sh
37 | ```
38 |
39 |
40 | ### Without Docker
41 | Assuming you already have Ollama and ChromaDB installed and running, you can simply just run the below commands to run the electron app by itself.
42 | Please note, if you already have Ollama, be sure to pull `nomic-embed-text` and `artifish/llama3.2-uncensored` as they are used. If you'd like, you can run your own choice of embedding and chat models. Configure your config/settings modal with your models.
43 | Dora defaults to the default ports for both Ollama and ChromaDB, `11434` and `8000` respectively, and will point to `localhost` as a base host for both.
44 |
45 | To run the electron app:
46 | ```bash
47 | npm install
48 | npm start
49 | ```
50 |
51 | ---
52 |
53 | ### Initialization
54 | When the program runs initially, it will pop-up the Settings modal. Below are the fields:
55 |
56 | 
57 |
58 | 1. `Target Directory`: This is the base directory which will be the starting point for the crawler/indexing function. Default is your base user directory See note no. 1.
59 | 2. `Ollama Host`: The host where Ollama is located. Default is `localhost`.
60 | 3. `Ollama Port`: The port for Ollama. Default is `11434` which is the default Ollama port.
61 | 4. `Chroma Host`: The host where ChromaDB is located. Default is `8000` which is the default ChromaDB port.
62 | 5. `Embed Model`: The model used specifically to create embeddings. Default is `nomic-embed-text` and it will be automatically pulled if you use `start.sh` to install and Dora.
63 | 6. `Chat Model`: The model used for chat search. Default is `antifish/llama3.2-uncensored` and it will be pulled automatically if you use `start.sh` to install and run Dora.
64 |
65 | Click the Save button and you're ready to go.
66 |
67 | ### Changing Target Directory
68 | To change your `Target Directory`, which is where the program starts to crawl recursively, simple click on the gear icon on top right corner and enter whatever directory you want.
69 | This will reset the crawler and embed function.
70 | Use absolute paths.
71 |
72 | ---
73 |
74 | ### Packaging The App
75 | You can package the app for yourself as an application so you have an executable. Please note, if you do this, you'll still have to run the Docker images for the services for the executable to work.
76 |
77 | To package the app:
78 | ```bash
79 | npm run make
80 | ```
81 |
82 | This will output your executable to a new sub folder in the `dora` directory located in `dora/out` and then the folder specific to your system architecture.
83 |
84 | ---
85 |
86 | If you want an executable that is cloud-based using the latest SOTA models, please see [Dora](https://dorafiles.com).
87 |
88 | ## Notes
89 | 1. If you have a lot of files here, I recommend pointing it to something less dense so you can try Dora out first without the crawler running for a long time; you can change this later.
90 |
91 | * Allow the model to warm up on the first chat request. Especially if you're running this on a relatively weak machine.
92 | * Dora will create an application folder call `.dora` in your base user directory where it will store the above-mentioned configs, chat log and the indexed files.
93 | * I am using [artifish/llama3.2-uncensored](https://ollama.com/artifish/llama3.2-uncensored) because asking some models for private files freaks them out.
94 | * You can try and use other uncensored models, I picked this one because it's relatively small and does well locally.
95 | * You can also change your embedding model, the default `nomic-embed-text` does the job fine though. You can just use the embedding models that come with ChromaDB, just make sure you specify each time you embed and query.
96 |
97 | ## License
98 | Apache 2.0
99 |
100 |
--------------------------------------------------------------------------------
/src/scripts/files.js:
--------------------------------------------------------------------------------
1 | let indexedFiles=0;
2 | let embeddedMetadata=0;
3 |
4 | class DoraFiles {
5 | constructor() {
6 | this.indexPath=appDataDir+'/index.json';
7 | }
8 | showFiles(dir) {
9 | E.get('pathIndicator').innerHTML='';
10 | E.get('filesGrid').innerHTML='';
11 | let pathIndicator=E.get('pathIndicator');
12 | //
13 | let base=E.span(pathIndicator,'pathIndicatorFolder','');
14 | base.innerHTML='';
15 | base.onclick=()=>{
16 | this.showFiles(config.targetDirectory);
17 | };
18 | E.span(pathIndicator,'','').innerHTML=' / ';
19 | for(let i=1;i{
23 | let buildPath='';
24 | for(let j=1;j<=i;j++) {
25 | buildPath=buildPath+'/'+dir.split('/')[j];
26 | }
27 | this.showFiles(buildPath);
28 | };
29 | E.span(pathIndicator,'','').innerHTML=' / ';
30 | }
31 | //
32 | let filesGrid=E.get('filesGrid');
33 | fs.readdir(dir, async (err, files) => {
34 | if (files) {
35 | files.forEach((file) => {
36 | let isDir=DoraFiles.isDirectory(path.join(dir,file));
37 | let f=E.div(filesGrid, 'gridItem', '');
38 | if(file.split('.')[file.split('.').length - 1] === 'png') E.img(f, 'gridItemThumb', '', dir + '/' + file);
39 | else if(isDir) E.div(f, 'gridItemIcon', '').innerHTML = '';
40 | else E.div(f, 'gridItemIcon', '').innerHTML = '';
41 | E.div(f, 'gridItemName', '').innerHTML = T.s(file, 20);
42 | f.onclick=()=>{};
43 | f.addEventListener("dblclick", (e) => {
44 | e.preventDefault();
45 | if(isDir) this.showFiles(dir+'/'+file);
46 | else shell.openPath(dir+'/'+file);
47 | });
48 | });
49 | if(fs.existsSync(this.indexPath)) {
50 | if(JSON.parse(fs.readFileSync(this.indexPath)).targetDirectory===config.targetDirectory) {
51 | indexedFiles=JSON.parse(fs.readFileSync(this.indexPath)).files.length;
52 | const collection=await chroma.getCollection({name:md5(config.targetDirectory)});
53 | embeddedMetadata=await collection.count();
54 | E.get('indexed').innerHTML='Target Directory: '+config.targetDirectory+' Files Indexed: '+H.numberNotation(indexedFiles, {notation:'short'})+' Metadata Embedded: '+H.numberNotation(embeddedMetadata,{notation:'short'});
55 | }
56 | else this.indexDirectory();
57 | }
58 | else {
59 | this.indexDirectory();
60 | }
61 | }
62 | });
63 | }
64 | indexDirectory() {
65 | let indexed={
66 | targetDirectory:config.targetDirectory,
67 | model:config.embedModel,
68 | files:[]
69 | };
70 | function walk(dir) {
71 | let items=fs.readdirSync(dir);
72 | if(items && items.length>0) {
73 | items.forEach((item)=>{
74 | if(config.ignored.indexOf(item)===-1) {
75 | let isDir=DoraFiles.isDirectory(path.join(dir,item));
76 | if(isDir) walk(path.join(dir,item));
77 | else {
78 | let filePath=path.join(dir,item);
79 | indexed.files.push({name:item,isDirectory:isDir,path:filePath,embedded:false});
80 | indexedFiles++;
81 | E.get('indexed').innerHTML='Target Directory: '+config.targetDirectory+' Files Indexed: '+indexedFiles;
82 | }
83 | }
84 | });
85 | }
86 | }
87 | walk(config.targetDirectory);
88 | E.get('indexed').innerHTML='Target Directory: '+config.targetDirectory+' Files Indexed: '+H.numberNotation(indexedFiles,{notation:'short'});
89 | fs.writeFile(this.indexPath,JSON.stringify(indexed),()=>{
90 | this.embedToChroma(indexed.files).then(vector=>{
91 | E.get('indexed').innerHTML='Target Directory: '+config.targetDirectory+' Files Indexed: '+H.numberNotation(indexedFiles,{notation:'short'})+' Indexes Embedded: '+H.numberNotation(embeddedMetadata,{notation:'short'});
92 | });
93 | });
94 | };
95 | static isDirectory(filePath) {
96 | try {
97 | const stats=fs.statSync(filePath);
98 | return (stats.mode & fs.constants.S_IFDIR)===fs.constants.S_IFDIR;
99 | } catch (error) {
100 | return false;
101 | }
102 | }
103 | async embedToChroma(data) {
104 | //
105 | let ids=[];
106 | let vectors=[];
107 | let documents=[];
108 | for(let i=0;iTarget Directory: '+config.targetDirectory+' Files Indexed: '+H.numberNotation(indexedFiles,{notation:'short'})+' Metadata Embedded: '+embeddedMetadata+'/'+indexedFiles+' ('+(embeddedMetadata/indexedFiles*100).toFixed(2)+'%)';
116 | E.get('progressInner').style.width=Math.floor((embeddedMetadata/indexedFiles)*100)+'%';
117 | }
118 | const collection=await chroma.getOrCreateCollection({name: md5(config.targetDirectory)});
119 | await collection.add({ids:ids,embeddings:vectors,documents:documents});
120 | return true;
121 | }
122 | }
123 |
124 |
125 | let files=new DoraFiles();
126 | files.showFiles(config.targetDirectory);
127 |
128 |
129 | E.get('settings').onclick=()=>{
130 | ipcRenderer.send('open-settings',{});
131 | };
132 |
--------------------------------------------------------------------------------
/src/scripts/chat.js:
--------------------------------------------------------------------------------
1 | class DoraChat {
2 | constructor() {
3 | this.path=appDataDir+'/chat.json';
4 | this.systemPrompt="Your name is Dora, a local file search assistant. Respond in JSON format with results in an array called 'files' and your accompanying text response in a key called 'text'. Be brief.";
5 | }
6 | async startModel() {
7 | ollama.ps().then(async running=>{
8 | if(running.models.findIndex(x=>x.name===config.chatModel)===-1) {
9 | await ollama.create({model:config.chatModel,from:config.chatModel,system:this.systemPrompt});
10 | console.log('start new model');
11 | }
12 | else {
13 | await ollama.show({model:config.chatModel}).then(async model=>{
14 | if(model.system!==this.systemPrompt) {
15 | await ollama.create({model:config.chatModel,from:config.chatModel,system:this.systemPrompt});
16 | console.log('running model system prompt does not match, starting a new one');
17 | }
18 | else console.log('no need to start model, already running');
19 | });
20 | }
21 | });
22 | };
23 | history(chatHistory,chatTable) {
24 | fs.readFile(this.path, 'utf-8', (err, data) => {
25 | if(err){
26 | alert("An error reading history :" + err.message);
27 | return;
28 | }
29 | chatHistory=JSON.parse(data);
30 | for(let i=0;i';
41 | for(let i=0;i';
44 | f.onclick=()=>{
45 | shell.openPath(structuredReply.files[i][Object.keys(structuredReply.files[i])[1]]);
46 | };
47 | }
48 | r.scrollIntoView();
49 | }
50 | }
51 | //
52 | });
53 | };
54 | async query(chatHistory,prompt,promptEmbeddings,r) {
55 | const collection=await chroma.getCollection({name:md5(config.targetDirectory)});
56 | let nResults=10;
57 | if(await collection.count()<10) nResults=await collection.count();
58 | const queryData=await collection.query({
59 | queryEmbeddings:promptEmbeddings.embeddings,
60 | nResults:nResults
61 | });
62 | ollama.chat({model:config.chatModel,messages:[{role:"user",content:"Using this data: " + queryData['documents'][0] + ". Respond to this prompt: " + prompt}]}).then(reply=>{
63 | console.log(reply.message.content);
64 | try {
65 | let structuredReply=JSON.parse(reply.message.content);
66 | r.innerHTML='';
67 | r.innerHTML='
COULD NOT PARSE. Note: chat model could not follow stuctured output in this instance, so here is the raw output instead:
'+reply.message.content+'
';
83 | }
84 | });
85 |
86 | //
87 | };
88 | chat() {
89 | let chatHistory=[];
90 | E.get('response').innerHTML='';
91 | let chatTable=E.table(E.get('response'),'','chatTable','center','100%');
92 | //
93 | if(!fs.existsSync(this.path)){
94 | fs.writeFile(this.path+'/chat.json','[]',(err)=>{
95 | if(err) alert('Could not create file'+err);
96 | });
97 | }
98 | //
99 | this.history(chatHistory,chatTable);
100 |
101 | let input=document.getElementById('input');
102 | input.onkeydown=(e)=>{
103 | if(e.keyCode===13) {
104 | let q=E.div(E.tableC(E.tableR(chatTable),''),'inputText','');
105 | q.innerHTML=input.value;
106 | q.scrollIntoView();
107 | chatHistory.push({role:'user',content:input.value});
108 | let inputVal=input.value;
109 | input.value='';
110 | let r=E.div(E.tableC(E.tableR(chatTable),''),'responseBlock','');
111 | E.img(r,'responseLoad','','images/loading.gif').scrollIntoView();
112 | async function embedPrompt(){
113 | return await ollama.embed({model:config.embedModel,input:inputVal});
114 | }
115 | embedPrompt().then(promptEmbeddings=>{
116 | this.query(chatHistory,inputVal,promptEmbeddings,r);
117 | fs.writeFile(this.path, JSON.stringify(chatHistory),(err)=>{
118 | if(err) alert('Error saving session');
119 | });
120 | });
121 | }
122 | };
123 | //
124 | let clear=document.getElementById('clear');
125 | clear.onclick=()=>{
126 | fs.writeFile(this.path,'[]',(err)=>{
127 | if(err) alert('Could not create file'+err);
128 | this.chat();
129 | });
130 | };
131 | };
132 | }
133 | //
134 | const chat=new DoraChat();
135 | chat.startModel().then(()=>{
136 | chat.chat();
137 | });
138 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2025 AdulisAI, Inc.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/src/scripts/e.js:
--------------------------------------------------------------------------------
1 | class E {
2 | static get(id) {
3 | return document.getElementById(id);
4 | };
5 | static fetch(type,value) {
6 | let e;
7 | switch(type) {
8 | case 'className':
9 | e=document.getElementsByClassName(value);
10 | break;
11 | case 'tagName':
12 | e=document.getElementsByTagName(value);
13 | break;
14 | }
15 | return e;
16 | }
17 | static fetch2(parent,type,value) {
18 | let e;
19 | switch(type) {
20 | case 'className':
21 | e=parent.getElementsByClassName(value);
22 | break;
23 | case 'tagName':
24 | e=parent.getElementsByTagName(value);
25 | break;
26 | }
27 | return e;
28 | }
29 | static bool(e) {
30 | let val;
31 | if(e.checked===true) val=1;
32 | if(e.checked===false) val=0;
33 | return val;
34 | };
35 | static script(parent,src) {
36 | let e=document.createElement('div');
37 | parent.appendChild(e);
38 | e.src=src;
39 | return e;
40 | };
41 |
42 | static div(parent,className,id) {
43 | let e=document.createElement('div');
44 | parent.appendChild(e);
45 | e.className=className;
46 | e.id=id;
47 | return e;
48 | };
49 | static span(parent,className,id) {
50 | let e=document.createElement('span');
51 | parent.appendChild(e);
52 | e.className=className;
53 | e.id=id;
54 | return e;
55 | };
56 | static form(parent,method) {
57 | let e=document.createElement('form');
58 | parent.appendChild(e);
59 | e.method=method;
60 | return e;
61 | };
62 | static a(parent,className,id,href,target) {
63 | let e=document.createElement('a');
64 | parent.appendChild(e);
65 | e.className=className;
66 | e.id=id;
67 | e.href=href;
68 | if(target) e.target=target;
69 | return e;
70 | };
71 | static table(parent,className,id,align,width) {
72 | let e=document.createElement('table');
73 | parent.appendChild(e);
74 | e.className=className;
75 | e.id=id;
76 | e.align=align;
77 | e.width=width;
78 | return e;
79 | };
80 | static tableR(table) {
81 | return table.insertRow(table.rows.length);
82 | };
83 | static tableC(tr,width) {
84 | let e=tr.insertCell(tr.cells.length);
85 | e.width=width;
86 | return e;
87 | };
88 | static tableC2(tr,width,style) {
89 | let e=tr.insertCell(tr.cells.length);
90 | e.width=width;
91 | e.style.background=style.background;
92 | return e;
93 | };
94 | static tableH(tr,width) {
95 | let e=document.createElement('th');
96 | tr.appendChild(e);
97 | e.width=width;
98 | return e;
99 | };
100 | static tableH2(tr,colspan) {
101 | let e=document.createElement('th');
102 | tr.appendChild(e);
103 | e.colSpan=colspan;
104 | return e;
105 | };
106 | static tableHV(tr,rowspan) {
107 | let e=document.createElement('th');
108 | tr.appendChild(e);
109 | e.rowSpan=rowspan;
110 | return e;
111 | };
112 | static img(parent,className,id,src) {
113 | let e=document.createElement('img');
114 | parent.appendChild(e);
115 | e.className=className;
116 | e.id=id;
117 | e.src=src;
118 | return e;
119 | };
120 | static video(parent,className,id,src,ext) {
121 | let e=document.createElement('video');
122 | parent.appendChild(e);
123 | e.className=className;
124 | e.id=id;
125 | //e.innerHTML="";
126 | e.setAttribute("width", "1000");
127 | e.setAttribute("height", "450");
128 | e.setAttribute("controls","controls");
129 | let s=document.createElement('source');
130 | s.src=src;
131 | s.type='video/'+ext;
132 | e.appendChild(s);
133 | return e;
134 | };
135 | static audio(parent,className,id,src,ext) {
136 | let e=document.createElement('audio');
137 | parent.appendChild(e);
138 | e.className=className;
139 | e.id=id;
140 | e.setAttribute("controls","controls");
141 | let s=document.createElement('source');
142 | s.src=src;
143 | s.type='audio/'+ext;
144 | e.appendChild(s);
145 | //e.innerHTML="";
146 | return e;
147 | };
148 | static canvas(parent,className,id,width,height) {
149 | let e=document.createElement('canvas');
150 | parent.appendChild(e);
151 | e.className=className;
152 | e.id=id;
153 | e.width=width;
154 | e.height=height;
155 | e.style.width=width;
156 | e.style.height=height;
157 | return e;
158 | };
159 |
160 | static input(parent,type,className,id,placeholder) {
161 | let e=document.createElement('input');
162 | parent.appendChild(e);
163 | e.type=type;
164 | e.className=className;
165 | e.id=id;
166 | e.placeholder=placeholder;
167 | return e;
168 | };
169 | static textarea(parent,className,id,placeholder) {
170 | let e=document.createElement('textarea');
171 | parent.appendChild(e);
172 | e.className=className;
173 | e.id=id;
174 | e.placeholder=placeholder;
175 | return e;
176 | };
177 | static button(parent,className,id,text) {
178 | let e=document.createElement('button');
179 | parent.appendChild(e);
180 | e.className=className;
181 | e.id=id;
182 | e.innerHTML=text;
183 | return e;
184 | };
185 | static select(parent,className,id,options) {
186 | let e=document.createElement('select');
187 | parent.appendChild(e);
188 | e.className=className;
189 | e.id=id;
190 | if(options.length>0) {
191 | for(let i=0;ilimit) return text.substr(0,limit)+" ...";
449 | else return text;
450 | };
451 |
452 | // check empty
453 | static e(text) {
454 | if(text===null || text==='' || !text) return true;
455 | else return false;
456 | }
457 |
458 | static e404(url) {
459 | let http = new XMLHttpRequest();
460 | http.open('HEAD', url, false);
461 | http.send();
462 | if(http.status===404) return true;
463 | else return false;
464 | };
465 |
466 | static yn(val) {
467 | if(parseInt(val)===1) return 'YES';
468 | else return 'NO';
469 | };
470 |
471 | static nullOrNot(val) {
472 | if(val) return 'YES';
473 | else return 'NO';
474 | };
475 |
476 | static finishTime(startTime,hours) {
477 | let today=new Date(startTime).getTime()/1000;
478 | let nextDate=today+(hours*3600);
479 | let finishTime=new Date(nextDate*1000);
480 | return finishTime.toLocaleString('en-US',{hour:'numeric',minute:'numeric',hour12:true});
481 | };
482 |
483 | static isPrimary(isPrimary) {
484 | if(isPrimary===1) return 'Primary';
485 | else return 'Backup';
486 | };
487 | static active(active) {
488 | if(active===1) return 'Active';
489 | else return 'Inactive';
490 | };
491 | static required(required) {
492 | if(required===1) return 'Required';
493 | else return 'Optional';
494 | };
495 | static tagColor(hexColor) {
496 | const hex = hexColor.replace('#', '');
497 | const c_r = parseInt(hex.substr(0, 2), 16);
498 | const c_g = parseInt(hex.substr(2, 2), 16);
499 | const c_b = parseInt(hex.substr(4, 2), 16);
500 | const brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
501 | //return brightness > 155;
502 | if((brightness < 155)) return '#FFFFFF';
503 | else return '#222222';
504 | };
505 | static isMe(userId) {
506 | if(userId===currentUser.id) return ' Me';
507 | else return '';
508 | };
509 | static isOwner(isOwner) {
510 | if(parseInt(isOwner)===1) return ' Owner';
511 | else return '';
512 | };
513 |
514 | static isAdmin(isAdmin) {
515 | if(parseInt(isAdmin)===1) return ' Admin';
516 | else return '';
517 | };
518 | static isCurrent(isCurrent) {
519 | if(parseInt(isCurrent)===1) return ' This Session';
520 | else return '';
521 | };
522 | static isDefault(isDefault) {
523 | if(parseInt(isDefault)===1) return ' Default';
524 | else return '';
525 | };
526 | static sourceMethod(method) {
527 | if(method) return ''+method.toUpperCase()+' ';
528 | else return '';
529 | };
530 | static isObjectEmpty(obj) {
531 | for(const prop in obj) {
532 | if(Object.hasOwn(obj,prop)) {
533 | return false;
534 | }
535 | }
536 | return true;
537 | }
538 | static hasParam(obj,param) {
539 | if(obj) {
540 | if(obj[param]) return obj[param];
541 | }
542 | return 'n/a';
543 | }
544 | }
545 | class I {
546 | static search(box,searchTerm) {
547 | let boxes=box.getElementsByClassName('gridItem');
548 | for(let i=0;i<=boxes.length;i++) {
549 | if(boxes[i].innerHTML.toUpperCase().indexOf(searchTerm.toUpperCase())>-1) {
550 | boxes[i].style.display='unset';
551 | }
552 | else {
553 | boxes[i].style.display='none';
554 | }
555 | }
556 | };
557 | }
--------------------------------------------------------------------------------