Compare commits
	
		
			138 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 7c9ac488e8 | ||
|  | fec1574447 | ||
|  | f7587de452 | ||
|  | 41a6e777ea | ||
|  | 8fb0de900b | ||
|  | a40bf71fd4 | ||
|  | 2a53bb03ae | ||
|  | a684879b91 | ||
|  | ddbd4f73c8 | ||
|  | b0ed790edf | ||
|  | 3424406ff1 | ||
|  | ce5c385c15 | ||
|  | cd9eef32b0 | ||
|  | 12d82e3b33 | ||
|  | f071d3f651 | ||
|  | 297b536ebc | ||
|  | 7cca2d9247 | ||
|  | 36dc802d16 | ||
|  | c78ddb70cb | ||
|  | 9fb0599c45 | ||
|  | 13f524fb39 | ||
|  | 27be3b4c90 | ||
|  | af4ea66742 | ||
|  | 0f42c396f3 | ||
|  | 9e96272eb3 | ||
|  | 965dbcbc9a | ||
|  | 7ac109e7f7 | ||
|  | ac25770c0e | ||
|  | 5b15424498 | ||
|  | f1240c26bf | ||
|  | 1c0fd243d1 | ||
|  | 3491235533 | ||
|  | 5f36856571 | ||
|  | d3e44b37e9 | ||
|  | 90e9297ec5 | ||
|  | c568ef2f8a | ||
|  | fcf6141cde | ||
|  | 21551d7b77 | ||
|  | 12031d369f | ||
|  | b44c523845 | ||
|  | 49989695ff | ||
|  | a55d3530e9 | ||
|  | 2aab3ad281 | ||
|  | 194ce4f10f | ||
|  | 2089c32839 | ||
|  | f437be7af0 | ||
|  | 96dc56098d | ||
|  | 61987e46f7 | ||
|  | 509093b755 | ||
|  | 097114c0f2 | ||
|  | 040f9185f8 | ||
|  | 6dc934abbe | ||
|  | 2d24bf81dd | ||
|  | 9452fc236b | ||
|  | 365c37604b | ||
|  | 01c7e58d47 | ||
|  | d3d49923b1 | ||
|  | 263ac299d0 | ||
|  | 3d185a5178 | ||
|  | 2ff7a890bc | ||
|  | 2eb1a9705f | ||
|  | ed1381103a | ||
|  | 170d317589 | ||
|  | ededc063df | ||
|  | 986eace1be | ||
|  | 29086d8dfe | ||
|  | 9b3f3fde05 | ||
|  | 6a50afd952 | ||
|  | 697eee2706 | ||
|  | 8a95afd756 | ||
|  | 4d6eda8fe6 | ||
|  | e4f459fa2b | ||
|  | f578e001b0 | ||
|  | 2a08aef885 | ||
|  | 7564bf388c | ||
|  | 7e4d70259f | ||
|  | 5b98c1c0f3 | ||
|  | 02dc7b199b | ||
|  | d39cdbfada | ||
|  | 50bb4a47ee | ||
|  | a4627f2ddb | ||
|  | c8253caae9 | ||
|  | 0ece9bd1be | ||
|  | b6935abcc9 | ||
|  | 37ab7b4641 | ||
|  | 013714cb5c | ||
|  | 1fe7c62f5a | ||
|  | a06618d851 | ||
|  | e7460ca3a9 | ||
|  | 073300bbcd | ||
|  | a201661ce5 | ||
|  | 6235a3c886 | ||
|  | 3972c27e7a | ||
|  | 14cffbbe62 | ||
|  | 599c3c04af | ||
|  | f1412b631d | ||
|  | 41908050bb | ||
|  | f07033423c | ||
|  | daf96fcbf2 | ||
|  | 2bca94529e | ||
|  | b2c9a0da21 | ||
|  | 7a9542b4fc | ||
|  | 3a95c9e1bc | ||
|  | 3d2ef6be01 | ||
|  | d67246699a | ||
|  | 14c704d6db | ||
|  | 4c8eeb2e6f | ||
|  | c1b245c8b1 | ||
|  | 74202d67bb | ||
|  | 26066f39b1 | ||
|  | b255cf190c | ||
|  | bc77b143b0 | ||
|  | 9f0ff6ae7a | ||
|  | 736704c7d6 | ||
|  | 654c116c58 | ||
|  | 89a5cab98f | ||
|  | c39d0be8cd | ||
|  | e75b4cd848 | ||
|  | 378e8f35e5 | ||
|  | bdb5e2f13f | ||
|  | 8211bed449 | ||
|  | b243632483 | ||
|  | e4d2513451 | ||
|  | 385144451b | ||
|  | c8c533844e | ||
|  | 0e69f0c079 | ||
|  | aee60c444f | ||
|  | e7a504c66b | ||
|  | 45d9c7164c | ||
|  | bd913a63a8 | ||
|  | 5a1938c078 | ||
|  | 015cd68756 | ||
|  | 76c0e5b2b8 | ||
|  | 0f8f707acd | ||
|  | 083cccea28 | ||
|  | 31b76b23ce | ||
|  | af529f82e5 | ||
|  | fc6669d254 | 
							
								
								
									
										4
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,4 @@ | |||||||
|  | node_modules | ||||||
|  | npm-debug.log | ||||||
|  | dist | ||||||
|  | .idea | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <dataSource name="document.db"> | <dataSource name="document.db"> | ||||||
|   <database-model serializer="dbm" rdbms="SQLITE" format-version="4.9"> |   <database-model serializer="dbm" rdbms="SQLITE" format-version="4.11"> | ||||||
|     <root id="1"> |     <root id="1"> | ||||||
|       <ServerVersion>3.16.1</ServerVersion> |       <ServerVersion>3.16.1</ServerVersion> | ||||||
|     </root> |     </root> | ||||||
| @@ -12,10 +12,10 @@ | |||||||
|     <collation id="4" parent="1" name="NOCASE"/> |     <collation id="4" parent="1" name="NOCASE"/> | ||||||
|     <collation id="5" parent="1" name="RTRIM"/> |     <collation id="5" parent="1" name="RTRIM"/> | ||||||
|     <table id="6" parent="2" name="api_tokens"/> |     <table id="6" parent="2" name="api_tokens"/> | ||||||
|     <table id="7" parent="2" name="branches"/> |     <table id="7" parent="2" name="attributes"/> | ||||||
|     <table id="8" parent="2" name="event_log"/> |     <table id="8" parent="2" name="branches"/> | ||||||
|     <table id="9" parent="2" name="images"/> |     <table id="9" parent="2" name="event_log"/> | ||||||
|     <table id="10" parent="2" name="labels"/> |     <table id="10" parent="2" name="images"/> | ||||||
|     <table id="11" parent="2" name="note_images"/> |     <table id="11" parent="2" name="note_images"/> | ||||||
|     <table id="12" parent="2" name="note_revisions"/> |     <table id="12" parent="2" name="note_revisions"/> | ||||||
|     <table id="13" parent="2" name="notes"/> |     <table id="13" parent="2" name="notes"/> | ||||||
| @@ -59,7 +59,6 @@ | |||||||
|     <index id="25" parent="6" name="sqlite_autoindex_api_tokens_1"> |     <index id="25" parent="6" name="sqlite_autoindex_api_tokens_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>apiTokenId</ColNames> |       <ColNames>apiTokenId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="26" parent="6"> |     <key id="26" parent="6"> | ||||||
| @@ -67,7 +66,7 @@ | |||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_api_tokens_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_api_tokens_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="27" parent="7" name="branchId"> |     <column id="27" parent="7" name="attributeId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
| @@ -77,589 +76,574 @@ | |||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="29" parent="7" name="parentNoteId"> |     <column id="29" parent="7" name="type"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="30" parent="7" name="notePosition"> |     <column id="30" parent="7" name="name"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>INTEGER|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="31" parent="7" name="prefix"> |     <column id="31" parent="7" name="value"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |       <DefaultExpression>''</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="32" parent="7" name="isExpanded"> |     <column id="32" parent="7" name="position"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>BOOLEAN|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|     </column> |  | ||||||
|     <column id="33" parent="7" name="isDeleted"> |  | ||||||
|       <Position>7</Position> |  | ||||||
|       <DataType>INTEGER|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|  |     <column id="33" parent="7" name="dateCreated"> | ||||||
|  |       <Position>7</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|     <column id="34" parent="7" name="dateModified"> |     <column id="34" parent="7" name="dateModified"> | ||||||
|       <Position>8</Position> |       <Position>8</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="35" parent="7" name="hash"> |     <column id="35" parent="7" name="isDeleted"> | ||||||
|  |       <Position>9</Position> | ||||||
|  |       <DataType>INT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="36" parent="7" name="hash"> | ||||||
|  |       <Position>10</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |       <DefaultExpression>""</DefaultExpression> | ||||||
|  |     </column> | ||||||
|  |     <column id="37" parent="7" name="isInheritable"> | ||||||
|  |       <Position>11</Position> | ||||||
|  |       <DataType>int|0s</DataType> | ||||||
|  |       <DefaultExpression>0</DefaultExpression> | ||||||
|  |     </column> | ||||||
|  |     <index id="38" parent="7" name="sqlite_autoindex_attributes_1"> | ||||||
|  |       <NameSurrogate>1</NameSurrogate> | ||||||
|  |       <ColNames>attributeId</ColNames> | ||||||
|  |       <Unique>1</Unique> | ||||||
|  |     </index> | ||||||
|  |     <key id="39" parent="7"> | ||||||
|  |       <ColNames>attributeId</ColNames> | ||||||
|  |       <Primary>1</Primary> | ||||||
|  |       <UnderlyingIndexName>sqlite_autoindex_attributes_1</UnderlyingIndexName> | ||||||
|  |     </key> | ||||||
|  |     <column id="40" parent="8" name="branchId"> | ||||||
|  |       <Position>1</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="41" parent="8" name="noteId"> | ||||||
|  |       <Position>2</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="42" parent="8" name="parentNoteId"> | ||||||
|  |       <Position>3</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="43" parent="8" name="notePosition"> | ||||||
|  |       <Position>4</Position> | ||||||
|  |       <DataType>INTEGER|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="44" parent="8" name="prefix"> | ||||||
|  |       <Position>5</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |     </column> | ||||||
|  |     <column id="45" parent="8" name="isExpanded"> | ||||||
|  |       <Position>6</Position> | ||||||
|  |       <DataType>BOOLEAN|0s</DataType> | ||||||
|  |     </column> | ||||||
|  |     <column id="46" parent="8" name="isDeleted"> | ||||||
|  |       <Position>7</Position> | ||||||
|  |       <DataType>INTEGER|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |       <DefaultExpression>0</DefaultExpression> | ||||||
|  |     </column> | ||||||
|  |     <column id="47" parent="8" name="dateModified"> | ||||||
|  |       <Position>8</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="48" parent="8" name="hash"> | ||||||
|       <Position>9</Position> |       <Position>9</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="36" parent="7" name="dateCreated"> |     <column id="49" parent="8" name="dateCreated"> | ||||||
|       <Position>10</Position> |       <Position>10</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>'1970-01-01T00:00:00.000Z'</DefaultExpression> |       <DefaultExpression>'1970-01-01T00:00:00.000Z'</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="37" parent="7" name="sqlite_autoindex_branches_1"> |     <index id="50" parent="8" name="sqlite_autoindex_branches_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="38" parent="7" name="IDX_branches_noteId_parentNoteId"> |     <index id="51" parent="8" name="IDX_branches_noteId_parentNoteId"> | ||||||
|       <ColNames>noteId |       <ColNames>noteId | ||||||
| parentNoteId</ColNames> | parentNoteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="39" parent="7" name="IDX_branches_noteId"> |     <index id="52" parent="8" name="IDX_branches_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="40" parent="7" name="IDX_branches_parentNoteId"> |     <index id="53" parent="8" name="IDX_branches_parentNoteId"> | ||||||
|       <ColNames>parentNoteId</ColNames> |       <ColNames>parentNoteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="41" parent="7"> |     <key id="54" parent="8"> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_branches_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_branches_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="42" parent="8" name="id"> |     <column id="55" parent="9" name="eventId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>INTEGER|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <SequenceIdentity>1</SequenceIdentity> |  | ||||||
|     </column> |     </column> | ||||||
|     <column id="43" parent="8" name="noteId"> |     <column id="56" parent="9" name="noteId"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="44" parent="8" name="comment"> |     <column id="57" parent="9" name="comment"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="45" parent="8" name="dateCreated"> |     <column id="58" parent="9" name="dateCreated"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <key id="46" parent="8"> |     <index id="59" parent="9" name="sqlite_autoindex_event_log_1"> | ||||||
|       <ColNames>id</ColNames> |       <NameSurrogate>1</NameSurrogate> | ||||||
|  |       <ColNames>eventId</ColNames> | ||||||
|  |       <Unique>1</Unique> | ||||||
|  |     </index> | ||||||
|  |     <key id="60" parent="9"> | ||||||
|  |       <ColNames>eventId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|  |       <UnderlyingIndexName>sqlite_autoindex_event_log_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="47" parent="9" name="imageId"> |     <column id="61" parent="10" name="imageId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="48" parent="9" name="format"> |     <column id="62" parent="10" name="format"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="49" parent="9" name="checksum"> |     <column id="63" parent="10" name="checksum"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="50" parent="9" name="name"> |     <column id="64" parent="10" name="name"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="51" parent="9" name="data"> |     <column id="65" parent="10" name="data"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>BLOB|0s</DataType> |       <DataType>BLOB|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="52" parent="9" name="isDeleted"> |     <column id="66" parent="10" name="isDeleted"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="53" parent="9" name="dateModified"> |     <column id="67" parent="10" name="dateModified"> | ||||||
|       <Position>7</Position> |       <Position>7</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="54" parent="9" name="dateCreated"> |     <column id="68" parent="10" name="dateCreated"> | ||||||
|       <Position>8</Position> |       <Position>8</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="55" parent="9" name="hash"> |     <column id="69" parent="10" name="hash"> | ||||||
|       <Position>9</Position> |       <Position>9</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="56" parent="9" name="sqlite_autoindex_images_1"> |     <index id="70" parent="10" name="sqlite_autoindex_images_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>imageId</ColNames> |       <ColNames>imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="57" parent="9"> |     <key id="71" parent="10"> | ||||||
|       <ColNames>imageId</ColNames> |       <ColNames>imageId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_images_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_images_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="58" parent="10" name="labelId"> |     <column id="72" parent="11" name="noteImageId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="59" parent="10" name="noteId"> |     <column id="73" parent="11" name="noteId"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="60" parent="10" name="name"> |     <column id="74" parent="11" name="imageId"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="61" parent="10" name="value"> |     <column id="75" parent="11" name="isDeleted"> | ||||||
|       <Position>4</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|       <DefaultExpression>''</DefaultExpression> |  | ||||||
|     </column> |  | ||||||
|     <column id="62" parent="10" name="position"> |  | ||||||
|       <Position>5</Position> |  | ||||||
|       <DataType>INT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|       <DefaultExpression>0</DefaultExpression> |  | ||||||
|     </column> |  | ||||||
|     <column id="63" parent="10" name="dateCreated"> |  | ||||||
|       <Position>6</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="64" parent="10" name="dateModified"> |  | ||||||
|       <Position>7</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="65" parent="10" name="isDeleted"> |  | ||||||
|       <Position>8</Position> |  | ||||||
|       <DataType>INT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="66" parent="10" name="hash"> |  | ||||||
|       <Position>9</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|       <DefaultExpression>""</DefaultExpression> |  | ||||||
|     </column> |  | ||||||
|     <index id="67" parent="10" name="sqlite_autoindex_labels_1"> |  | ||||||
|       <NameSurrogate>1</NameSurrogate> |  | ||||||
|       <ColNames>labelId</ColNames> |  | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |  | ||||||
|     </index> |  | ||||||
|     <index id="68" parent="10" name="IDX_labels_noteId"> |  | ||||||
|       <ColNames>noteId</ColNames> |  | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |  | ||||||
|     <index id="69" parent="10" name="IDX_labels_name_value"> |  | ||||||
|       <ColNames>name |  | ||||||
| value</ColNames> |  | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |  | ||||||
|     <key id="70" parent="10"> |  | ||||||
|       <ColNames>labelId</ColNames> |  | ||||||
|       <Primary>1</Primary> |  | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_labels_1</UnderlyingIndexName> |  | ||||||
|     </key> |  | ||||||
|     <column id="71" parent="11" name="noteImageId"> |  | ||||||
|       <Position>1</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="72" parent="11" name="noteId"> |  | ||||||
|       <Position>2</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="73" parent="11" name="imageId"> |  | ||||||
|       <Position>3</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|     </column> |  | ||||||
|     <column id="74" parent="11" name="isDeleted"> |  | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="75" parent="11" name="dateModified"> |     <column id="76" parent="11" name="dateModified"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="76" parent="11" name="dateCreated"> |     <column id="77" parent="11" name="dateCreated"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="77" parent="11" name="hash"> |     <column id="78" parent="11" name="hash"> | ||||||
|       <Position>7</Position> |       <Position>7</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="78" parent="11" name="sqlite_autoindex_note_images_1"> |     <index id="79" parent="11" name="sqlite_autoindex_note_images_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteImageId</ColNames> |       <ColNames>noteImageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="79" parent="11" name="IDX_note_images_noteId_imageId"> |     <index id="80" parent="11" name="IDX_note_images_noteId_imageId"> | ||||||
|       <ColNames>noteId |       <ColNames>noteId | ||||||
| imageId</ColNames> | imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="80" parent="11" name="IDX_note_images_noteId"> |     <index id="81" parent="11" name="IDX_note_images_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="81" parent="11" name="IDX_note_images_imageId"> |     <index id="82" parent="11" name="IDX_note_images_imageId"> | ||||||
|       <ColNames>imageId</ColNames> |       <ColNames>imageId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="82" parent="11"> |     <key id="83" parent="11"> | ||||||
|       <ColNames>noteImageId</ColNames> |       <ColNames>noteImageId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_note_images_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_note_images_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="83" parent="12" name="noteRevisionId"> |     <column id="84" parent="12" name="noteRevisionId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="84" parent="12" name="noteId"> |     <column id="85" parent="12" name="noteId"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="85" parent="12" name="title"> |     <column id="86" parent="12" name="title"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="86" parent="12" name="content"> |     <column id="87" parent="12" name="content"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="87" parent="12" name="isProtected"> |     <column id="88" parent="12" name="isProtected"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="88" parent="12" name="dateModifiedFrom"> |     <column id="89" parent="12" name="dateModifiedFrom"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="89" parent="12" name="dateModifiedTo"> |     <column id="90" parent="12" name="dateModifiedTo"> | ||||||
|       <Position>7</Position> |       <Position>7</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="90" parent="12" name="type"> |     <column id="91" parent="12" name="type"> | ||||||
|       <Position>8</Position> |       <Position>8</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>''</DefaultExpression> |       <DefaultExpression>''</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="91" parent="12" name="mime"> |     <column id="92" parent="12" name="mime"> | ||||||
|       <Position>9</Position> |       <Position>9</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>''</DefaultExpression> |       <DefaultExpression>''</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="92" parent="12" name="hash"> |     <column id="93" parent="12" name="hash"> | ||||||
|       <Position>10</Position> |       <Position>10</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="93" parent="12" name="sqlite_autoindex_note_revisions_1"> |     <index id="94" parent="12" name="sqlite_autoindex_note_revisions_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteRevisionId</ColNames> |       <ColNames>noteRevisionId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="94" parent="12" name="IDX_note_revisions_noteId"> |     <index id="95" parent="12" name="IDX_note_revisions_noteId"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="95" parent="12" name="IDX_note_revisions_dateModifiedFrom"> |     <index id="96" parent="12" name="IDX_note_revisions_dateModifiedFrom"> | ||||||
|       <ColNames>dateModifiedFrom</ColNames> |       <ColNames>dateModifiedFrom</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <index id="96" parent="12" name="IDX_note_revisions_dateModifiedTo"> |     <index id="97" parent="12" name="IDX_note_revisions_dateModifiedTo"> | ||||||
|       <ColNames>dateModifiedTo</ColNames> |       <ColNames>dateModifiedTo</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="97" parent="12"> |     <key id="98" parent="12"> | ||||||
|       <ColNames>noteRevisionId</ColNames> |       <ColNames>noteRevisionId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_note_revisions_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_note_revisions_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="98" parent="13" name="noteId"> |     <column id="99" parent="13" name="noteId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="99" parent="13" name="title"> |     <column id="100" parent="13" name="title"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>"unnamed"</DefaultExpression> |       <DefaultExpression>"unnamed"</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="100" parent="13" name="content"> |     <column id="101" parent="13" name="content"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="101" parent="13" name="isProtected"> |     <column id="102" parent="13" name="isProtected"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="102" parent="13" name="isDeleted"> |     <column id="103" parent="13" name="isDeleted"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="103" parent="13" name="dateCreated"> |     <column id="104" parent="13" name="dateCreated"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="104" parent="13" name="dateModified"> |     <column id="105" parent="13" name="dateModified"> | ||||||
|       <Position>7</Position> |       <Position>7</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="105" parent="13" name="type"> |     <column id="106" parent="13" name="type"> | ||||||
|       <Position>8</Position> |       <Position>8</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>'text'</DefaultExpression> |       <DefaultExpression>'text'</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="106" parent="13" name="mime"> |     <column id="107" parent="13" name="mime"> | ||||||
|       <Position>9</Position> |       <Position>9</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>'text/html'</DefaultExpression> |       <DefaultExpression>'text/html'</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="107" parent="13" name="hash"> |     <column id="108" parent="13" name="hash"> | ||||||
|       <Position>10</Position> |       <Position>10</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="108" parent="13" name="sqlite_autoindex_notes_1"> |     <index id="109" parent="13" name="sqlite_autoindex_notes_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="109" parent="13" name="IDX_notes_type"> |     <index id="110" parent="13" name="IDX_notes_type"> | ||||||
|       <ColNames>type</ColNames> |       <ColNames>type</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="110" parent="13"> |     <key id="111" parent="13"> | ||||||
|       <ColNames>noteId</ColNames> |       <ColNames>noteId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_notes_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_notes_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="111" parent="14" name="name"> |     <column id="112" parent="14" name="name"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="112" parent="14" name="value"> |     <column id="113" parent="14" name="value"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="113" parent="14" name="dateModified"> |     <column id="114" parent="14" name="dateModified"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>INT|0s</DataType> |       <DataType>INT|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="114" parent="14" name="isSynced"> |     <column id="115" parent="14" name="isSynced"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>INTEGER|0s</DataType> |       <DataType>INTEGER|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>0</DefaultExpression> |       <DefaultExpression>0</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="115" parent="14" name="hash"> |     <column id="116" parent="14" name="hash"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <column id="116" parent="14" name="dateCreated"> |     <column id="117" parent="14" name="dateCreated"> | ||||||
|       <Position>6</Position> |       <Position>6</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <DefaultExpression>'1970-01-01T00:00:00.000Z'</DefaultExpression> |       <DefaultExpression>'1970-01-01T00:00:00.000Z'</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="117" parent="14" name="sqlite_autoindex_options_1"> |     <index id="118" parent="14" name="sqlite_autoindex_options_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>name</ColNames> |       <ColNames>name</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="118" parent="14"> |     <key id="119" parent="14"> | ||||||
|       <ColNames>name</ColNames> |       <ColNames>name</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_options_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_options_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="119" parent="15" name="branchId"> |     <column id="120" parent="15" name="branchId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="120" parent="15" name="notePath"> |     <column id="121" parent="15" name="notePath"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="121" parent="15" name="dateCreated"> |     <column id="122" parent="15" name="hash"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |  | ||||||
|     <column id="122" parent="15" name="isDeleted"> |  | ||||||
|       <Position>4</Position> |  | ||||||
|       <DataType>INT|0s</DataType> |  | ||||||
|     </column> |  | ||||||
|     <column id="123" parent="15" name="hash"> |  | ||||||
|       <Position>5</Position> |  | ||||||
|       <DataType>TEXT|0s</DataType> |  | ||||||
|       <NotNull>1</NotNull> |  | ||||||
|       <DefaultExpression>""</DefaultExpression> |       <DefaultExpression>""</DefaultExpression> | ||||||
|     </column> |     </column> | ||||||
|     <index id="124" parent="15" name="sqlite_autoindex_recent_notes_1"> |     <column id="123" parent="15" name="dateCreated"> | ||||||
|  |       <Position>4</Position> | ||||||
|  |       <DataType>TEXT|0s</DataType> | ||||||
|  |       <NotNull>1</NotNull> | ||||||
|  |     </column> | ||||||
|  |     <column id="124" parent="15" name="isDeleted"> | ||||||
|  |       <Position>5</Position> | ||||||
|  |       <DataType>INT|0s</DataType> | ||||||
|  |     </column> | ||||||
|  |     <index id="125" parent="15" name="sqlite_autoindex_recent_notes_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="125" parent="15"> |     <key id="126" parent="15"> | ||||||
|       <ColNames>branchId</ColNames> |       <ColNames>branchId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_recent_notes_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_recent_notes_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="126" parent="16" name="sourceId"> |     <column id="127" parent="16" name="sourceId"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="127" parent="16" name="dateCreated"> |     <column id="128" parent="16" name="dateCreated"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <index id="128" parent="16" name="sqlite_autoindex_source_ids_1"> |     <index id="129" parent="16" name="sqlite_autoindex_source_ids_1"> | ||||||
|       <NameSurrogate>1</NameSurrogate> |       <NameSurrogate>1</NameSurrogate> | ||||||
|       <ColNames>sourceId</ColNames> |       <ColNames>sourceId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <key id="129" parent="16"> |     <key id="130" parent="16"> | ||||||
|       <ColNames>sourceId</ColNames> |       <ColNames>sourceId</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|       <UnderlyingIndexName>sqlite_autoindex_source_ids_1</UnderlyingIndexName> |       <UnderlyingIndexName>sqlite_autoindex_source_ids_1</UnderlyingIndexName> | ||||||
|     </key> |     </key> | ||||||
|     <column id="130" parent="17" name="type"> |     <column id="131" parent="17" name="type"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>text|0s</DataType> |       <DataType>text|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="131" parent="17" name="name"> |     <column id="132" parent="17" name="name"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>text|0s</DataType> |       <DataType>text|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="132" parent="17" name="tbl_name"> |     <column id="133" parent="17" name="tbl_name"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>text|0s</DataType> |       <DataType>text|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="133" parent="17" name="rootpage"> |     <column id="134" parent="17" name="rootpage"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>integer|0s</DataType> |       <DataType>integer|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="134" parent="17" name="sql"> |     <column id="135" parent="17" name="sql"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>text|0s</DataType> |       <DataType>text|0s</DataType> | ||||||
|     </column> |     </column> | ||||||
|     <column id="135" parent="18" name="name"> |     <column id="136" parent="18" name="name"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|     </column> |     </column> | ||||||
|     <column id="136" parent="18" name="seq"> |     <column id="137" parent="18" name="seq"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|     </column> |     </column> | ||||||
|     <column id="137" parent="19" name="id"> |     <column id="138" parent="19" name="id"> | ||||||
|       <Position>1</Position> |       <Position>1</Position> | ||||||
|       <DataType>INTEGER|0s</DataType> |       <DataType>INTEGER|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|       <SequenceIdentity>1</SequenceIdentity> |       <SequenceIdentity>1</SequenceIdentity> | ||||||
|     </column> |     </column> | ||||||
|     <column id="138" parent="19" name="entityName"> |     <column id="139" parent="19" name="entityName"> | ||||||
|       <Position>2</Position> |       <Position>2</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="139" parent="19" name="entityId"> |     <column id="140" parent="19" name="entityId"> | ||||||
|       <Position>3</Position> |       <Position>3</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="140" parent="19" name="sourceId"> |     <column id="141" parent="19" name="sourceId"> | ||||||
|       <Position>4</Position> |       <Position>4</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <column id="141" parent="19" name="syncDate"> |     <column id="142" parent="19" name="syncDate"> | ||||||
|       <Position>5</Position> |       <Position>5</Position> | ||||||
|       <DataType>TEXT|0s</DataType> |       <DataType>TEXT|0s</DataType> | ||||||
|       <NotNull>1</NotNull> |       <NotNull>1</NotNull> | ||||||
|     </column> |     </column> | ||||||
|     <index id="142" parent="19" name="IDX_sync_entityName_entityId"> |     <index id="143" parent="19" name="IDX_sync_entityName_entityId"> | ||||||
|       <ColNames>entityName |       <ColNames>entityName | ||||||
| entityId</ColNames> | entityId</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|       <Unique>1</Unique> |       <Unique>1</Unique> | ||||||
|     </index> |     </index> | ||||||
|     <index id="143" parent="19" name="IDX_sync_syncDate"> |     <index id="144" parent="19" name="IDX_sync_syncDate"> | ||||||
|       <ColNames>syncDate</ColNames> |       <ColNames>syncDate</ColNames> | ||||||
|       <ColumnCollations></ColumnCollations> |  | ||||||
|     </index> |     </index> | ||||||
|     <key id="144" parent="19"> |     <key id="145" parent="19"> | ||||||
|       <ColNames>id</ColNames> |       <ColNames>id</ColNames> | ||||||
|       <Primary>1</Primary> |       <Primary>1</Primary> | ||||||
|     </key> |     </key> | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								.idea/sqldialects.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="SqlDialectMappings"> | ||||||
|  |     <file url="PROJECT" dialect="SQLite" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										21
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,21 @@ | |||||||
|  | FROM node:8.11.2 | ||||||
|  |  | ||||||
|  | RUN apt-get update && apt-get install -y nasm | ||||||
|  |  | ||||||
|  | # Create app directory | ||||||
|  | WORKDIR /usr/src/app | ||||||
|  |  | ||||||
|  | # Install app dependencies | ||||||
|  | # A wildcard is used to ensure both package.json AND package-lock.json are copied | ||||||
|  | # where available (npm@5+) | ||||||
|  | COPY package*.json ./ | ||||||
|  |  | ||||||
|  | RUN npm install --production | ||||||
|  | # If you are building your code for production | ||||||
|  | # RUN npm install --only=production | ||||||
|  |  | ||||||
|  | # Bundle app source | ||||||
|  | COPY . . | ||||||
|  |  | ||||||
|  | EXPOSE 8080 | ||||||
|  | CMD [ "node", "src/www" ] | ||||||
							
								
								
									
										8
									
								
								bin/build-docker.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						| @@ -0,0 +1,8 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | if [[ $# -eq 0 ]] ; then | ||||||
|  |     echo "Missing argument of new version" | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | sudo docker build -t zadam/trilium:latest -t zadam/trilium:$1 . | ||||||
							
								
								
									
										23
									
								
								bin/build-pkg.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						| @@ -0,0 +1,23 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | if [[ $# -eq 0 ]] ; then | ||||||
|  |     echo "Missing argument of new version" | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | VERSION=$1 | ||||||
|  |  | ||||||
|  | PKG_DIR=dist/trilium-linux-x64-server | ||||||
|  |  | ||||||
|  | mkdir $PKG_DIR | ||||||
|  |  | ||||||
|  | pkg . --targets node8-linux-x64 --output ${PKG_DIR}/trilium | ||||||
|  |  | ||||||
|  | chmod +x ${PKG_DIR}/trilium | ||||||
|  |  | ||||||
|  | cp node_modules/sqlite3/lib/binding/node-v57-linux-x64/node_sqlite3.node ${PKG_DIR}/ | ||||||
|  | cp node_modules/scrypt/build/Release/scrypt.node ${PKG_DIR}/ | ||||||
|  |  | ||||||
|  | cd dist | ||||||
|  |  | ||||||
|  | 7z a trilium-linux-x64-${VERSION}-server.7z trilium-linux-x64-server | ||||||
							
								
								
									
										9
									
								
								bin/push-docker-image.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						| @@ -0,0 +1,9 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | if [[ $# -eq 0 ]] ; then | ||||||
|  |     echo "Missing argument of new version" | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | sudo docker push zadam/trilium:latest | ||||||
|  | sudo docker push zadam/trilium:$1 | ||||||
| @@ -47,6 +47,7 @@ bin/package.sh | |||||||
| LINUX_X64_BUILD=trilium-linux-x64-$VERSION.7z | LINUX_X64_BUILD=trilium-linux-x64-$VERSION.7z | ||||||
| LINUX_IA32_BUILD=trilium-linux-ia32-$VERSION.7z | LINUX_IA32_BUILD=trilium-linux-ia32-$VERSION.7z | ||||||
| WINDOWS_X64_BUILD=trilium-windows-x64-$VERSION.7z | WINDOWS_X64_BUILD=trilium-windows-x64-$VERSION.7z | ||||||
|  | SERVER_BUILD=trilium-linux-x64-server.elf | ||||||
|  |  | ||||||
| echo "Creating release in GitHub" | echo "Creating release in GitHub" | ||||||
|  |  | ||||||
| @@ -75,4 +76,21 @@ github-release upload \ | |||||||
|     --name "$WINDOWS_X64_BUILD" \ |     --name "$WINDOWS_X64_BUILD" \ | ||||||
|     --file "dist/$WINDOWS_X64_BUILD" |     --file "dist/$WINDOWS_X64_BUILD" | ||||||
|  |  | ||||||
|  | echo "Packaging server version" | ||||||
|  |  | ||||||
|  | bin/build-pkg.sh $VERSION | ||||||
|  |  | ||||||
|  | github-release upload \ | ||||||
|  |     --tag $TAG \ | ||||||
|  |     --name "$SERVER_BUILD" \ | ||||||
|  |     --file "dist/$SERVER_BUILD" | ||||||
|  |  | ||||||
|  | echo "Building docker image" | ||||||
|  |  | ||||||
|  | bin/build-docker.sh $VERSION | ||||||
|  |  | ||||||
|  | echo "Pushing docker image to dockerhub" | ||||||
|  |  | ||||||
|  | bin/push-docker-image.sh $VERSION | ||||||
|  |  | ||||||
| echo "Release finished!" | echo "Release finished!" | ||||||
| @@ -3,15 +3,10 @@ | |||||||
| instanceName= | instanceName= | ||||||
|  |  | ||||||
| [Network] | [Network] | ||||||
|  | # port setting is relevant only for web deployments, desktop builds run on random free port | ||||||
| port=8080 | port=8080 | ||||||
| # true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure). | # true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure). | ||||||
| https=false | https=false | ||||||
| # path to certificate (run "bash generate-cert.sh" to generate self-signed certificate). Relevant only if https=true | # path to certificate (run "bash generate-cert.sh" to generate self-signed certificate). Relevant only if https=true | ||||||
| certPath= | certPath= | ||||||
| keyPath= | keyPath= | ||||||
|  |  | ||||||
| [Sync] |  | ||||||
| syncServerHost= |  | ||||||
| syncServerTimeout=10000 |  | ||||||
| syncProxy= |  | ||||||
| syncServerCertificate= |  | ||||||
							
								
								
									
										2
									
								
								db/migrations/0097__add_zoomFactor.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,2 @@ | |||||||
|  | INSERT INTO options (optionId, name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('zoomFactor_key', 'zoomFactor', '1.0', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
							
								
								
									
										1
									
								
								db/migrations/0098__rename_hideInAutocomplete.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1 @@ | |||||||
|  | UPDATE labels SET name = 'archived' WHERE name = 'hideInAutocomplete' | ||||||
							
								
								
									
										2
									
								
								db/migrations/0099__add_theme_option.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,2 @@ | |||||||
|  | INSERT INTO options (optionId, name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('theme_key', 'theme', 'white', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
							
								
								
									
										15
									
								
								db/migrations/0100__remove_optionId.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,15 @@ | |||||||
|  | create table options_mig | ||||||
|  | ( | ||||||
|  |   name TEXT not null PRIMARY KEY, | ||||||
|  |   value TEXT, | ||||||
|  |   dateModified INT, | ||||||
|  |   isSynced INTEGER default 0 not null, | ||||||
|  |   hash TEXT default "" not null, | ||||||
|  |   dateCreated TEXT default '1970-01-01T00:00:00.000Z' not null | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | INSERT INTO options_mig (name, value, dateModified, isSynced, hash, dateCreated) | ||||||
|  | SELECT name, value, dateModified, isSynced, hash, dateCreated FROM options; | ||||||
|  |  | ||||||
|  | DROP TABLE options; | ||||||
|  | ALTER TABLE options_mig RENAME TO options; | ||||||
							
								
								
									
										8
									
								
								db/migrations/0101__add_sync_options.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,8 @@ | |||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('syncServerHost', '', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
|  |  | ||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('syncServerTimeout', '5000', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
|  |  | ||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('syncProxy', '', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
							
								
								
									
										2
									
								
								db/migrations/0102__fix_sync_entityIds.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,2 @@ | |||||||
|  | DELETE FROM sync WHERE entityName = 'note_tree'; | ||||||
|  | DELETE FROM sync WHERE entityName = 'attributes'; | ||||||
							
								
								
									
										2
									
								
								db/migrations/0103__add_initialized_option.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,2 @@ | |||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('initialized', 'true', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0); | ||||||
							
								
								
									
										4
									
								
								db/migrations/0104__fill_sync_rows_for_options.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,4 @@ | |||||||
|  | const syncTableService = require('../../src/services/sync_table'); | ||||||
|  |  | ||||||
|  | // options has not been filled so far which caused problems with clean-slate sync. | ||||||
|  | module.exports = async () => await syncTableService.fillAllSyncRows(); | ||||||
| @@ -0,0 +1,2 @@ | |||||||
|  | UPDATE notes SET content = '' WHERE isDeleted = 1; | ||||||
|  | UPDATE note_revisions SET content = '' WHERE (SELECT isDeleted FROM notes WHERE noteId = note_revisions.noteId) = 1; | ||||||
							
								
								
									
										15
									
								
								db/migrations/0106__add_relations_table.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,15 @@ | |||||||
|  | CREATE TABLE relations | ||||||
|  | ( | ||||||
|  |     relationId  TEXT not null primary key, | ||||||
|  |     sourceNoteId       TEXT not null, | ||||||
|  |     name         TEXT not null, | ||||||
|  |     targetNoteId        TEXT not null, | ||||||
|  |     position     INT  default 0 not null, | ||||||
|  |     dateCreated  TEXT not null, | ||||||
|  |     dateModified TEXT not null, | ||||||
|  |     isDeleted    INT  not null | ||||||
|  |   , hash TEXT DEFAULT "" NOT NULL); | ||||||
|  | CREATE INDEX IDX_relation_sourceNoteId | ||||||
|  |   on relations (sourceNoteId); | ||||||
|  | CREATE INDEX IDX_relation_targetNoteId | ||||||
|  |   on relations (targetNoteId); | ||||||
| @@ -0,0 +1 @@ | |||||||
|  | ALTER TABLE relations ADD isInheritable int DEFAULT 0 NULL; | ||||||
							
								
								
									
										9
									
								
								db/migrations/0108__new_backup_options.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,9 @@ | |||||||
|  | UPDATE options SET name = 'lastDailyBackupDate' WHERE name = 'lastBackupDate'; | ||||||
|  |  | ||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('lastWeeklyBackupDate', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); | ||||||
|  |  | ||||||
|  | INSERT INTO options (name, value, dateCreated, dateModified, isSynced) | ||||||
|  | VALUES ('lastMonthlyBackupDate', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0); | ||||||
|  |  | ||||||
|  | -- these options are not synced so no need to fix sync rows | ||||||
							
								
								
									
										27
									
								
								db/migrations/0109__create_attributes.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,27 @@ | |||||||
|  | create table attributes | ||||||
|  | ( | ||||||
|  |   attributeId      TEXT not null primary key, | ||||||
|  |   noteId       TEXT not null, | ||||||
|  |   type         TEXT not null, | ||||||
|  |   name         TEXT not null, | ||||||
|  |   value        TEXT default '' not null, | ||||||
|  |   position     INT  default 0 not null, | ||||||
|  |   dateCreated  TEXT not null, | ||||||
|  |   dateModified TEXT not null, | ||||||
|  |   isDeleted    INT  not null, | ||||||
|  |   hash         TEXT default "" not null); | ||||||
|  |  | ||||||
|  | create index IDX_attributes_name_value | ||||||
|  |   on labels (name, value); | ||||||
|  |  | ||||||
|  | create index IDX_attributes_value | ||||||
|  |   on labels (value); | ||||||
|  |  | ||||||
|  | create index IDX_attributes_noteId | ||||||
|  |   on labels (noteId); | ||||||
|  |  | ||||||
|  | INSERT INTO attributes (attributeId, noteId, type, name, value, position, dateCreated, dateModified, isDeleted, hash) | ||||||
|  | SELECT labelId, noteId, 'label', name, value, position, dateCreated, dateModified, isDeleted, hash FROM labels; | ||||||
|  |  | ||||||
|  | INSERT INTO attributes (attributeId, noteId, type, name, value, position, dateCreated, dateModified, isDeleted, hash) | ||||||
|  | SELECT relationId, sourceNoteId, 'relation', name, targetNoteId, position, dateCreated, dateModified, isDeleted, hash FROM relations; | ||||||
							
								
								
									
										1
									
								
								db/migrations/0110__add_isInheritable_to_attributes.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1 @@ | |||||||
|  | ALTER TABLE attributes ADD isInheritable int DEFAULT 0 NULL; | ||||||
							
								
								
									
										4
									
								
								db/migrations/0111__cleanup_labels_and_relations.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,4 @@ | |||||||
|  | DROP TABLE relations; | ||||||
|  | DROP TABLE labels; | ||||||
|  |  | ||||||
|  | DELETE FROM sync WHERE entityName = 'relations' OR entityName = 'labels'; | ||||||
| @@ -1,8 +1,3 @@ | |||||||
| CREATE TABLE IF NOT EXISTS "options" ( |  | ||||||
|     `name`	TEXT NOT NULL PRIMARY KEY, |  | ||||||
|     `value`	TEXT, |  | ||||||
|     `dateModified` INT, |  | ||||||
|     isSynced INTEGER NOT NULL DEFAULT 0); |  | ||||||
| CREATE TABLE IF NOT EXISTS "sync" ( | CREATE TABLE IF NOT EXISTS "sync" ( | ||||||
|   `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |   `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||||||
|   `entityName`	TEXT NOT NULL, |   `entityName`	TEXT NOT NULL, | ||||||
| @@ -29,7 +24,7 @@ CREATE TABLE IF NOT EXISTS "note_revisions" ( | |||||||
|   `isProtected`	INT NOT NULL DEFAULT 0, |   `isProtected`	INT NOT NULL DEFAULT 0, | ||||||
|   `dateModifiedFrom` TEXT NOT NULL, |   `dateModifiedFrom` TEXT NOT NULL, | ||||||
|   `dateModifiedTo` TEXT NOT NULL |   `dateModifiedTo` TEXT NOT NULL | ||||||
| , type TEXT DEFAULT '' NOT NULL, mime TEXT DEFAULT '' NOT NULL); | , type TEXT DEFAULT '' NOT NULL, mime TEXT DEFAULT '' NOT NULL, hash TEXT DEFAULT "" NOT NULL); | ||||||
| CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` ( | CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` ( | ||||||
|   `noteId` |   `noteId` | ||||||
| ); | ); | ||||||
| @@ -49,7 +44,7 @@ CREATE TABLE IF NOT EXISTS "images" | |||||||
|   isDeleted INT NOT NULL DEFAULT 0, |   isDeleted INT NOT NULL DEFAULT 0, | ||||||
|   dateModified TEXT NOT NULL, |   dateModified TEXT NOT NULL, | ||||||
|   dateCreated TEXT NOT NULL |   dateCreated TEXT NOT NULL | ||||||
| ); | , hash TEXT DEFAULT "" NOT NULL); | ||||||
| CREATE TABLE note_images | CREATE TABLE note_images | ||||||
| ( | ( | ||||||
|   noteImageId TEXT PRIMARY KEY NOT NULL, |   noteImageId TEXT PRIMARY KEY NOT NULL, | ||||||
| @@ -58,7 +53,7 @@ CREATE TABLE note_images | |||||||
|   isDeleted INT NOT NULL DEFAULT 0, |   isDeleted INT NOT NULL DEFAULT 0, | ||||||
|   dateModified TEXT NOT NULL, |   dateModified TEXT NOT NULL, | ||||||
|   dateCreated TEXT NOT NULL |   dateCreated TEXT NOT NULL | ||||||
| ); | , hash TEXT DEFAULT "" NOT NULL); | ||||||
| CREATE INDEX IDX_note_images_noteId ON note_images (noteId); | CREATE INDEX IDX_note_images_noteId ON note_images (noteId); | ||||||
| CREATE INDEX IDX_note_images_imageId ON note_images (imageId); | CREATE INDEX IDX_note_images_imageId ON note_images (imageId); | ||||||
| CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId); | CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId); | ||||||
| @@ -68,7 +63,7 @@ CREATE TABLE IF NOT EXISTS "api_tokens" | |||||||
|   token TEXT NOT NULL, |   token TEXT NOT NULL, | ||||||
|   dateCreated TEXT NOT NULL, |   dateCreated TEXT NOT NULL, | ||||||
|   isDeleted INT NOT NULL DEFAULT 0 |   isDeleted INT NOT NULL DEFAULT 0 | ||||||
| ); | , hash TEXT DEFAULT "" NOT NULL); | ||||||
| CREATE TABLE IF NOT EXISTS "branches" ( | CREATE TABLE IF NOT EXISTS "branches" ( | ||||||
|   `branchId`	TEXT NOT NULL, |   `branchId`	TEXT NOT NULL, | ||||||
|   `noteId`	TEXT NOT NULL, |   `noteId`	TEXT NOT NULL, | ||||||
| @@ -77,7 +72,7 @@ CREATE TABLE IF NOT EXISTS "branches" ( | |||||||
|   `prefix`	TEXT, |   `prefix`	TEXT, | ||||||
|   `isExpanded`	BOOLEAN, |   `isExpanded`	BOOLEAN, | ||||||
|   `isDeleted`	INTEGER NOT NULL DEFAULT 0, |   `isDeleted`	INTEGER NOT NULL DEFAULT 0, | ||||||
|   `dateModified`	TEXT NOT NULL, |   `dateModified`	TEXT NOT NULL, hash TEXT DEFAULT "" NOT NULL, dateCreated TEXT NOT NULL DEFAULT '1970-01-01T00:00:00.000Z', | ||||||
|   PRIMARY KEY(`branchId`) |   PRIMARY KEY(`branchId`) | ||||||
| ); | ); | ||||||
| CREATE INDEX `IDX_branches_noteId` ON `branches` ( | CREATE INDEX `IDX_branches_noteId` ON `branches` ( | ||||||
| @@ -87,34 +82,6 @@ CREATE INDEX `IDX_branches_noteId_parentNoteId` ON `branches` ( | |||||||
|   `noteId`, |   `noteId`, | ||||||
|   `parentNoteId` |   `parentNoteId` | ||||||
| ); | ); | ||||||
| CREATE TABLE IF NOT EXISTS "recent_notes" ( |  | ||||||
|   `branchId` TEXT NOT NULL PRIMARY KEY, |  | ||||||
|   `notePath` TEXT NOT NULL, |  | ||||||
|   `dateAccessed` TEXT NOT NULL, |  | ||||||
|   isDeleted INT |  | ||||||
| ); |  | ||||||
| CREATE TABLE labels |  | ||||||
| ( |  | ||||||
|   labelId  TEXT not null primary key, |  | ||||||
|   noteId       TEXT not null, |  | ||||||
|   name         TEXT not null, |  | ||||||
|   value        TEXT default '' not null, |  | ||||||
|   position     INT  default 0 not null, |  | ||||||
|   dateCreated  TEXT not null, |  | ||||||
|   dateModified TEXT not null, |  | ||||||
|   isDeleted    INT  not null |  | ||||||
| ); |  | ||||||
| CREATE INDEX IDX_labels_name_value |  | ||||||
|   on labels (name, value); |  | ||||||
| CREATE INDEX IDX_labels_noteId |  | ||||||
|   on labels (noteId); |  | ||||||
| CREATE TABLE IF NOT EXISTS "event_log" |  | ||||||
| ( |  | ||||||
|   id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |  | ||||||
|   noteId TEXT, |  | ||||||
|   comment TEXT, |  | ||||||
|   dateAdded TEXT NOT NULL |  | ||||||
| ); |  | ||||||
| CREATE TABLE IF NOT EXISTS "notes" ( | CREATE TABLE IF NOT EXISTS "notes" ( | ||||||
|   `noteId`	TEXT NOT NULL, |   `noteId`	TEXT NOT NULL, | ||||||
|   `title`	TEXT NOT NULL DEFAULT "unnamed", |   `title`	TEXT NOT NULL DEFAULT "unnamed", | ||||||
| @@ -124,9 +91,43 @@ CREATE TABLE IF NOT EXISTS "notes" ( | |||||||
|   `dateCreated`	TEXT NOT NULL, |   `dateCreated`	TEXT NOT NULL, | ||||||
|   `dateModified`	TEXT NOT NULL, |   `dateModified`	TEXT NOT NULL, | ||||||
|   type TEXT NOT NULL DEFAULT 'text', |   type TEXT NOT NULL DEFAULT 'text', | ||||||
|   mime TEXT NOT NULL DEFAULT 'text/html', |   mime TEXT NOT NULL DEFAULT 'text/html', hash TEXT DEFAULT "" NOT NULL, | ||||||
|   PRIMARY KEY(`noteId`) |   PRIMARY KEY(`noteId`) | ||||||
| ); | ); | ||||||
| CREATE INDEX `IDX_notes_isDeleted` ON `notes` ( | CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId); | ||||||
|   `isDeleted` | CREATE INDEX IDX_notes_type | ||||||
|  |   on notes (type); | ||||||
|  | CREATE TABLE IF NOT EXISTS "recent_notes" ( | ||||||
|  |   `branchId` TEXT NOT NULL PRIMARY KEY, | ||||||
|  |   `notePath` TEXT NOT NULL, | ||||||
|  |   hash TEXT DEFAULT "" NOT NULL, | ||||||
|  |   `dateCreated` TEXT NOT NULL, | ||||||
|  |   isDeleted INT | ||||||
| ); | ); | ||||||
|  | CREATE TABLE IF NOT EXISTS "event_log" ( | ||||||
|  |   `eventId`	TEXT NOT NULL PRIMARY KEY, | ||||||
|  |   `noteId`	TEXT, | ||||||
|  |   `comment`	TEXT, | ||||||
|  |   `dateCreated`	TEXT NOT NULL | ||||||
|  | ); | ||||||
|  | CREATE TABLE IF NOT EXISTS "options" | ||||||
|  | ( | ||||||
|  |   name TEXT not null PRIMARY KEY, | ||||||
|  |   value TEXT, | ||||||
|  |   dateModified INT, | ||||||
|  |   isSynced INTEGER default 0 not null, | ||||||
|  |   hash TEXT default "" not null, | ||||||
|  |   dateCreated TEXT default '1970-01-01T00:00:00.000Z' not null | ||||||
|  | ); | ||||||
|  | CREATE TABLE attributes | ||||||
|  | ( | ||||||
|  |   attributeId      TEXT not null primary key, | ||||||
|  |   noteId       TEXT not null, | ||||||
|  |   type         TEXT not null, | ||||||
|  |   name         TEXT not null, | ||||||
|  |   value        TEXT default '' not null, | ||||||
|  |   position     INT  default 0 not null, | ||||||
|  |   dateCreated  TEXT not null, | ||||||
|  |   dateModified TEXT not null, | ||||||
|  |   isDeleted    INT  not null, | ||||||
|  |   hash         TEXT default "" not null, isInheritable int DEFAULT 0 NULL); | ||||||
|   | |||||||
| @@ -2,9 +2,9 @@ | |||||||
|  |  | ||||||
| const electron = require('electron'); | const electron = require('electron'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const config = require('./src/services/config'); |  | ||||||
| const log = require('./src/services/log'); | const log = require('./src/services/log'); | ||||||
| const url = require("url"); | const url = require("url"); | ||||||
|  | const port = require('./src/services/port'); | ||||||
|  |  | ||||||
| const app = electron.app; | const app = electron.app; | ||||||
| const globalShortcut = electron.globalShortcut; | const globalShortcut = electron.globalShortcut; | ||||||
| @@ -23,7 +23,7 @@ function onClosed() { | |||||||
|     mainWindow = null; |     mainWindow = null; | ||||||
| } | } | ||||||
|  |  | ||||||
| function createMainWindow() { | async function createMainWindow() { | ||||||
|     const win = new electron.BrowserWindow({ |     const win = new electron.BrowserWindow({ | ||||||
|         width: 1200, |         width: 1200, | ||||||
|         height: 900, |         height: 900, | ||||||
| @@ -31,10 +31,8 @@ function createMainWindow() { | |||||||
|         icon: path.join(__dirname, 'src/public/images/app-icons/png/256x256.png') |         icon: path.join(__dirname, 'src/public/images/app-icons/png/256x256.png') | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     const port = config['Network']['port'] || '3000'; |  | ||||||
|  |  | ||||||
|     win.setMenu(null); |     win.setMenu(null); | ||||||
|     win.loadURL('http://localhost:' + port); |     win.loadURL('http://localhost:' + await port); | ||||||
|     win.on('closed', onClosed); |     win.on('closed', onClosed); | ||||||
|  |  | ||||||
|     win.webContents.on('new-window', (e, url) => { |     win.webContents.on('new-window', (e, url) => { | ||||||
|   | |||||||
							
								
								
									
										5992
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
							
								
								
									
										49
									
								
								package.json
									
									
									
									
									
								
							
							
						
						| @@ -1,9 +1,12 @@ | |||||||
| { | { | ||||||
|   "name": "trilium", |   "name": "trilium", | ||||||
|   "description": "Trilium Notes", |   "description": "Trilium Notes", | ||||||
|   "version": "0.14.0", |   "version": "0.19.0", | ||||||
|   "license": "AGPL-3.0-only", |   "license": "AGPL-3.0-only", | ||||||
|   "main": "electron.js", |   "main": "electron.js", | ||||||
|  |   "bin": { | ||||||
|  |     "trilium": "./src/www" | ||||||
|  |   }, | ||||||
|   "repository": { |   "repository": { | ||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "https://github.com/zadam/trilium.git" |     "url": "https://github.com/zadam/trilium.git" | ||||||
| @@ -28,23 +31,24 @@ | |||||||
|     "debug": "~3.1.0", |     "debug": "~3.1.0", | ||||||
|     "devtron": "^1.4.0", |     "devtron": "^1.4.0", | ||||||
|     "ejs": "~2.6.1", |     "ejs": "~2.6.1", | ||||||
|     "electron-debug": "^1.5.0", |     "electron-debug": "^2.0.0", | ||||||
|     "electron-dl": "^1.12.0", |     "electron-dl": "^1.12.0", | ||||||
|     "electron-in-page-search": "^1.3.2", |     "electron-in-page-search": "^1.3.2", | ||||||
|     "express": "~4.16.3", |     "express": "~4.16.3", | ||||||
|     "express-session": "^1.15.6", |     "express-session": "^1.15.6", | ||||||
|     "fs-extra": "^6.0.1", |     "fs-extra": "^7.0.0", | ||||||
|     "helmet": "^3.12.1", |     "get-port": "^4.0.0", | ||||||
|  |     "helmet": "^3.13.0", | ||||||
|     "html": "^1.0.0", |     "html": "^1.0.0", | ||||||
|     "image-type": "^3.0.0", |     "image-type": "^3.0.0", | ||||||
|     "imagemin": "^5.3.1", |     "imagemin": "^6.0.0", | ||||||
|     "imagemin-giflossy": "^5.1.10", |     "imagemin-giflossy": "^5.1.10", | ||||||
|     "imagemin-mozjpeg": "^7.0.0", |     "imagemin-mozjpeg": "^7.0.0", | ||||||
|     "imagemin-pngquant": "^5.1.0", |     "imagemin-pngquant": "^6.0.0", | ||||||
|     "ini": "^1.3.5", |     "ini": "^1.3.5", | ||||||
|     "jimp": "^0.2.28", |     "jimp": "^0.3.0", | ||||||
|     "moment": "^2.22.1", |     "moment": "^2.22.2", | ||||||
|     "multer": "^1.3.0", |     "multer": "^1.3.1", | ||||||
|     "open": "0.0.5", |     "open": "0.0.5", | ||||||
|     "rand-token": "^0.4.0", |     "rand-token": "^0.4.0", | ||||||
|     "rcedit": "^1.1.0", |     "rcedit": "^1.1.0", | ||||||
| @@ -59,18 +63,19 @@ | |||||||
|     "sqlite": "^2.9.2", |     "sqlite": "^2.9.2", | ||||||
|     "tar-stream": "^1.6.1", |     "tar-stream": "^1.6.1", | ||||||
|     "unescape": "^1.0.1", |     "unescape": "^1.0.1", | ||||||
|     "ws": "^5.2.0", |     "ws": "^6.0.0", | ||||||
|     "xml2js": "^0.4.19" |     "xml2js": "^0.4.19" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "electron": "^2.0.1", |     "electron": "^2.0.6", | ||||||
|     "electron-compile": "^6.4.2", |     "electron-compile": "^6.4.3", | ||||||
|     "electron-packager": "^12.1.0", |     "electron-packager": "^12.1.0", | ||||||
|     "electron-prebuilt-compile": "2.0.0", |     "electron-prebuilt-compile": "2.0.6", | ||||||
|     "electron-rebuild": "^1.7.3", |     "electron-rebuild": "^1.8.2", | ||||||
|     "lorem-ipsum": "^1.0.4", |     "lorem-ipsum": "^1.0.5", | ||||||
|     "tape": "^4.9.0", |     "tape": "^4.9.1", | ||||||
|     "xo": "^0.21.1" |     "xo": "^0.21.1", | ||||||
|  |     "pkg": "^4.3.3" | ||||||
|   }, |   }, | ||||||
|   "config": { |   "config": { | ||||||
|     "forge": { |     "forge": { | ||||||
| @@ -109,5 +114,15 @@ | |||||||
|       "node", |       "node", | ||||||
|       "browser" |       "browser" | ||||||
|     ] |     ] | ||||||
|  |   }, | ||||||
|  |   "pkg": { | ||||||
|  |     "assets": [ | ||||||
|  |       "./db/**/*", | ||||||
|  |       "./src/public/**/*", | ||||||
|  |       "./src/views/**/*", | ||||||
|  |       "./node_modules/mozjpeg/vendor/*", | ||||||
|  |       "./node_modules/pngquant-bin/vendor/*", | ||||||
|  |       "./node_modules/giflossy/vendor/*" | ||||||
|  |     ] | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ const os = require('os'); | |||||||
| const sessionSecret = require('./services/session_secret'); | const sessionSecret = require('./services/session_secret'); | ||||||
| const cls = require('./services/cls'); | const cls = require('./services/cls'); | ||||||
| require('./entities/entity_constructor'); | require('./entities/entity_constructor'); | ||||||
|  | require('./services/handlers'); | ||||||
|  |  | ||||||
| const app = express(); | const app = express(); | ||||||
|  |  | ||||||
| @@ -47,7 +48,7 @@ const sessionParser = session({ | |||||||
|     cookie: { |     cookie: { | ||||||
|         //    path: "/", |         //    path: "/", | ||||||
|         httpOnly: true, |         httpOnly: true, | ||||||
|         maxAge:  1800000 |         maxAge:  24 * 60 * 60 * 1000 // in milliseconds | ||||||
|     }, |     }, | ||||||
|     store: new FileStore({ |     store: new FileStore({ | ||||||
|         ttl: 30 * 24 * 3600, |         ttl: 30 * 24 * 3600, | ||||||
|   | |||||||
| @@ -9,8 +9,6 @@ class ApiToken extends Entity { | |||||||
|     static get hashedProperties() { return ["apiTokenId", "token", "dateCreated", "isDeleted"]; } |     static get hashedProperties() { return ["apiTokenId", "token", "dateCreated", "isDeleted"]; } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (!this.isDeleted) { |         if (!this.isDeleted) { | ||||||
|             this.isDeleted = false; |             this.isDeleted = false; | ||||||
|         } |         } | ||||||
| @@ -18,6 +16,8 @@ class ApiToken extends Entity { | |||||||
|         if (!this.dateCreated) { |         if (!this.dateCreated) { | ||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         super.beforeSaving(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										77
									
								
								src/entities/attribute.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,77 @@ | |||||||
|  | "use strict"; | ||||||
|  |  | ||||||
|  | const Entity = require('./entity'); | ||||||
|  | const repository = require('../services/repository'); | ||||||
|  | const dateUtils = require('../services/date_utils'); | ||||||
|  | const sql = require('../services/sql'); | ||||||
|  |  | ||||||
|  | class Attribute extends Entity { | ||||||
|  |     static get tableName() { return "attributes"; } | ||||||
|  |     static get primaryKeyName() { return "attributeId"; } | ||||||
|  |     static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable", "isDeleted", "dateCreated"]; } | ||||||
|  |  | ||||||
|  |     constructor(row) { | ||||||
|  |         super(row); | ||||||
|  |  | ||||||
|  |         this.isInheritable = !!this.isInheritable; | ||||||
|  |  | ||||||
|  |         if (this.isDefinition()) { | ||||||
|  |             try { | ||||||
|  |                 this.value = JSON.parse(this.value); | ||||||
|  |             } | ||||||
|  |             catch (e) { | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async getNote() { | ||||||
|  |         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async getTargetNote() { | ||||||
|  |         if (this.type !== 'relation') { | ||||||
|  |             throw new Error(`Attribute ${this.attributeId} is not relation`); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!this.value) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.value]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     isDefinition() { | ||||||
|  |         return this.type === 'label-definition' || this.type === 'relation-definition'; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async beforeSaving() { | ||||||
|  |         if (!this.value) { | ||||||
|  |             // null value isn't allowed | ||||||
|  |             this.value = ""; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (this.position === undefined) { | ||||||
|  |             this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM attributes WHERE noteId = ?`, [this.noteId]); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!this.isInheritable) { | ||||||
|  |             this.isInheritable = false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!this.isDeleted) { | ||||||
|  |             this.isDeleted = false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!this.dateCreated) { | ||||||
|  |             this.dateCreated = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         super.beforeSaving(); | ||||||
|  |  | ||||||
|  |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | module.exports = Attribute; | ||||||
| @@ -9,15 +9,13 @@ class Branch extends Entity { | |||||||
|     static get tableName() { return "branches"; } |     static get tableName() { return "branches"; } | ||||||
|     static get primaryKeyName() { return "branchId"; } |     static get primaryKeyName() { return "branchId"; } | ||||||
|     // notePosition is not part of hash because it would produce a lot of updates in case of reordering |     // notePosition is not part of hash because it would produce a lot of updates in case of reordering | ||||||
|     static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "dateModified", "isDeleted", "prefix"]; } |     static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "isDeleted", "prefix"]; } | ||||||
|  |  | ||||||
|     async getNote() { |     async getNote() { | ||||||
|         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); |         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async beforeSaving() { |     async beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (this.notePosition === undefined) { |         if (this.notePosition === undefined) { | ||||||
|             const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [this.parentNoteId]); |             const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [this.parentNoteId]); | ||||||
|             this.notePosition = maxNotePos === null ? 0 : maxNotePos + 1; |             this.notePosition = maxNotePos === null ? 0 : maxNotePos + 1; | ||||||
| @@ -31,7 +29,11 @@ class Branch extends Entity { | |||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |         super.beforeSaving(); | ||||||
|  |  | ||||||
|  |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,13 +1,16 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const utils = require('../services/utils'); | const utils = require('../services/utils'); | ||||||
| const repository = require('../services/repository'); |  | ||||||
|  |  | ||||||
| class Entity { | class Entity { | ||||||
|     constructor(row = {}) { |     constructor(row = {}) { | ||||||
|         for (const key in row) { |         for (const key in row) { | ||||||
|             this[key] = row[key]; |             this[key] = row[key]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if ('isDeleted' in this) { | ||||||
|  |             this.isDeleted = !!this.isDeleted; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
| @@ -15,20 +18,25 @@ class Entity { | |||||||
|             this[this.constructor.primaryKeyName] = utils.newEntityId(); |             this[this.constructor.primaryKeyName] = utils.newEntityId(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         const origHash = this.hash; | ||||||
|  |  | ||||||
|  |         this.hash = this.generateHash(); | ||||||
|  |  | ||||||
|  |         this.isChanged = origHash !== this.hash; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     generateHash() { | ||||||
|         let contentToHash = ""; |         let contentToHash = ""; | ||||||
|  |  | ||||||
|         for (const propertyName of this.constructor.hashedProperties) { |         for (const propertyName of this.constructor.hashedProperties) { | ||||||
|             contentToHash += "|" + this[propertyName]; |             contentToHash += "|" + this[propertyName]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // this IF is to ease the migration from before hashed options, can be later removed |         return utils.hash(contentToHash).substr(0, 10); | ||||||
|         if (this.constructor.tableName !== 'options' || this.isSynced) { |  | ||||||
|             this["hash"] = utils.hash(contentToHash).substr(0, 10); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async save() { |     async save() { | ||||||
|         await repository.updateEntity(this); |         await require('../services/repository').updateEntity(this); | ||||||
|  |  | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,17 +3,37 @@ const NoteRevision = require('../entities/note_revision'); | |||||||
| const Image = require('../entities/image'); | const Image = require('../entities/image'); | ||||||
| const NoteImage = require('../entities/note_image'); | const NoteImage = require('../entities/note_image'); | ||||||
| const Branch = require('../entities/branch'); | const Branch = require('../entities/branch'); | ||||||
| const Label = require('../entities/label'); | const Attribute = require('../entities/attribute'); | ||||||
| const RecentNote = require('../entities/recent_note'); | const RecentNote = require('../entities/recent_note'); | ||||||
| const ApiToken = require('../entities/api_token'); | const ApiToken = require('../entities/api_token'); | ||||||
| const Option = require('../entities/option'); | const Option = require('../entities/option'); | ||||||
| const repository = require('../services/repository'); | const repository = require('../services/repository'); | ||||||
|  |  | ||||||
|  | const TABLE_NAME_TO_ENTITY = { | ||||||
|  |     "attributes": Attribute, | ||||||
|  |     "images": Image, | ||||||
|  |     "note_images": NoteImage, | ||||||
|  |     "branches": Branch, | ||||||
|  |     "notes": Note, | ||||||
|  |     "note_revisions": NoteRevision, | ||||||
|  |     "recent_notes": RecentNote, | ||||||
|  |     "options": Option, | ||||||
|  |     "api_tokens": ApiToken | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | function getEntityFromTableName(tableName) { | ||||||
|  |     if (!(tableName in TABLE_NAME_TO_ENTITY)) { | ||||||
|  |         throw new Error(`Entity for table ${tableName} not found!`); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return TABLE_NAME_TO_ENTITY[tableName]; | ||||||
|  | } | ||||||
|  |  | ||||||
| function createEntityFromRow(row) { | function createEntityFromRow(row) { | ||||||
|     let entity; |     let entity; | ||||||
|  |  | ||||||
|     if (row.labelId) { |     if (row.attributeId) { | ||||||
|         entity = new Label(row); |         entity = new Attribute(row); | ||||||
|     } |     } | ||||||
|     else if (row.noteRevisionId) { |     else if (row.noteRevisionId) { | ||||||
|         entity = new NoteRevision(row); |         entity = new NoteRevision(row); | ||||||
| @@ -46,8 +66,9 @@ function createEntityFromRow(row) { | |||||||
|     return entity; |     return entity; | ||||||
| } | } | ||||||
|  |  | ||||||
| repository.setEntityConstructor(createEntityFromRow); |  | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     createEntityFromRow |     createEntityFromRow, | ||||||
| }; |     getEntityFromTableName | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | repository.setEntityConstructor(module.exports); | ||||||
|   | |||||||
| @@ -6,11 +6,9 @@ const dateUtils = require('../services/date_utils'); | |||||||
| class Image extends Entity { | class Image extends Entity { | ||||||
|     static get tableName() { return "images"; } |     static get tableName() { return "images"; } | ||||||
|     static get primaryKeyName() { return "imageId"; } |     static get primaryKeyName() { return "imageId"; } | ||||||
|     static get hashedProperties() { return ["imageId", "format", "checksum", "name", "isDeleted", "dateModified", "dateCreated"]; } |     static get hashedProperties() { return ["imageId", "format", "checksum", "name", "isDeleted", "dateCreated"]; } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (!this.isDeleted) { |         if (!this.isDeleted) { | ||||||
|             this.isDeleted = false; |             this.isDeleted = false; | ||||||
|         } |         } | ||||||
| @@ -19,7 +17,11 @@ class Image extends Entity { | |||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |         super.beforeSaving(); | ||||||
|  |  | ||||||
|  |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,41 +0,0 @@ | |||||||
| "use strict"; |  | ||||||
|  |  | ||||||
| const Entity = require('./entity'); |  | ||||||
| const repository = require('../services/repository'); |  | ||||||
| const dateUtils = require('../services/date_utils'); |  | ||||||
| const sql = require('../services/sql'); |  | ||||||
|  |  | ||||||
| class Label extends Entity { |  | ||||||
|     static get tableName() { return "labels"; } |  | ||||||
|     static get primaryKeyName() { return "labelId"; } |  | ||||||
|     static get hashedProperties() { return ["labelId", "noteId", "name", "value", "dateModified", "dateCreated"]; } |  | ||||||
|  |  | ||||||
|     async getNote() { |  | ||||||
|         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     async beforeSaving() { |  | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (!this.value) { |  | ||||||
|             // null value isn't allowed |  | ||||||
|             this.value = ""; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (this.position === undefined) { |  | ||||||
|             this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM labels WHERE noteId = ?`, [this.noteId]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (!this.isDeleted) { |  | ||||||
|             this.isDeleted = false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (!this.dateCreated) { |  | ||||||
|             this.dateCreated = dateUtils.nowDate(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| module.exports = Label; |  | ||||||
| @@ -1,6 +1,7 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const Entity = require('./entity'); | const Entity = require('./entity'); | ||||||
|  | const Attribute = require('./attribute'); | ||||||
| const protectedSessionService = require('../services/protected_session'); | const protectedSessionService = require('../services/protected_session'); | ||||||
| const repository = require('../services/repository'); | const repository = require('../services/repository'); | ||||||
| const dateUtils = require('../services/date_utils'); | const dateUtils = require('../services/date_utils'); | ||||||
| @@ -8,11 +9,13 @@ const dateUtils = require('../services/date_utils'); | |||||||
| class Note extends Entity { | class Note extends Entity { | ||||||
|     static get tableName() { return "notes"; } |     static get tableName() { return "notes"; } | ||||||
|     static get primaryKeyName() { return "noteId"; } |     static get primaryKeyName() { return "noteId"; } | ||||||
|     static get hashedProperties() { return ["noteId", "title", "content", "type", "dateModified", "isProtected", "isDeleted"]; } |     static get hashedProperties() { return ["noteId", "title", "content", "type", "isProtected", "isDeleted"]; } | ||||||
|  |  | ||||||
|     constructor(row) { |     constructor(row) { | ||||||
|         super(row); |         super(row); | ||||||
|  |  | ||||||
|  |         this.isProtected = !!this.isProtected; | ||||||
|  |  | ||||||
|         // check if there's noteId, otherwise this is a new entity which wasn't encrypted yet |         // check if there's noteId, otherwise this is a new entity which wasn't encrypted yet | ||||||
|         if (this.isProtected && this.noteId) { |         if (this.isProtected && this.noteId) { | ||||||
|             protectedSessionService.decryptNote(this); |             protectedSessionService.decryptNote(this); | ||||||
| @@ -30,6 +33,10 @@ class Note extends Entity { | |||||||
|         catch(e) {} |         catch(e) {} | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     isRoot() { | ||||||
|  |         return this.noteId === 'root'; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     isJson() { |     isJson() { | ||||||
|         return this.mime === "application/json"; |         return this.mime === "application/json"; | ||||||
|     } |     } | ||||||
| @@ -59,30 +66,140 @@ class Note extends Entity { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getLabels() { |     async getOwnedAttributes() { | ||||||
|         return await repository.getEntities("SELECT * FROM labels WHERE noteId = ? AND isDeleted = 0", [this.noteId]); |         return await repository.getEntities(`SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`, [this.noteId]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // WARNING: this doesn't take into account the possibility to have multi-valued labels! |     async getAttributes() { | ||||||
|     async getLabelMap() { |         if (!this.__attributeCache) { | ||||||
|         const map = {}; |             await this.loadAttributesToCache(); | ||||||
|  |  | ||||||
|         for (const label of await this.getLabels()) { |  | ||||||
|             map[label.name] = label.value; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return map; |         return this.__attributeCache; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     invalidateAttributeCache() { | ||||||
|  |         this.__attributeCache = null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async loadAttributesToCache() { | ||||||
|  |         const attributes = await repository.getEntities(` | ||||||
|  |             WITH RECURSIVE | ||||||
|  |             tree(noteId, level) AS ( | ||||||
|  |                 SELECT ?, 0 | ||||||
|  |                 UNION | ||||||
|  |                 SELECT branches.parentNoteId, tree.level + 1 FROM branches | ||||||
|  |                     JOIN tree ON branches.noteId = tree.noteId | ||||||
|  |                     JOIN notes ON notes.noteId = branches.parentNoteId | ||||||
|  |                 WHERE notes.isDeleted = 0 | ||||||
|  |                   AND branches.isDeleted = 0 | ||||||
|  |             ), | ||||||
|  |             treeWithAttrs(noteId, level) AS ( | ||||||
|  |                 SELECT * FROM tree | ||||||
|  |                 UNION | ||||||
|  |                 SELECT attributes.value, treeWithAttrs.level + 1 FROM attributes | ||||||
|  |                      JOIN treeWithAttrs ON treeWithAttrs.noteId = attributes.noteId | ||||||
|  |                 WHERE attributes.isDeleted = 0 | ||||||
|  |                   AND attributes.type = 'relation' | ||||||
|  |                   AND attributes.name = 'inheritAttributes' | ||||||
|  |                   AND (attributes.noteId = ? OR attributes.isInheritable = 1) | ||||||
|  |                 ) | ||||||
|  |             SELECT attributes.* FROM attributes JOIN treeWithAttrs ON attributes.noteId = treeWithAttrs.noteId | ||||||
|  |             WHERE attributes.isDeleted = 0 AND (attributes.isInheritable = 1 OR attributes.noteId = ?) | ||||||
|  |             ORDER BY level, noteId, position`, [this.noteId, this.noteId, this.noteId]); | ||||||
|  |         // attributes are ordered so that "closest" attributes are first | ||||||
|  |         // we order by noteId so that attributes from same note stay together. Actual noteId ordering doesn't matter. | ||||||
|  |  | ||||||
|  |         const filteredAttributes = attributes.filter((attr, index) => { | ||||||
|  |             if (attr.isDefinition()) { | ||||||
|  |                 const firstDefinitionIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); | ||||||
|  |  | ||||||
|  |                 // keep only if this element is the first definition for this type & name | ||||||
|  |                 return firstDefinitionIndex === index; | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 const definitionAttr = attributes.find(el => el.type === attr.type + '-definition' && el.name === attr.name); | ||||||
|  |  | ||||||
|  |                 if (!definitionAttr) { | ||||||
|  |                     return true; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 const definition = definitionAttr.value; | ||||||
|  |  | ||||||
|  |                 if (definition.multiplicityType === 'multivalue') { | ||||||
|  |                     return true; | ||||||
|  |                 } | ||||||
|  |                 else { | ||||||
|  |                     const firstAttrIndex = attributes.findIndex(el => el.type === attr.type && el.name === attr.name); | ||||||
|  |  | ||||||
|  |                     // in case of single-valued attribute we'll keep it only if it's first (closest) | ||||||
|  |                     return firstAttrIndex === index; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         for (const attr of filteredAttributes) { | ||||||
|  |             attr.isOwned = attr.noteId === this.noteId; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         this.__attributeCache = filteredAttributes; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async hasLabel(name) { |     async hasLabel(name) { | ||||||
|         const map = await this.getLabelMap(); |         return !!await this.getLabel(name); | ||||||
|  |  | ||||||
|         return map.hasOwnProperty(name); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // WARNING: this doesn't take into account the possibility to have multi-valued labels! |     // WARNING: this doesn't take into account the possibility to have multi-valued labels! | ||||||
|     async getLabel(name) { |     async getLabel(name) { | ||||||
|         return await repository.getEntity("SELECT * FROM labels WHERE noteId = ? AND name = ?", [this.noteId, name]); |         const attributes = await this.getAttributes(); | ||||||
|  |  | ||||||
|  |         return attributes.find(attr => attr.type === 'label' && attr.name === name); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async getLabelValue(name) { | ||||||
|  |         const label = await this.getLabel(name); | ||||||
|  |  | ||||||
|  |         return label ? label.value : null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async toggleLabel(enabled, name, value = "") { | ||||||
|  |         if (enabled) { | ||||||
|  |             await this.setLabel(name, value); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             await this.removeLabel(name, value); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async setLabel(name, value = "") { | ||||||
|  |         const attributes = await this.getOwnedAttributes(); | ||||||
|  |         let label = attributes.find(attr => attr.type === 'label' && attr.value === value); | ||||||
|  |  | ||||||
|  |         if (!label) { | ||||||
|  |             label = new Attribute({ | ||||||
|  |                 noteId: this.noteId, | ||||||
|  |                 type: 'label', | ||||||
|  |                 name: name, | ||||||
|  |                 value: value | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             await label.save(); | ||||||
|  |  | ||||||
|  |             this.invalidateAttributeCache(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async removeLabel(name, value = "") { | ||||||
|  |         const attributes = await this.getOwnedAttributes(); | ||||||
|  |  | ||||||
|  |         for (const attribute of attributes) { | ||||||
|  |             if (attribute.type === 'label' && (!value || value === attribute.value)) { | ||||||
|  |                 attribute.isDeleted = true; | ||||||
|  |                 await attribute.save(); | ||||||
|  |  | ||||||
|  |                 this.invalidateAttributeCache(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getRevisions() { |     async getRevisions() { | ||||||
| @@ -140,8 +257,6 @@ class Note extends Entity { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (this.isJson() && this.jsonContent) { |         if (this.isJson() && this.jsonContent) { | ||||||
|             this.content = JSON.stringify(this.jsonContent, null, '\t'); |             this.content = JSON.stringify(this.jsonContent, null, '\t'); | ||||||
|         } |         } | ||||||
| @@ -158,7 +273,11 @@ class Note extends Entity { | |||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |         super.beforeSaving(); | ||||||
|  |  | ||||||
|  |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ const dateUtils = require('../services/date_utils'); | |||||||
| class NoteImage extends Entity { | class NoteImage extends Entity { | ||||||
|     static get tableName() { return "note_images"; } |     static get tableName() { return "note_images"; } | ||||||
|     static get primaryKeyName() { return "noteImageId"; } |     static get primaryKeyName() { return "noteImageId"; } | ||||||
|     static get hashedProperties() { return ["noteImageId", "noteId", "imageId", "isDeleted", "dateModified", "dateCreated"]; } |     static get hashedProperties() { return ["noteImageId", "noteId", "imageId", "isDeleted", "dateCreated"]; } | ||||||
|  |  | ||||||
|     async getNote() { |     async getNote() { | ||||||
|         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); |         return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]); | ||||||
| @@ -18,8 +18,6 @@ class NoteImage extends Entity { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (!this.isDeleted) { |         if (!this.isDeleted) { | ||||||
|             this.isDeleted = false; |             this.isDeleted = false; | ||||||
|         } |         } | ||||||
| @@ -28,7 +26,11 @@ class NoteImage extends Entity { | |||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |         super.beforeSaving(); | ||||||
|  |  | ||||||
|  |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,11 +7,13 @@ const repository = require('../services/repository'); | |||||||
| class NoteRevision extends Entity { | class NoteRevision extends Entity { | ||||||
|     static get tableName() { return "note_revisions"; } |     static get tableName() { return "note_revisions"; } | ||||||
|     static get primaryKeyName() { return "noteRevisionId"; } |     static get primaryKeyName() { return "noteRevisionId"; } | ||||||
|     static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "content", "dateModifiedFrom", "dateModifiedTo"]; } |     static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "content", "isProtected", "dateModifiedFrom", "dateModifiedTo"]; } | ||||||
|  |  | ||||||
|     constructor(row) { |     constructor(row) { | ||||||
|         super(row); |         super(row); | ||||||
|  |  | ||||||
|  |         this.isProtected = !!this.isProtected; | ||||||
|  |  | ||||||
|         if (this.isProtected) { |         if (this.isProtected) { | ||||||
|             protectedSessionService.decryptNoteRevision(this); |             protectedSessionService.decryptNoteRevision(this); | ||||||
|         } |         } | ||||||
| @@ -22,11 +24,11 @@ class NoteRevision extends Entity { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (this.isProtected) { |         if (this.isProtected) { | ||||||
|             protectedSessionService.encryptNoteRevision(this); |             protectedSessionService.encryptNoteRevision(this); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         super.beforeSaving(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,10 +8,18 @@ class Option extends Entity { | |||||||
|     static get primaryKeyName() { return "name"; } |     static get primaryKeyName() { return "name"; } | ||||||
|     static get hashedProperties() { return ["name", "value"]; } |     static get hashedProperties() { return ["name", "value"]; } | ||||||
|  |  | ||||||
|  |     constructor(row) { | ||||||
|  |         super(row); | ||||||
|  |  | ||||||
|  |         this.isSynced = !!this.isSynced; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |         super.beforeSaving(); | ||||||
|  |  | ||||||
|         this.dateModified = dateUtils.nowDate(); |         if (this.isChanged) { | ||||||
|  |             this.dateModified = dateUtils.nowDate(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,8 +9,6 @@ class RecentNote extends Entity { | |||||||
|     static get hashedProperties() { return ["branchId", "notePath", "dateCreated", "isDeleted"]; } |     static get hashedProperties() { return ["branchId", "notePath", "dateCreated", "isDeleted"]; } | ||||||
|  |  | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         super.beforeSaving(); |  | ||||||
|  |  | ||||||
|         if (!this.isDeleted) { |         if (!this.isDeleted) { | ||||||
|             this.isDeleted = false; |             this.isDeleted = false; | ||||||
|         } |         } | ||||||
| @@ -18,6 +16,8 @@ class RecentNote extends Entity { | |||||||
|         if (!this.dateCreated) { |         if (!this.dateCreated) { | ||||||
|             this.dateCreated = dateUtils.nowDate(); |             this.dateCreated = dateUtils.nowDate(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         super.beforeSaving(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| Before Width: | Height: | Size: 511 B After Width: | Height: | Size: 511 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/clock-16.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 381 B | 
| Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 245 B | 
| Before Width: | Height: | Size: 339 B After Width: | Height: | Size: 339 B | 
| Before Width: | Height: | Size: 463 B After Width: | Height: | Size: 463 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/edit-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 312 B | 
| Before Width: | Height: | Size: 288 B After Width: | Height: | Size: 288 B | 
| Before Width: | Height: | Size: 284 B After Width: | Height: | Size: 284 B | 
| Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 292 B | 
| Before Width: | Height: | Size: 511 B After Width: | Height: | Size: 511 B | 
| Before Width: | Height: | Size: 155 B After Width: | Height: | Size: 155 B | 
| Before Width: | Height: | Size: 323 B | 
| Before Width: | Height: | Size: 358 B After Width: | Height: | Size: 358 B | 
| Before Width: | Height: | Size: 252 B After Width: | Height: | Size: 252 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/play-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 288 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/save-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 388 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/search-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 431 B | 
| Before Width: | Height: | Size: 419 B After Width: | Height: | Size: 419 B | 
| Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 354 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/shield-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 388 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/shield-off-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 462 B | 
| Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B | 
| Before Width: | Height: | Size: 337 B | 
							
								
								
									
										
											BIN
										
									
								
								src/public/images/icons/x-20.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 259 B | 
| @@ -15,6 +15,7 @@ const $prefixFormGroup = $("#add-link-prefix-form-group"); | |||||||
| const $linkTypeDiv = $("#add-link-type-div"); | const $linkTypeDiv = $("#add-link-type-div"); | ||||||
| const $linkTypes = $("input[name='add-link-type']"); | const $linkTypes = $("input[name='add-link-type']"); | ||||||
| const $linkTypeHtml = $linkTypes.filter('input[value="html"]'); | const $linkTypeHtml = $linkTypes.filter('input[value="html"]'); | ||||||
|  | const $showRecentNotesButton = $("#add-link-show-recent-notes"); | ||||||
|  |  | ||||||
| function setLinkType(linkType) { | function setLinkType(linkType) { | ||||||
|     $linkTypes.each(function () { |     $linkTypes.each(function () { | ||||||
| @@ -53,16 +54,33 @@ async function showDialog() { | |||||||
|         $linkTitle.val(noteTitle); |         $linkTitle.val(noteTitle); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $autoComplete.autocomplete({ |     await $autoComplete.autocomplete({ | ||||||
|         source: async function(request, response) { |         source: async function(request, response) { | ||||||
|             const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); |             const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); | ||||||
|  |  | ||||||
|             response(result); |             if (result.length > 0) { | ||||||
|  |                 response(result.map(row => { | ||||||
|  |                     return { | ||||||
|  |                         label: row.label, | ||||||
|  |                         value: row.label + ' (' + row.value + ')' | ||||||
|  |                     } | ||||||
|  |                 })); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 response([{ | ||||||
|  |                     label: "No results", | ||||||
|  |                     value: "No results" | ||||||
|  |                 }]); | ||||||
|  |             } | ||||||
|         }, |         }, | ||||||
|         minLength: 2, |         minLength: 0, | ||||||
|         change: async () => { |         change: async (event, ui) => { | ||||||
|             const val = $autoComplete.val(); |             if (!ui.item) { | ||||||
|             const notePath = linkService.getNodePathFromLabel(val); |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             const notePath = linkService.getNotePathFromLabel(ui.item.value); | ||||||
|  |  | ||||||
|             if (!notePath) { |             if (!notePath) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| @@ -73,21 +91,30 @@ async function showDialog() { | |||||||
|                 await setDefaultLinkTitle(noteId); |                 await setDefaultLinkTitle(noteId); | ||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|  |         select: function (event, ui) { | ||||||
|  |             if (ui.item.value === 'No results') { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         // this is called when user goes through autocomplete list with keyboard |         // this is called when user goes through autocomplete list with keyboard | ||||||
|         // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is |         // at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is | ||||||
|         focus: async (event, ui) => { |         focus: async (event, ui) => { | ||||||
|             const notePath = linkService.getNodePathFromLabel(ui.item.value); |             const notePath = linkService.getNotePathFromLabel(ui.item.value); | ||||||
|             const noteId = treeUtils.getNoteIdFromNotePath(notePath); |             const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|             await setDefaultLinkTitle(noteId); |             await setDefaultLinkTitle(noteId); | ||||||
|  |  | ||||||
|  |             event.preventDefault(); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     showRecentNotes(); | ||||||
| } | } | ||||||
|  |  | ||||||
| $form.submit(() => { | $form.submit(() => { | ||||||
|     const value = $autoComplete.val(); |     const value = $autoComplete.val(); | ||||||
|  |  | ||||||
|     const notePath = linkService.getNodePathFromLabel(value); |     const notePath = linkService.getNotePathFromLabel(value); | ||||||
|     const noteId = treeUtils.getNoteIdFromNotePath(notePath); |     const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
| @@ -145,8 +172,14 @@ function linkTypeChanged() { | |||||||
|     $linkTypeDiv.toggle(!hasSelection()); |     $linkTypeDiv.toggle(!hasSelection()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function showRecentNotes() { | ||||||
|  |     $autoComplete.autocomplete("search", ""); | ||||||
|  | } | ||||||
|  |  | ||||||
| $linkTypes.change(linkTypeChanged); | $linkTypes.change(linkTypeChanged); | ||||||
|  |  | ||||||
|  | $showRecentNotesButton.click(showRecentNotes); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     showDialog |     showDialog | ||||||
| }; | }; | ||||||
							
								
								
									
										318
									
								
								src/public/javascripts/dialogs/attributes.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,318 @@ | |||||||
|  | import noteDetailService from '../services/note_detail.js'; | ||||||
|  | import server from '../services/server.js'; | ||||||
|  | import infoService from "../services/info.js"; | ||||||
|  | import treeUtils from "../services/tree_utils.js"; | ||||||
|  | import linkService from "../services/link.js"; | ||||||
|  |  | ||||||
|  | const $dialog = $("#attributes-dialog"); | ||||||
|  | const $saveAttributesButton = $("#save-attributes-button"); | ||||||
|  | const $ownedAttributesBody = $('#owned-attributes-table tbody'); | ||||||
|  |  | ||||||
|  | const attributesModel = new AttributesModel(); | ||||||
|  |  | ||||||
|  | function AttributesModel() { | ||||||
|  |     const self = this; | ||||||
|  |  | ||||||
|  |     this.ownedAttributes = ko.observableArray(); | ||||||
|  |     this.inheritedAttributes = ko.observableArray(); | ||||||
|  |  | ||||||
|  |     this.availableTypes = [ | ||||||
|  |         { text: "Label", value: "label" }, | ||||||
|  |         { text: "Label definition", value: "label-definition" }, | ||||||
|  |         { text: "Relation", value: "relation" }, | ||||||
|  |         { text: "Relation definition", value: "relation-definition" } | ||||||
|  |     ]; | ||||||
|  |  | ||||||
|  |     this.availableLabelTypes = [ | ||||||
|  |         { text: "Text", value: "text" }, | ||||||
|  |         { text: "Number", value: "number" }, | ||||||
|  |         { text: "Boolean", value: "boolean" }, | ||||||
|  |         { text: "Date", value: "date" } | ||||||
|  |     ]; | ||||||
|  |  | ||||||
|  |     this.multiplicityTypes = [ | ||||||
|  |         { text: "Single value", value: "singlevalue" }, | ||||||
|  |         { text: "Multi value", value: "multivalue" } | ||||||
|  |     ]; | ||||||
|  |  | ||||||
|  |     this.typeChanged = function(data, event) { | ||||||
|  |         self.getTargetAttribute(event.target).valueHasMutated(); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.labelTypeChanged = function(data, event) { | ||||||
|  |         self.getTargetAttribute(event.target).valueHasMutated(); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.updateAttributePositions = function() { | ||||||
|  |         let position = 0; | ||||||
|  |  | ||||||
|  |         // we need to update positions by searching in the DOM, because order of the | ||||||
|  |         // attributes in the viewmodel (self.ownedAttributes()) stays the same | ||||||
|  |         $ownedAttributesBody.find('input[name="position"]').each(function() { | ||||||
|  |             const attribute = self.getTargetAttribute(this); | ||||||
|  |  | ||||||
|  |             attribute().position = position++; | ||||||
|  |         }); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     async function showAttributes(attributes) { | ||||||
|  |         const ownedAttributes = attributes.filter(attr => attr.isOwned); | ||||||
|  |  | ||||||
|  |         for (const attr of ownedAttributes) { | ||||||
|  |             attr.labelValue = attr.type === 'label' ? attr.value : ''; | ||||||
|  |             attr.relationValue = attr.type === 'relation' ? (await treeUtils.getNoteTitle(attr.value) + " (" + attr.value + ")") : ''; | ||||||
|  |             attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : { | ||||||
|  |                 labelType: "text", | ||||||
|  |                 multiplicityType: "singlevalue", | ||||||
|  |                 isPromoted: true | ||||||
|  |             }; | ||||||
|  |             attr.relationDefinition = attr.type === ('relation-definition' && attr.value) ? attr.value : { | ||||||
|  |                 multiplicityType: "singlevalue", | ||||||
|  |                 isPromoted: true | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             delete attr.value; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         self.ownedAttributes(ownedAttributes.map(ko.observable)); | ||||||
|  |  | ||||||
|  |         addLastEmptyRow(); | ||||||
|  |  | ||||||
|  |         const inheritedAttributes = attributes.filter(attr => !attr.isOwned); | ||||||
|  |  | ||||||
|  |         self.inheritedAttributes(inheritedAttributes); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     this.loadAttributes = async function() { | ||||||
|  |         const noteId = noteDetailService.getCurrentNoteId(); | ||||||
|  |  | ||||||
|  |         const attributes = await server.get('notes/' + noteId + '/attributes'); | ||||||
|  |  | ||||||
|  |         await showAttributes(attributes); | ||||||
|  |  | ||||||
|  |         // attribute might not be rendered immediatelly so could not focus | ||||||
|  |         setTimeout(() => $(".attribute-name:last").focus(), 100); | ||||||
|  |  | ||||||
|  |         $ownedAttributesBody.sortable({ | ||||||
|  |             handle: '.handle', | ||||||
|  |             containment: $ownedAttributesBody, | ||||||
|  |             update: this.updateAttributePositions | ||||||
|  |         }); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.deleteAttribute = function(data, event) { | ||||||
|  |         const attribute = self.getTargetAttribute(event.target); | ||||||
|  |         const attributeData = attribute(); | ||||||
|  |  | ||||||
|  |         if (attributeData) { | ||||||
|  |             attributeData.isDeleted = true; | ||||||
|  |  | ||||||
|  |             attribute(attributeData); | ||||||
|  |  | ||||||
|  |             addLastEmptyRow(); | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     function isValid() { | ||||||
|  |         for (let attributes = self.ownedAttributes(), i = 0; i < attributes.length; i++) { | ||||||
|  |             if (self.isEmptyName(i)) { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     this.save = async function() { | ||||||
|  |         // we need to defocus from input (in case of enter-triggered save) because value is updated | ||||||
|  |         // on blur event (because of conflict with jQuery UI Autocomplete). Without this, input would | ||||||
|  |         // stay in focus, blur wouldn't be triggered and change wouldn't be updated in the viewmodel. | ||||||
|  |         $saveAttributesButton.focus(); | ||||||
|  |  | ||||||
|  |         if (!isValid()) { | ||||||
|  |             alert("Please fix all validation errors and try saving again."); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         self.updateAttributePositions(); | ||||||
|  |  | ||||||
|  |         const noteId = noteDetailService.getCurrentNoteId(); | ||||||
|  |  | ||||||
|  |         const attributesToSave = self.ownedAttributes() | ||||||
|  |             .map(attribute => attribute()) | ||||||
|  |             .filter(attribute => attribute.attributeId !== "" || attribute.name !== ""); | ||||||
|  |  | ||||||
|  |         for (const attr of attributesToSave) { | ||||||
|  |             if (attr.type === 'label') { | ||||||
|  |                 attr.value = attr.labelValue; | ||||||
|  |             } | ||||||
|  |             else if (attr.type === 'relation') { | ||||||
|  |                 attr.value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel(attr.relationValue)); | ||||||
|  |             } | ||||||
|  |             else if (attr.type === 'label-definition') { | ||||||
|  |                 attr.value = attr.labelDefinition; | ||||||
|  |             } | ||||||
|  |             else if (attr.type === 'relation-definition') { | ||||||
|  |                 attr.value = attr.relationDefinition; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             delete attr.labelValue; | ||||||
|  |             delete attr.relationValue; | ||||||
|  |             delete attr.labelDefinition; | ||||||
|  |             delete attr.relationDefinition; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const attributes = await server.put('notes/' + noteId + '/attributes', attributesToSave); | ||||||
|  |  | ||||||
|  |         await showAttributes(attributes); | ||||||
|  |  | ||||||
|  |         infoService.showMessage("Attributes have been saved."); | ||||||
|  |  | ||||||
|  |         noteDetailService.loadAttributes(); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     function addLastEmptyRow() { | ||||||
|  |         const attributes = self.ownedAttributes().filter(attr => !attr().isDeleted); | ||||||
|  |         const last = attributes.length === 0 ? null : attributes[attributes.length - 1](); | ||||||
|  |  | ||||||
|  |         if (!last || last.name.trim() !== "") { | ||||||
|  |             self.ownedAttributes.push(ko.observable({ | ||||||
|  |                 attributeId: '', | ||||||
|  |                 type: 'label', | ||||||
|  |                 name: '', | ||||||
|  |                 labelValue: '', | ||||||
|  |                 relationValue: '', | ||||||
|  |                 isInheritable: false, | ||||||
|  |                 isDeleted: false, | ||||||
|  |                 position: 0, | ||||||
|  |                 labelDefinition: { | ||||||
|  |                     labelType: "text", | ||||||
|  |                     multiplicityType: "singlevalue", | ||||||
|  |                     isPromoted: true | ||||||
|  |                 }, | ||||||
|  |                 relationDefinition: { | ||||||
|  |                     multiplicityType: "singlevalue", | ||||||
|  |                     isPromoted: true | ||||||
|  |                 } | ||||||
|  |             })); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     this.attributeChanged = function (data, event) { | ||||||
|  |         addLastEmptyRow(); | ||||||
|  |  | ||||||
|  |         const attribute = self.getTargetAttribute(event.target); | ||||||
|  |  | ||||||
|  |         attribute.valueHasMutated(); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.isNotUnique = function(index) { | ||||||
|  |         const cur = self.ownedAttributes()[index](); | ||||||
|  |  | ||||||
|  |         if (cur.name.trim() === "") { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         for (let attributes = self.ownedAttributes(), i = 0; i < attributes.length; i++) { | ||||||
|  |             const attribute = attributes[i](); | ||||||
|  |  | ||||||
|  |             if (index !== i && cur.name === attribute.name && cur.type === attribute.type) { | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.isEmptyName = function(index) { | ||||||
|  |         const cur = self.ownedAttributes()[index](); | ||||||
|  |  | ||||||
|  |         return cur.name.trim() === "" && !cur.isDeleted && (cur.attributeId !== "" || cur.labelValue !== "" || cur.relationValue); | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     this.getTargetAttribute = function(target) { | ||||||
|  |         const context = ko.contextFor(target); | ||||||
|  |         const index = context.$index(); | ||||||
|  |  | ||||||
|  |         return self.ownedAttributes()[index]; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function showDialog() { | ||||||
|  |     glob.activeDialog = $dialog; | ||||||
|  |  | ||||||
|  |     await attributesModel.loadAttributes(); | ||||||
|  |  | ||||||
|  |     $dialog.dialog({ | ||||||
|  |         modal: true, | ||||||
|  |         width: 950, | ||||||
|  |         height: 500 | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ko.applyBindings(attributesModel, $dialog[0]); | ||||||
|  |  | ||||||
|  | $dialog.on('focus', '.attribute-name', function (e) { | ||||||
|  |     if (!$(this).hasClass("ui-autocomplete-input")) { | ||||||
|  |         $(this).autocomplete({ | ||||||
|  |             source: async (request, response) => { | ||||||
|  |                 const attribute = attributesModel.getTargetAttribute(this); | ||||||
|  |                 const type = (attribute().type === 'relation' || attribute().type === 'relation-definition') ? 'relation' : 'label'; | ||||||
|  |                 const names = await server.get('attributes/names/?type=' + type + '&query=' + encodeURIComponent(request.term)); | ||||||
|  |                 const result = names.map(name => { | ||||||
|  |                     return { | ||||||
|  |                         label: name, | ||||||
|  |                         value: name | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 if (result.length > 0) { | ||||||
|  |                     response(result); | ||||||
|  |                 } | ||||||
|  |                 else { | ||||||
|  |                     response([{ | ||||||
|  |                         label: "No results", | ||||||
|  |                         value: "No results" | ||||||
|  |                     }]); | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             minLength: 0 | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $(this).autocomplete("search", $(this).val()); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | $dialog.on('focus', '.label-value', async function (e) { | ||||||
|  |     if (!$(this).hasClass("ui-autocomplete-input")) { | ||||||
|  |         const attributeName = $(this).parent().parent().find('.attribute-name').val(); | ||||||
|  |  | ||||||
|  |         if (attributeName.trim() === "") { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const attributeValues = await server.get('attributes/values/' + encodeURIComponent(attributeName)); | ||||||
|  |  | ||||||
|  |         if (attributeValues.length === 0) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $(this).autocomplete({ | ||||||
|  |             // shouldn't be required and autocomplete should just accept array of strings, but that fails | ||||||
|  |             // because we have overriden filter() function in autocomplete.js | ||||||
|  |             source: attributeValues.map(attribute => { | ||||||
|  |                 return { | ||||||
|  |                     attribute: attribute, | ||||||
|  |                     value: attribute | ||||||
|  |                 } | ||||||
|  |             }), | ||||||
|  |             minLength: 0 | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $(this).autocomplete("search", $(this).val()); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     showDialog | ||||||
|  | }; | ||||||
| @@ -1,10 +1,11 @@ | |||||||
| import treeService from '../services/tree.js'; | import treeService from '../services/tree.js'; | ||||||
| import linkService from '../services/link.js'; |  | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
|  | import searchNotesService from '../services/search_notes.js'; | ||||||
|  |  | ||||||
| const $dialog = $("#jump-to-note-dialog"); | const $dialog = $("#jump-to-note-dialog"); | ||||||
| const $autoComplete = $("#jump-to-note-autocomplete"); | const $autoComplete = $("#jump-to-note-autocomplete"); | ||||||
| const $form = $("#jump-to-note-form"); | const $showInFullTextButton = $("#show-in-full-text-button"); | ||||||
|  | const $showRecentNotesButton = $("#jump-to-note-show-recent-notes"); | ||||||
|  |  | ||||||
| async function showDialog() { | async function showDialog() { | ||||||
|     glob.activeDialog = $dialog; |     glob.activeDialog = $dialog; | ||||||
| @@ -13,39 +14,66 @@ async function showDialog() { | |||||||
|  |  | ||||||
|     $dialog.dialog({ |     $dialog.dialog({ | ||||||
|         modal: true, |         modal: true, | ||||||
|         width: 800 |         width: 800, | ||||||
|  |         position: { my: "center top+100", at: "top", of: window } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     await $autoComplete.autocomplete({ |     await $autoComplete.autocomplete({ | ||||||
|         source: async function(request, response) { |         source: async function(request, response) { | ||||||
|             const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); |             const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); | ||||||
|  |  | ||||||
|             response(result); |             if (result.length > 0) { | ||||||
|  |                 response(result); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 response([{ | ||||||
|  |                     label: "No results", | ||||||
|  |                     value: "No results" | ||||||
|  |                 }]); | ||||||
|  |             } | ||||||
|         }, |         }, | ||||||
|         minLength: 2 |         focus: function(event, ui) { | ||||||
|  |             event.preventDefault(); | ||||||
|  |         }, | ||||||
|  |         minLength: 0, | ||||||
|  |         autoFocus: true, | ||||||
|  |         select: function (event, ui) { | ||||||
|  |             if (ui.item.value === 'No results') { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             treeService.activateNode(ui.item.value); | ||||||
|  |  | ||||||
|  |             $dialog.dialog('close'); | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     showRecentNotes(); | ||||||
| } | } | ||||||
|  |  | ||||||
| function getSelectedNotePath() { | function showInFullText(e) { | ||||||
|     const val = $autoComplete.val(); |     // stop from propagating upwards (dangerous especially with ctrl+enter executable javascript notes) | ||||||
|     return linkService.getNodePathFromLabel(val); |     e.preventDefault(); | ||||||
|  |     e.stopPropagation(); | ||||||
|  |  | ||||||
|  |     const searchText = $autoComplete.val(); | ||||||
|  |  | ||||||
|  |     searchNotesService.resetSearch(); | ||||||
|  |     searchNotesService.showSearch(); | ||||||
|  |     searchNotesService.doSearch(searchText); | ||||||
|  |  | ||||||
|  |     $dialog.dialog('close'); | ||||||
| } | } | ||||||
|  |  | ||||||
| function goToNote() { | function showRecentNotes() { | ||||||
|     const notePath = getSelectedNotePath(); |     $autoComplete.autocomplete("search", ""); | ||||||
|  |  | ||||||
|     if (notePath) { |  | ||||||
|         treeService.activateNode(notePath); |  | ||||||
|  |  | ||||||
|         $dialog.dialog('close'); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| $form.submit(() => { | $showInFullTextButton.click(showInFullText); | ||||||
|     goToNote(); |  | ||||||
|  |  | ||||||
|     return false; | $showRecentNotesButton.click(showRecentNotes); | ||||||
| }); |  | ||||||
|  | $dialog.bind('keydown', 'ctrl+return', showInFullText); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     showDialog |     showDialog | ||||||
|   | |||||||
| @@ -1,223 +0,0 @@ | |||||||
| import noteDetailService from '../services/note_detail.js'; |  | ||||||
| import utils from '../services/utils.js'; |  | ||||||
| import server from '../services/server.js'; |  | ||||||
| import infoService from "../services/info.js"; |  | ||||||
|  |  | ||||||
| const $dialog = $("#labels-dialog"); |  | ||||||
| const $saveLabelsButton = $("#save-labels-button"); |  | ||||||
| const $labelsBody = $('#labels-table tbody'); |  | ||||||
|  |  | ||||||
| const labelsModel = new LabelsModel(); |  | ||||||
| let labelNames = []; |  | ||||||
|  |  | ||||||
| function LabelsModel() { |  | ||||||
|     const self = this; |  | ||||||
|  |  | ||||||
|     this.labels = ko.observableArray(); |  | ||||||
|  |  | ||||||
|     this.updateLabelPositions = function() { |  | ||||||
|         let position = 0; |  | ||||||
|  |  | ||||||
|         // we need to update positions by searching in the DOM, because order of the |  | ||||||
|         // labels in the viewmodel (self.labels()) stays the same |  | ||||||
|         $labelsBody.find('input[name="position"]').each(function() { |  | ||||||
|             const label = self.getTargetLabel(this); |  | ||||||
|  |  | ||||||
|             label().position = position++; |  | ||||||
|         }); |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     this.loadLabels = async function() { |  | ||||||
|         const noteId = noteDetailService.getCurrentNoteId(); |  | ||||||
|  |  | ||||||
|         const labels = await server.get('notes/' + noteId + '/labels'); |  | ||||||
|  |  | ||||||
|         self.labels(labels.map(ko.observable)); |  | ||||||
|  |  | ||||||
|         addLastEmptyRow(); |  | ||||||
|  |  | ||||||
|         labelNames = await server.get('labels/names'); |  | ||||||
|  |  | ||||||
|         // label might not be rendered immediatelly so could not focus |  | ||||||
|         setTimeout(() => $(".label-name:last").focus(), 100); |  | ||||||
|  |  | ||||||
|         $labelsBody.sortable({ |  | ||||||
|             handle: '.handle', |  | ||||||
|             containment: $labelsBody, |  | ||||||
|             update: this.updateLabelPositions |  | ||||||
|         }); |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     this.deleteLabel = function(data, event) { |  | ||||||
|         const label = self.getTargetLabel(event.target); |  | ||||||
|         const labelData = label(); |  | ||||||
|  |  | ||||||
|         if (labelData) { |  | ||||||
|             labelData.isDeleted = 1; |  | ||||||
|  |  | ||||||
|             label(labelData); |  | ||||||
|  |  | ||||||
|             addLastEmptyRow(); |  | ||||||
|         } |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     function isValid() { |  | ||||||
|         for (let labels = self.labels(), i = 0; i < labels.length; i++) { |  | ||||||
|             if (self.isEmptyName(i)) { |  | ||||||
|                 return false; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     this.save = async function() { |  | ||||||
|         // we need to defocus from input (in case of enter-triggered save) because value is updated |  | ||||||
|         // on blur event (because of conflict with jQuery UI Autocomplete). Without this, input would |  | ||||||
|         // stay in focus, blur wouldn't be triggered and change wouldn't be updated in the viewmodel. |  | ||||||
|         $saveLabelsButton.focus(); |  | ||||||
|  |  | ||||||
|         if (!isValid()) { |  | ||||||
|             alert("Please fix all validation errors and try saving again."); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         self.updateLabelPositions(); |  | ||||||
|  |  | ||||||
|         const noteId = noteDetailService.getCurrentNoteId(); |  | ||||||
|  |  | ||||||
|         const labelsToSave = self.labels() |  | ||||||
|             .map(label => label()) |  | ||||||
|             .filter(label => label.labelId !== "" || label.name !== ""); |  | ||||||
|  |  | ||||||
|         const labels = await server.put('notes/' + noteId + '/labels', labelsToSave); |  | ||||||
|  |  | ||||||
|         self.labels(labels.map(ko.observable)); |  | ||||||
|  |  | ||||||
|         addLastEmptyRow(); |  | ||||||
|  |  | ||||||
|         infoService.showMessage("Labels have been saved."); |  | ||||||
|  |  | ||||||
|         noteDetailService.loadLabelList(); |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     function addLastEmptyRow() { |  | ||||||
|         const labels = self.labels().filter(attr => attr().isDeleted === 0); |  | ||||||
|         const last = labels.length === 0 ? null : labels[labels.length - 1](); |  | ||||||
|  |  | ||||||
|         if (!last || last.name.trim() !== "" || last.value !== "") { |  | ||||||
|             self.labels.push(ko.observable({ |  | ||||||
|                 labelId: '', |  | ||||||
|                 name: '', |  | ||||||
|                 value: '', |  | ||||||
|                 isDeleted: 0, |  | ||||||
|                 position: 0 |  | ||||||
|             })); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     this.labelChanged = function (data, event) { |  | ||||||
|         addLastEmptyRow(); |  | ||||||
|  |  | ||||||
|         const label = self.getTargetLabel(event.target); |  | ||||||
|  |  | ||||||
|         label.valueHasMutated(); |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     this.isNotUnique = function(index) { |  | ||||||
|         const cur = self.labels()[index](); |  | ||||||
|  |  | ||||||
|         if (cur.name.trim() === "") { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         for (let labels = self.labels(), i = 0; i < labels.length; i++) { |  | ||||||
|             const label = labels[i](); |  | ||||||
|  |  | ||||||
|             if (index !== i && cur.name === label.name) { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     this.isEmptyName = function(index) { |  | ||||||
|         const cur = self.labels()[index](); |  | ||||||
|  |  | ||||||
|         return cur.name.trim() === "" && (cur.labelId !== "" || cur.value !== ""); |  | ||||||
|     }; |  | ||||||
|  |  | ||||||
|     this.getTargetLabel = function(target) { |  | ||||||
|         const context = ko.contextFor(target); |  | ||||||
|         const index = context.$index(); |  | ||||||
|  |  | ||||||
|         return self.labels()[index]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function showDialog() { |  | ||||||
|     glob.activeDialog = $dialog; |  | ||||||
|  |  | ||||||
|     await labelsModel.loadLabels(); |  | ||||||
|  |  | ||||||
|     $dialog.dialog({ |  | ||||||
|         modal: true, |  | ||||||
|         width: 800, |  | ||||||
|         height: 500 |  | ||||||
|     }); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| ko.applyBindings(labelsModel, document.getElementById('labels-dialog')); |  | ||||||
|  |  | ||||||
| $(document).on('focus', '.label-name', function (e) { |  | ||||||
|     if (!$(this).hasClass("ui-autocomplete-input")) { |  | ||||||
|         $(this).autocomplete({ |  | ||||||
|             // shouldn't be required and autocomplete should just accept array of strings, but that fails |  | ||||||
|             // because we have overriden filter() function in autocomplete.js |  | ||||||
|             source: labelNames.map(label => { |  | ||||||
|                 return { |  | ||||||
|                     label: label, |  | ||||||
|                     value: label |  | ||||||
|                 } |  | ||||||
|             }), |  | ||||||
|             minLength: 0 |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $(this).autocomplete("search", $(this).val()); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| $(document).on('focus', '.label-value', async function (e) { |  | ||||||
|     if (!$(this).hasClass("ui-autocomplete-input")) { |  | ||||||
|         const labelName = $(this).parent().parent().find('.label-name').val(); |  | ||||||
|  |  | ||||||
|         if (labelName.trim() === "") { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         const labelValues = await server.get('labels/values/' + encodeURIComponent(labelName)); |  | ||||||
|  |  | ||||||
|         if (labelValues.length === 0) { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $(this).autocomplete({ |  | ||||||
|             // shouldn't be required and autocomplete should just accept array of strings, but that fails |  | ||||||
|             // because we have overriden filter() function in autocomplete.js |  | ||||||
|             source: labelValues.map(label => { |  | ||||||
|                 return { |  | ||||||
|                     label: label, |  | ||||||
|                     value: label |  | ||||||
|                 } |  | ||||||
|             }), |  | ||||||
|             minLength: 0 |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $(this).autocomplete("search", $(this).val()); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| export default { |  | ||||||
|     showDialog |  | ||||||
| }; |  | ||||||
| @@ -29,7 +29,7 @@ function formatNode(node, level) { | |||||||
|     const indentAfter  = new Array(level - 1).join('  '); |     const indentAfter  = new Array(level - 1).join('  '); | ||||||
|     let textNode; |     let textNode; | ||||||
|  |  | ||||||
|     for (const i = 0; i < node.children.length; i++) { |     for (let i = 0; i < node.children.length; i++) { | ||||||
|         textNode = document.createTextNode('\n' + indentBefore); |         textNode = document.createTextNode('\n' + indentBefore); | ||||||
|         node.insertBefore(textNode, node.children[i]); |         node.insertBefore(textNode, node.children[i]); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| import protectedSessionHolder from '../services/protected_session_holder.js'; | import protectedSessionHolder from '../services/protected_session_holder.js'; | ||||||
| import utils from '../services/utils.js'; |  | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
| import infoService from "../services/info.js"; | import infoService from "../services/info.js"; | ||||||
|  | import zoomService from "../services/zoom.js"; | ||||||
|  | import utils from "../services/utils.js"; | ||||||
|  |  | ||||||
| const $dialog = $("#options-dialog"); | const $dialog = $("#options-dialog"); | ||||||
| const $tabs = $("#options-tabs"); | const $tabs = $("#options-tabs"); | ||||||
| @@ -33,8 +34,8 @@ async function showDialog() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function saveOptions(optionName, optionValue) { | async function saveOptions(options) { | ||||||
|     await server.put('options/' + encodeURIComponent(optionName) + '/' + encodeURIComponent(optionValue)); |     await server.put('options', options); | ||||||
|  |  | ||||||
|     infoService.showMessage("Options change have been saved."); |     infoService.showMessage("Options change have been saved."); | ||||||
| } | } | ||||||
| @@ -44,6 +45,41 @@ export default { | |||||||
|     saveOptions |     saveOptions | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | addTabHandler((function() { | ||||||
|  |     const $themeSelect = $("#theme-select"); | ||||||
|  |     const $zoomFactorSelect = $("#zoom-factor-select"); | ||||||
|  |     const $html = $("html"); | ||||||
|  |  | ||||||
|  |     function optionsLoaded(options) { | ||||||
|  |         $themeSelect.val(options.theme); | ||||||
|  |  | ||||||
|  |         if (utils.isElectron()) { | ||||||
|  |             $zoomFactorSelect.val(options.zoomFactor); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             $zoomFactorSelect.prop('disabled', true); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $themeSelect.change(function() { | ||||||
|  |         const newTheme = $(this).val(); | ||||||
|  |  | ||||||
|  |         $html.attr("class", "theme-" + newTheme); | ||||||
|  |  | ||||||
|  |         server.put('options/theme/' + newTheme); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     $zoomFactorSelect.change(function() { | ||||||
|  |         const newZoomFactor = $(this).val(); | ||||||
|  |  | ||||||
|  |         zoomService.setZoomFactorAndSave(newZoomFactor); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     return { | ||||||
|  |         optionsLoaded | ||||||
|  |     }; | ||||||
|  | })()); | ||||||
|  |  | ||||||
| addTabHandler((function() { | addTabHandler((function() { | ||||||
|     const $form = $("#change-password-form"); |     const $form = $("#change-password-form"); | ||||||
|     const $oldPassword = $("#old-password"); |     const $oldPassword = $("#old-password"); | ||||||
| @@ -93,16 +129,15 @@ addTabHandler((function() { | |||||||
| addTabHandler((function() { | addTabHandler((function() { | ||||||
|     const $form = $("#protected-session-timeout-form"); |     const $form = $("#protected-session-timeout-form"); | ||||||
|     const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds"); |     const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds"); | ||||||
|     const optionName = 'protectedSessionTimeout'; |  | ||||||
|  |  | ||||||
|     function optionsLoaded(options) { |     function optionsLoaded(options) { | ||||||
|         $protectedSessionTimeout.val(options[optionName]); |         $protectedSessionTimeout.val(options['protectedSessionTimeout']); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $form.submit(() => { |     $form.submit(() => { | ||||||
|         const protectedSessionTimeout = $protectedSessionTimeout.val(); |         const protectedSessionTimeout = $protectedSessionTimeout.val(); | ||||||
|  |  | ||||||
|         saveOptions(optionName, protectedSessionTimeout).then(() => { |         saveOptions({ 'protectedSessionTimeout': protectedSessionTimeout }).then(() => { | ||||||
|             protectedSessionHolder.setProtectedSessionTimeout(protectedSessionTimeout); |             protectedSessionHolder.setProtectedSessionTimeout(protectedSessionTimeout); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -117,14 +152,13 @@ addTabHandler((function() { | |||||||
| addTabHandler((function () { | addTabHandler((function () { | ||||||
|     const $form = $("#note-revision-snapshot-time-interval-form"); |     const $form = $("#note-revision-snapshot-time-interval-form"); | ||||||
|     const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds"); |     const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds"); | ||||||
|     const optionName = 'noteRevisionSnapshotTimeInterval'; |  | ||||||
|  |  | ||||||
|     function optionsLoaded(options) { |     function optionsLoaded(options) { | ||||||
|         $timeInterval.val(options[optionName]); |         $timeInterval.val(options['noteRevisionSnapshotTimeInterval']); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $form.submit(() => { |     $form.submit(() => { | ||||||
|         saveOptions(optionName, $timeInterval.val()); |         saveOptions({ 'noteRevisionSnapshotTimeInterval': $timeInterval.val() }); | ||||||
|  |  | ||||||
|         return false; |         return false; | ||||||
|     }); |     }); | ||||||
| @@ -137,6 +171,7 @@ addTabHandler((function () { | |||||||
| addTabHandler((async function () { | addTabHandler((async function () { | ||||||
|     const $appVersion = $("#app-version"); |     const $appVersion = $("#app-version"); | ||||||
|     const $dbVersion = $("#db-version"); |     const $dbVersion = $("#db-version"); | ||||||
|  |     const $syncVersion = $("#sync-version"); | ||||||
|     const $buildDate = $("#build-date"); |     const $buildDate = $("#build-date"); | ||||||
|     const $buildRevision = $("#build-revision"); |     const $buildRevision = $("#build-revision"); | ||||||
|  |  | ||||||
| @@ -144,6 +179,7 @@ addTabHandler((async function () { | |||||||
|  |  | ||||||
|     $appVersion.html(appInfo.appVersion); |     $appVersion.html(appInfo.appVersion); | ||||||
|     $dbVersion.html(appInfo.dbVersion); |     $dbVersion.html(appInfo.dbVersion); | ||||||
|  |     $syncVersion.html(appInfo.syncVersion); | ||||||
|     $buildDate.html(appInfo.buildDate); |     $buildDate.html(appInfo.buildDate); | ||||||
|     $buildRevision.html(appInfo.buildRevision); |     $buildRevision.html(appInfo.buildRevision); | ||||||
|     $buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.buildRevision); |     $buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.buildRevision); | ||||||
| @@ -151,6 +187,57 @@ addTabHandler((async function () { | |||||||
|     return {}; |     return {}; | ||||||
| })()); | })()); | ||||||
|  |  | ||||||
|  | addTabHandler((function() { | ||||||
|  |     const $form = $("#sync-setup-form"); | ||||||
|  |     const $syncServerHost = $("#sync-server-host"); | ||||||
|  |     const $syncServerTimeout = $("#sync-server-timeout"); | ||||||
|  |     const $syncProxy = $("#sync-proxy"); | ||||||
|  |     const $testSyncButton = $("#test-sync-button"); | ||||||
|  |     const $syncToServerButton = $("#sync-to-server-button"); | ||||||
|  |  | ||||||
|  |     function optionsLoaded(options) { | ||||||
|  |         $syncServerHost.val(options['syncServerHost']); | ||||||
|  |         $syncServerTimeout.val(options['syncServerTimeout']); | ||||||
|  |         $syncProxy.val(options['syncProxy']); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     $form.submit(() => { | ||||||
|  |         saveOptions({ | ||||||
|  |             'syncServerHost': $syncServerHost.val(), | ||||||
|  |             'syncServerTimeout': $syncServerTimeout.val(), | ||||||
|  |             'syncProxy': $syncProxy.val() | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         return false; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     $testSyncButton.click(async () => { | ||||||
|  |         const result = await server.post('sync/test'); | ||||||
|  |  | ||||||
|  |         if (result.connection === "Success") { | ||||||
|  |             infoService.showMessage("Sync server handshake has been successful"); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             infoService.showError("Sync server handshake failed, error: " + result.error); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     $syncToServerButton.click(async () => { | ||||||
|  |         const resp = await server.post("setup/sync-to-server"); | ||||||
|  |  | ||||||
|  |         if (resp.success) { | ||||||
|  |             infoService.showMessage("Sync has been established to the server instance. It will take some time to finish."); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             infoService.showError('Sync setup failed: ' + resp.error); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     return { | ||||||
|  |         optionsLoaded | ||||||
|  |     }; | ||||||
|  | })()); | ||||||
|  |  | ||||||
| addTabHandler((async function () { | addTabHandler((async function () { | ||||||
|     const $forceFullSyncButton = $("#force-full-sync-button"); |     const $forceFullSyncButton = $("#force-full-sync-button"); | ||||||
|     const $fillSyncRowsButton = $("#fill-sync-rows-button"); |     const $fillSyncRowsButton = $("#fill-sync-rows-button"); | ||||||
|   | |||||||
| @@ -1,113 +0,0 @@ | |||||||
| import treeService from '../services/tree.js'; |  | ||||||
| import messagingService from '../services/messaging.js'; |  | ||||||
| import server from '../services/server.js'; |  | ||||||
| import utils from "../services/utils.js"; |  | ||||||
| import treeUtils from "../services/tree_utils.js"; |  | ||||||
|  |  | ||||||
| const $dialog = $("#recent-notes-dialog"); |  | ||||||
| const $searchInput = $('#recent-notes-search-input'); |  | ||||||
|  |  | ||||||
| // list of recent note paths |  | ||||||
| let list = []; |  | ||||||
|  |  | ||||||
| async function reload() { |  | ||||||
|     const result = await server.get('recent-notes'); |  | ||||||
|  |  | ||||||
|     list = result.map(r => r.notePath); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function addRecentNote(branchId, notePath) { |  | ||||||
|     setTimeout(async () => { |  | ||||||
|         // we include the note into recent list only if the user stayed on the note at least 5 seconds |  | ||||||
|         if (notePath && notePath === treeService.getCurrentNotePath()) { |  | ||||||
|             const result = await server.put('recent-notes/' + branchId + '/' + encodeURIComponent(notePath)); |  | ||||||
|  |  | ||||||
|             list = result.map(r => r.notePath); |  | ||||||
|         } |  | ||||||
|     }, 1500); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function getNoteTitle(notePath) { |  | ||||||
|     let noteTitle; |  | ||||||
|  |  | ||||||
|     try { |  | ||||||
|         noteTitle = await treeUtils.getNotePathTitle(notePath); |  | ||||||
|     } |  | ||||||
|     catch (e) { |  | ||||||
|         noteTitle = "[error - can't find note title]"; |  | ||||||
|  |  | ||||||
|         messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return noteTitle; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function showDialog() { |  | ||||||
|     glob.activeDialog = $dialog; |  | ||||||
|  |  | ||||||
|     $dialog.dialog({ |  | ||||||
|         modal: true, |  | ||||||
|         width: 800, |  | ||||||
|         height: 100, |  | ||||||
|         position: { my: "center top+100", at: "top", of: window } |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     $searchInput.val(''); |  | ||||||
|  |  | ||||||
|     // remove the current note |  | ||||||
|     const recNotes = list.filter(note => note !== treeService.getCurrentNotePath()); |  | ||||||
|     const items = []; |  | ||||||
|  |  | ||||||
|     for (const notePath of recNotes) { |  | ||||||
|         items.push({ |  | ||||||
|             label: await getNoteTitle(notePath), |  | ||||||
|             value: notePath |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $searchInput.autocomplete({ |  | ||||||
|         source: items, |  | ||||||
|         minLength: 0, |  | ||||||
|         autoFocus: true, |  | ||||||
|         select: function (event, ui) { |  | ||||||
|             treeService.activateNode(ui.item.value); |  | ||||||
|  |  | ||||||
|             $searchInput.autocomplete('destroy'); |  | ||||||
|             $dialog.dialog('close'); |  | ||||||
|         }, |  | ||||||
|         focus: function (event, ui) { |  | ||||||
|             event.preventDefault(); |  | ||||||
|         }, |  | ||||||
|         close: function (event, ui) { |  | ||||||
|             if (event.keyCode === 27) { // escape closes dialog |  | ||||||
|                 $searchInput.autocomplete('destroy'); |  | ||||||
|                 $dialog.dialog('close'); |  | ||||||
|             } |  | ||||||
|             else { |  | ||||||
|                 // keep autocomplete open |  | ||||||
|                 // we're kind of abusing autocomplete to work in a way which it's not designed for |  | ||||||
|                 $searchInput.autocomplete("search", ""); |  | ||||||
|             } |  | ||||||
|         }, |  | ||||||
|         create: () => $searchInput.autocomplete("search", ""), |  | ||||||
|         classes: { |  | ||||||
|             "ui-autocomplete": "recent-notes-autocomplete" |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| setTimeout(reload, 100); |  | ||||||
|  |  | ||||||
| messagingService.subscribeToMessages(syncData => { |  | ||||||
|     if (syncData.some(sync => sync.entityName === 'recent_notes')) { |  | ||||||
|         console.log(utils.now(), "Reloading recent notes because of background changes"); |  | ||||||
|  |  | ||||||
|         reload(); |  | ||||||
|     } |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| export default { |  | ||||||
|     showDialog, |  | ||||||
|     addRecentNote, |  | ||||||
|     reload |  | ||||||
| }; |  | ||||||
| @@ -6,7 +6,8 @@ class NoteShort { | |||||||
|         this.isProtected = row.isProtected; |         this.isProtected = row.isProtected; | ||||||
|         this.type = row.type; |         this.type = row.type; | ||||||
|         this.mime = row.mime; |         this.mime = row.mime; | ||||||
|         this.hideInAutocomplete = row.hideInAutocomplete; |         this.archived = row.archived; | ||||||
|  |         this.cssClass = row.cssClass; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     isJson() { |     isJson() { | ||||||
| @@ -59,7 +60,7 @@ class NoteShort { | |||||||
|     get dto() { |     get dto() { | ||||||
|         const dto = Object.assign({}, this); |         const dto = Object.assign({}, this); | ||||||
|         delete dto.treeCache; |         delete dto.treeCache; | ||||||
|         delete dto.hideInAutocomplete; |         delete dto.archived; | ||||||
|  |  | ||||||
|         return dto; |         return dto; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,46 +0,0 @@ | |||||||
| import server from './services/server.js'; |  | ||||||
|  |  | ||||||
| $(document).ready(async () => { |  | ||||||
|     const {appDbVersion, dbVersion} = await server.get('migration'); |  | ||||||
|  |  | ||||||
|     console.log("HI", {appDbVersion, dbVersion}); |  | ||||||
|  |  | ||||||
|     if (appDbVersion === dbVersion) { |  | ||||||
|         $("#up-to-date").show(); |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         $("#need-to-migrate").show(); |  | ||||||
|  |  | ||||||
|         $("#app-db-version").html(appDbVersion); |  | ||||||
|         $("#db-version").html(dbVersion); |  | ||||||
|     } |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| $("#run-migration").click(async () => { |  | ||||||
|     $("#run-migration").prop("disabled", true); |  | ||||||
|  |  | ||||||
|     $("#migration-result").show(); |  | ||||||
|  |  | ||||||
|     const result = await server.post('migration'); |  | ||||||
|  |  | ||||||
|     for (const migration of result.migrations) { |  | ||||||
|         const row = $('<tr>') |  | ||||||
|             .append($('<td>').html(migration.dbVersion)) |  | ||||||
|             .append($('<td>').html(migration.name)) |  | ||||||
|             .append($('<td>').html(migration.success ? 'Yes' : 'No')) |  | ||||||
|             .append($('<td>').html(migration.success ? 'N/A' : migration.error)); |  | ||||||
|  |  | ||||||
|         if (!migration.success) { |  | ||||||
|             row.addClass("danger"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $("#migration-table").append(row); |  | ||||||
|     } |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| // copy of this shortcut to be able to debug migration problems |  | ||||||
| $(document).bind('keydown', 'ctrl+shift+i', () => { |  | ||||||
|     require('electron').remote.getCurrentWindow().toggleDevTools(); |  | ||||||
|  |  | ||||||
|     return false; |  | ||||||
| }); |  | ||||||
							
								
								
									
										14
									
								
								src/public/javascripts/services/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,10 +1,9 @@ | |||||||
| import addLinkDialog from '../dialogs/add_link.js'; | import addLinkDialog from '../dialogs/add_link.js'; | ||||||
| import jumpToNoteDialog from '../dialogs/jump_to_note.js'; | import jumpToNoteDialog from '../dialogs/jump_to_note.js'; | ||||||
| import labelsDialog from '../dialogs/labels.js'; | import attributesDialog from '../dialogs/attributes.js'; | ||||||
| import noteRevisionsDialog from '../dialogs/note_revisions.js'; | import noteRevisionsDialog from '../dialogs/note_revisions.js'; | ||||||
| import noteSourceDialog from '../dialogs/note_source.js'; | import noteSourceDialog from '../dialogs/note_source.js'; | ||||||
| import recentChangesDialog from '../dialogs/recent_changes.js'; | import recentChangesDialog from '../dialogs/recent_changes.js'; | ||||||
| import recentNotesDialog from '../dialogs/recent_notes.js'; |  | ||||||
| import optionsDialog from '../dialogs/options.js'; | import optionsDialog from '../dialogs/options.js'; | ||||||
| import sqlConsoleDialog from '../dialogs/sql_console.js'; | import sqlConsoleDialog from '../dialogs/sql_console.js'; | ||||||
|  |  | ||||||
| @@ -17,7 +16,7 @@ import messagingService from './messaging.js'; | |||||||
| import noteDetailService from './note_detail.js'; | import noteDetailService from './note_detail.js'; | ||||||
| import noteType from './note_type.js'; | import noteType from './note_type.js'; | ||||||
| import protected_session from './protected_session.js'; | import protected_session from './protected_session.js'; | ||||||
| import searchTreeService from './search_tree.js'; | import searchNotesService from './search_notes.js'; | ||||||
| import ScriptApi from './script_api.js'; | import ScriptApi from './script_api.js'; | ||||||
| import ScriptContext from './script_context.js'; | import ScriptContext from './script_context.js'; | ||||||
| import sync from './sync.js'; | import sync from './sync.js'; | ||||||
| @@ -36,6 +35,8 @@ import libraryLoader from "./library_loader.js"; | |||||||
| window.glob.getCurrentNode = treeService.getCurrentNode; | window.glob.getCurrentNode = treeService.getCurrentNode; | ||||||
| window.glob.getHeaders = server.getHeaders; | window.glob.getHeaders = server.getHeaders; | ||||||
| window.glob.showAddLinkDialog = addLinkDialog.showDialog; | window.glob.showAddLinkDialog = addLinkDialog.showDialog; | ||||||
|  | // this is required by CKEditor when uploading images | ||||||
|  | window.glob.noteChanged = noteDetailService.noteChanged; | ||||||
|  |  | ||||||
| // required for ESLint plugin | // required for ESLint plugin | ||||||
| window.glob.getCurrentNote = noteDetailService.getCurrentNote; | window.glob.getCurrentNote = noteDetailService.getCurrentNote; | ||||||
| @@ -47,7 +48,12 @@ window.onerror = function (msg, url, lineNo, columnNo, error) { | |||||||
|  |  | ||||||
|     let message = "Uncaught error: "; |     let message = "Uncaught error: "; | ||||||
|  |  | ||||||
|     if (string.indexOf("script error") > -1){ |     if (string.includes("Cannot read property 'defaultView' of undefined")) { | ||||||
|  |         // ignore this specific error which is very common but we don't know where it comes from | ||||||
|  |         // and it seems to be harmless | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |     else if (string.includes("script error")) { | ||||||
|         message += 'No details available'; |         message += 'No details available'; | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|   | |||||||
| @@ -1,8 +1,14 @@ | |||||||
| import ScriptContext from "./script_context.js"; | import ScriptContext from "./script_context.js"; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
|  |  | ||||||
| async function executeBundle(bundle) { | async function getAndExecuteBundle(noteId, originEntity = null) { | ||||||
|     const apiContext = ScriptContext(bundle.note, bundle.allNotes); |     const bundle = await server.get('script/bundle/' + noteId); | ||||||
|  |  | ||||||
|  |     await executeBundle(bundle, originEntity); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function executeBundle(bundle, originEntity) { | ||||||
|  |     const apiContext = ScriptContext(bundle.note, bundle.allNotes, originEntity); | ||||||
|  |  | ||||||
|     return await (function () { |     return await (function () { | ||||||
|         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); |         return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); | ||||||
| @@ -17,7 +23,17 @@ async function executeStartupBundles() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function executeRelationBundles(note, relationName) { | ||||||
|  |     const bundlesToRun = await server.get("script/relation/" + note.noteId + "/" + relationName); | ||||||
|  |  | ||||||
|  |     for (const bundle of bundlesToRun) { | ||||||
|  |         await executeBundle(bundle, note); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     executeBundle, |     executeBundle, | ||||||
|     executeStartupBundles |     getAndExecuteBundle, | ||||||
|  |     executeStartupBundles, | ||||||
|  |     executeRelationBundles | ||||||
| } | } | ||||||
| @@ -114,13 +114,14 @@ const contextMenuOptions = { | |||||||
|         // Modify menu entries depending on node status |         // Modify menu entries depending on node status | ||||||
|         $tree.contextmenu("enableEntry", "insertNoteHere", isNotRoot && parentNote.type !== 'search'); |         $tree.contextmenu("enableEntry", "insertNoteHere", isNotRoot && parentNote.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "delete", isNotRoot); |         $tree.contextmenu("enableEntry", "delete", isNotRoot && parentNote.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "copy", isNotRoot); |         $tree.contextmenu("enableEntry", "copy", isNotRoot); | ||||||
|         $tree.contextmenu("enableEntry", "cut", isNotRoot); |         $tree.contextmenu("enableEntry", "cut", isNotRoot); | ||||||
|         $tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && isNotRoot && parentNote.type !== 'search'); |         $tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && isNotRoot && parentNote.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search'); |         $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "importBranch", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "importBranch", note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "exportBranch", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "exportBranch", note.type !== 'search'); | ||||||
|  |         $tree.contextmenu("enableEntry", "editBranchPrefix", isNotRoot && parentNote.type !== 'search'); | ||||||
|  |  | ||||||
|         // Activate node on right-click |         // Activate node on right-click | ||||||
|         node.setActive(); |         node.setActive(); | ||||||
|   | |||||||
| @@ -2,16 +2,16 @@ import utils from "./utils.js"; | |||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import linkService from "./link.js"; | import linkService from "./link.js"; | ||||||
| import fileService from "./file.js"; | import fileService from "./file.js"; | ||||||
|  | import zoomService from "./zoom.js"; | ||||||
| import noteRevisionsDialog from "../dialogs/note_revisions.js"; | import noteRevisionsDialog from "../dialogs/note_revisions.js"; | ||||||
| import optionsDialog from "../dialogs/options.js"; | import optionsDialog from "../dialogs/options.js"; | ||||||
| import addLinkDialog from "../dialogs/add_link.js"; | import addLinkDialog from "../dialogs/add_link.js"; | ||||||
| import recentNotesDialog from "../dialogs/recent_notes.js"; |  | ||||||
| import jumpToNoteDialog from "../dialogs/jump_to_note.js"; | import jumpToNoteDialog from "../dialogs/jump_to_note.js"; | ||||||
| import noteSourceDialog from "../dialogs/note_source.js"; | import noteSourceDialog from "../dialogs/note_source.js"; | ||||||
| import recentChangesDialog from "../dialogs/recent_changes.js"; | import recentChangesDialog from "../dialogs/recent_changes.js"; | ||||||
| import sqlConsoleDialog from "../dialogs/sql_console.js"; | import sqlConsoleDialog from "../dialogs/sql_console.js"; | ||||||
| import searchTreeService from "./search_tree.js"; | import searchNotesService from "./search_notes.js"; | ||||||
| import labelsDialog from "../dialogs/labels.js"; | import attributesDialog from "../dialogs/attributes.js"; | ||||||
| import protectedSessionService from "./protected_session.js"; | import protectedSessionService from "./protected_session.js"; | ||||||
|  |  | ||||||
| function registerEntrypoints() { | function registerEntrypoints() { | ||||||
| @@ -22,27 +22,23 @@ function registerEntrypoints() { | |||||||
|  |  | ||||||
|     utils.bindShortcut('ctrl+l', addLinkDialog.showDialog); |     utils.bindShortcut('ctrl+l', addLinkDialog.showDialog); | ||||||
|  |  | ||||||
|     $("#jump-to-note-button").click(jumpToNoteDialog.showDialog); |     $("#jump-to-note-dialog-button").click(jumpToNoteDialog.showDialog); | ||||||
|     utils.bindShortcut('ctrl+j', jumpToNoteDialog.showDialog); |     utils.bindShortcut('ctrl+j', jumpToNoteDialog.showDialog); | ||||||
|  |  | ||||||
|     $("#show-note-revisions-button").click(noteRevisionsDialog.showCurrentNoteRevisions); |     $("#show-note-revisions-button").click(noteRevisionsDialog.showCurrentNoteRevisions); | ||||||
|  |  | ||||||
|     $("#show-source-button").click(noteSourceDialog.showDialog); |     $("#show-source-button").click(noteSourceDialog.showDialog); | ||||||
|     utils.bindShortcut('ctrl+u', noteSourceDialog.showDialog); |  | ||||||
|  |  | ||||||
|     $("#recent-changes-button").click(recentChangesDialog.showDialog); |     $("#recent-changes-button").click(recentChangesDialog.showDialog); | ||||||
|  |  | ||||||
|     $("#protected-session-on").click(protectedSessionService.enterProtectedSession); |     $("#protected-session-on").click(protectedSessionService.enterProtectedSession); | ||||||
|     $("#protected-session-off").click(protectedSessionService.leaveProtectedSession); |     $("#protected-session-off").click(protectedSessionService.leaveProtectedSession); | ||||||
|  |  | ||||||
|     $("#recent-notes-button").click(recentNotesDialog.showDialog); |     $("#toggle-search-button").click(searchNotesService.toggleSearch); | ||||||
|     utils.bindShortcut('ctrl+e', recentNotesDialog.showDialog); |     utils.bindShortcut('ctrl+s', searchNotesService.toggleSearch); | ||||||
|  |  | ||||||
|     $("#toggle-search-button").click(searchTreeService.toggleSearch); |     $(".show-attributes-button").click(attributesDialog.showDialog); | ||||||
|     utils.bindShortcut('ctrl+s', searchTreeService.toggleSearch); |     utils.bindShortcut('alt+a', attributesDialog.showDialog); | ||||||
|  |  | ||||||
|     $(".show-labels-button").click(labelsDialog.showDialog); |  | ||||||
|     utils.bindShortcut('alt+l', labelsDialog.showDialog); |  | ||||||
|  |  | ||||||
|     $("#options-button").click(optionsDialog.showDialog); |     $("#options-button").click(optionsDialog.showDialog); | ||||||
|  |  | ||||||
| @@ -57,7 +53,13 @@ function registerEntrypoints() { | |||||||
|         utils.bindShortcut('alt+right', window.history.forward); |         utils.bindShortcut('alt+right', window.history.forward); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     utils.bindShortcut('alt+m', e => $(".hide-toggle").toggleClass("suppressed")); |     utils.bindShortcut('alt+m', e => { | ||||||
|  |         $(".hide-toggle").toggle(); | ||||||
|  |  | ||||||
|  |         // when hiding switch display to block, otherwise grid still tries to display columns which shows | ||||||
|  |         // left empty column | ||||||
|  |         $("#container").css("display", $("#container").css("display") === "grid" ? "block" : "grid"); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     // hide (toggle) everything except for the note content for distraction free writing |     // hide (toggle) everything except for the note content for distraction free writing | ||||||
|     utils.bindShortcut('alt+t', e => { |     utils.bindShortcut('alt+t', e => { | ||||||
| @@ -109,27 +111,10 @@ function registerEntrypoints() { | |||||||
|         $("#note-detail-text").focus(); |         $("#note-detail-text").focus(); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     $(document).bind('keydown', 'ctrl+-', () => { |     if (utils.isElectron()) { | ||||||
|         if (utils.isElectron()) { |         $(document).bind('keydown', 'ctrl+-', zoomService.decreaseZoomFactor); | ||||||
|             const webFrame = require('electron').webFrame; |         $(document).bind('keydown', 'ctrl+=', zoomService.increaseZoomFactor); | ||||||
|  |     } | ||||||
|             if (webFrame.getZoomFactor() > 0.2) { |  | ||||||
|                 webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.1); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     $(document).bind('keydown', 'ctrl+=', () => { |  | ||||||
|         if (utils.isElectron()) { |  | ||||||
|             const webFrame = require('electron').webFrame; |  | ||||||
|  |  | ||||||
|             webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.1); |  | ||||||
|  |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     $("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus()); |     $("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus()); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ function getNotePathFromLink(url) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function getNodePathFromLabel(label) { | function getNotePathFromLabel(label) { | ||||||
|     const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); |     const notePathMatch = / \(([A-Za-z0-9/]+)\)/.exec(label); | ||||||
|  |  | ||||||
|     if (notePathMatch !== null) { |     if (notePathMatch !== null) { | ||||||
| @@ -23,7 +23,7 @@ function getNodePathFromLabel(label) { | |||||||
|     return null; |     return null; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function createNoteLink(notePath, noteTitle) { | async function createNoteLink(notePath, noteTitle = null) { | ||||||
|     if (!noteTitle) { |     if (!noteTitle) { | ||||||
|         const noteId = treeUtils.getNoteIdFromNotePath(notePath); |         const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
| @@ -90,6 +90,18 @@ function addTextToEditor(text) { | |||||||
|     doc.enqueueChanges(() => editor.data.insertText(text), doc.selection); |     doc.enqueueChanges(() => editor.data.insertText(text), doc.selection); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | ko.bindingHandlers.noteLink = { | ||||||
|  |     init: async function(element, valueAccessor, allBindings, viewModel, bindingContext) { | ||||||
|  |         const noteId = ko.unwrap(valueAccessor()); | ||||||
|  |  | ||||||
|  |         if (noteId) { | ||||||
|  |             const link = await createNoteLink(noteId); | ||||||
|  |  | ||||||
|  |             $(element).append(link); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }; | ||||||
|  |  | ||||||
| // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior | // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior | ||||||
| // of opening the link in new window/tab | // of opening the link in new window/tab | ||||||
| $(document).on('click', "a[action='note']", goToLink); | $(document).on('click', "a[action='note']", goToLink); | ||||||
| @@ -97,7 +109,7 @@ $(document).on('click', 'div.popover-content a, div.ui-tooltip-content a', goToL | |||||||
| $(document).on('dblclick', '#note-detail-text a', goToLink); | $(document).on('dblclick', '#note-detail-text a', goToLink); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     getNodePathFromLabel, |     getNotePathFromLabel, | ||||||
|     getNotePathFromLink, |     getNotePathFromLink, | ||||||
|     createNoteLink, |     createNoteLink, | ||||||
|     addLinkToEditor, |     addLinkToEditor, | ||||||
|   | |||||||
| @@ -1,8 +1,9 @@ | |||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
|  |  | ||||||
| const $changesToPushCount = $("#changes-to-push-count"); | const $outstandingSyncsCount = $("#outstanding-syncs-count"); | ||||||
|  |  | ||||||
|  | const syncMessageHandlers = []; | ||||||
| const messageHandlers = []; | const messageHandlers = []; | ||||||
|  |  | ||||||
| let ws; | let ws; | ||||||
| @@ -25,9 +26,17 @@ function subscribeToMessages(messageHandler) { | |||||||
|     messageHandlers.push(messageHandler); |     messageHandlers.push(messageHandler); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function subscribeToSyncMessages(messageHandler) { | ||||||
|  |     syncMessageHandlers.push(messageHandler); | ||||||
|  | } | ||||||
|  |  | ||||||
| function handleMessage(event) { | function handleMessage(event) { | ||||||
|     const message = JSON.parse(event.data); |     const message = JSON.parse(event.data); | ||||||
|  |  | ||||||
|  |     for (const messageHandler of messageHandlers) { | ||||||
|  |         messageHandler(message); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     if (message.type === 'sync') { |     if (message.type === 'sync') { | ||||||
|         lastPingTs = new Date().getTime(); |         lastPingTs = new Date().getTime(); | ||||||
|  |  | ||||||
| @@ -39,11 +48,11 @@ function handleMessage(event) { | |||||||
|  |  | ||||||
|         const syncData = message.data.filter(sync => sync.sourceId !== glob.sourceId); |         const syncData = message.data.filter(sync => sync.sourceId !== glob.sourceId); | ||||||
|  |  | ||||||
|         for (const messageHandler of messageHandlers) { |         for (const syncMessageHandler of syncMessageHandlers) { | ||||||
|             messageHandler(syncData); |             syncMessageHandler(syncData); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $changesToPushCount.html(message.changesToPushCount); |         $outstandingSyncsCount.html(message.outstandingSyncs); | ||||||
|     } |     } | ||||||
|     else if (message.type === 'sync-hash-check-failed') { |     else if (message.type === 'sync-hash-check-failed') { | ||||||
|         infoService.showError("Sync check failed!", 60000); |         infoService.showError("Sync check failed!", 60000); | ||||||
| @@ -73,26 +82,10 @@ setTimeout(() => { | |||||||
|  |  | ||||||
|     lastSyncId = glob.maxSyncIdAtLoad; |     lastSyncId = glob.maxSyncIdAtLoad; | ||||||
|     lastPingTs = new Date().getTime(); |     lastPingTs = new Date().getTime(); | ||||||
|     let connectionBrokenNotification = null; |  | ||||||
|  |  | ||||||
|     setInterval(async () => { |     setInterval(async () => { | ||||||
|         if (new Date().getTime() - lastPingTs > 30000) { |         if (new Date().getTime() - lastPingTs > 30000) { | ||||||
|             if (!connectionBrokenNotification) { |             console.log("Lost connection to server"); | ||||||
|                 connectionBrokenNotification = $.notify({ |  | ||||||
|                     // options |  | ||||||
|                     message: "Lost connection to server" |  | ||||||
|                 },{ |  | ||||||
|                     // options |  | ||||||
|                     type: 'danger', |  | ||||||
|                     delay: 100000000 // keep it until we explicitly close it |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         else if (connectionBrokenNotification) { |  | ||||||
|             await connectionBrokenNotification.close(); |  | ||||||
|             connectionBrokenNotification = null; |  | ||||||
|  |  | ||||||
|             infoService.showMessage("Re-connected to server"); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         ws.send(JSON.stringify({ |         ws.send(JSON.stringify({ | ||||||
| @@ -104,5 +97,6 @@ setTimeout(() => { | |||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     logError, |     logError, | ||||||
|     subscribeToMessages |     subscribeToMessages, | ||||||
|  |     subscribeToSyncMessages | ||||||
| }; | }; | ||||||
							
								
								
									
										54
									
								
								src/public/javascripts/services/note_autocomplete.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,54 @@ | |||||||
|  | import server from "./server.js"; | ||||||
|  |  | ||||||
|  | async function initNoteAutocomplete($el) { | ||||||
|  |     if (!$el.hasClass("ui-autocomplete-input")) { | ||||||
|  |         const $showRecentNotesButton = $("<span>") | ||||||
|  |             .addClass("input-group-addon show-recent-notes-button") | ||||||
|  |             .prop("title", "Show recent notes"); | ||||||
|  |  | ||||||
|  |         $el.after($showRecentNotesButton); | ||||||
|  |  | ||||||
|  |         $showRecentNotesButton.click(() => $el.autocomplete("search", "")); | ||||||
|  |  | ||||||
|  |         await $el.autocomplete({ | ||||||
|  |             appendTo: $el.parent().parent(), | ||||||
|  |             source: async function (request, response) { | ||||||
|  |                 const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); | ||||||
|  |  | ||||||
|  |                 if (result.length > 0) { | ||||||
|  |                     response(result.map(row => { | ||||||
|  |                         return { | ||||||
|  |                             label: row.label, | ||||||
|  |                             value: row.label + ' (' + row.value + ')' | ||||||
|  |                         } | ||||||
|  |                     })); | ||||||
|  |                 } | ||||||
|  |                 else { | ||||||
|  |                     response([{ | ||||||
|  |                         label: "No results", | ||||||
|  |                         value: "No results" | ||||||
|  |                     }]); | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             minLength: 0, | ||||||
|  |             change: function (event, ui) { | ||||||
|  |                 $el.trigger("change"); | ||||||
|  |             }, | ||||||
|  |             select: function (event, ui) { | ||||||
|  |                 if (ui.item.value === 'No results') { | ||||||
|  |                     return false; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ko.bindingHandlers.noteAutocomplete = { | ||||||
|  |     init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { | ||||||
|  |         initNoteAutocomplete($(element)); | ||||||
|  |     } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     initNoteAutocomplete | ||||||
|  | } | ||||||
| @@ -7,6 +7,7 @@ import utils from './utils.js'; | |||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| import messagingService from "./messaging.js"; | import messagingService from "./messaging.js"; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
|  | import linkService from "./link.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import NoteFull from "../entities/note_full.js"; | import NoteFull from "../entities/note_full.js"; | ||||||
| import noteDetailCode from './note_detail_code.js'; | import noteDetailCode from './note_detail_code.js'; | ||||||
| @@ -14,6 +15,8 @@ import noteDetailText from './note_detail_text.js'; | |||||||
| import noteDetailFile from './note_detail_file.js'; | import noteDetailFile from './note_detail_file.js'; | ||||||
| import noteDetailSearch from './note_detail_search.js'; | import noteDetailSearch from './note_detail_search.js'; | ||||||
| import noteDetailRender from './note_detail_render.js'; | import noteDetailRender from './note_detail_render.js'; | ||||||
|  | import bundleService from "./bundle.js"; | ||||||
|  | import noteAutocompleteService from "./note_autocomplete.js"; | ||||||
|  |  | ||||||
| const $noteTitle = $("#note-title"); | const $noteTitle = $("#note-title"); | ||||||
|  |  | ||||||
| @@ -22,10 +25,13 @@ const $noteDetailComponents = $(".note-detail-component"); | |||||||
| const $protectButton = $("#protect-button"); | const $protectButton = $("#protect-button"); | ||||||
| const $unprotectButton = $("#unprotect-button"); | const $unprotectButton = $("#unprotect-button"); | ||||||
| const $noteDetailWrapper = $("#note-detail-wrapper"); | const $noteDetailWrapper = $("#note-detail-wrapper"); | ||||||
|  | const $noteDetailComponentWrapper = $("#note-detail-component-wrapper"); | ||||||
| const $noteIdDisplay = $("#note-id-display"); | const $noteIdDisplay = $("#note-id-display"); | ||||||
| const $labelList = $("#label-list"); | const $attributeList = $("#attribute-list"); | ||||||
| const $labelListInner = $("#label-list-inner"); | const $attributeListInner = $("#attribute-list-inner"); | ||||||
| const $childrenOverview = $("#children-overview"); | const $childrenOverview = $("#children-overview"); | ||||||
|  | const $scriptArea = $("#note-detail-script-area"); | ||||||
|  | const $promotedAttributesContainer = $("#note-detail-promoted-attributes"); | ||||||
|  |  | ||||||
| let currentNote = null; | let currentNote = null; | ||||||
|  |  | ||||||
| @@ -116,9 +122,9 @@ async function saveNoteIfChanged() { | |||||||
| function setNoteBackgroundIfProtected(note) { | function setNoteBackgroundIfProtected(note) { | ||||||
|     const isProtected = !!note.isProtected; |     const isProtected = !!note.isProtected; | ||||||
|  |  | ||||||
|     $noteDetailWrapper.toggleClass("protected", isProtected); |     $noteDetailComponentWrapper.toggleClass("protected", isProtected); | ||||||
|     $protectButton.toggle(!isProtected); |     $protectButton.toggleClass("active", isProtected); | ||||||
|     $unprotectButton.toggle(isProtected); |     $unprotectButton.toggleClass("active", !isProtected); | ||||||
| } | } | ||||||
|  |  | ||||||
| let isNewNoteCreated = false; | let isNewNoteCreated = false; | ||||||
| @@ -150,6 +156,8 @@ async function loadNoteDetail(noteId) { | |||||||
|  |  | ||||||
|     $noteIdDisplay.html(noteId); |     $noteIdDisplay.html(noteId); | ||||||
|  |  | ||||||
|  |     setNoteBackgroundIfProtected(currentNote); | ||||||
|  |  | ||||||
|     await handleProtectedSession(); |     await handleProtectedSession(); | ||||||
|  |  | ||||||
|     $noteDetailWrapper.show(); |     $noteDetailWrapper.show(); | ||||||
| @@ -170,15 +178,18 @@ async function loadNoteDetail(noteId) { | |||||||
|         noteChangeDisabled = false; |         noteChangeDisabled = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     setNoteBackgroundIfProtected(currentNote); |  | ||||||
|     treeService.setBranchBackgroundBasedOnProtectedStatus(noteId); |     treeService.setBranchBackgroundBasedOnProtectedStatus(noteId); | ||||||
|  |  | ||||||
|     // after loading new note make sure editor is scrolled to the top |     // after loading new note make sure editor is scrolled to the top | ||||||
|     $noteDetailWrapper.scrollTop(0); |     $noteDetailWrapper.scrollTop(0); | ||||||
|  |  | ||||||
|     const labels = await loadLabelList(); |     $scriptArea.html(''); | ||||||
|  |  | ||||||
|     const hideChildrenOverview = labels.some(label => label.name === 'hideChildrenOverview'); |     await bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteView'); | ||||||
|  |  | ||||||
|  |     const attributes = await loadAttributes(); | ||||||
|  |  | ||||||
|  |     const hideChildrenOverview = attributes.some(attr => attr.type === 'label' && attr.name === 'hideChildrenOverview'); | ||||||
|     await showChildrenOverview(hideChildrenOverview); |     await showChildrenOverview(hideChildrenOverview); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -207,25 +218,207 @@ async function showChildrenOverview(hideChildrenOverview) { | |||||||
|     $childrenOverview.show(); |     $childrenOverview.show(); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function loadLabelList() { | async function loadAttributes() { | ||||||
|  |     $promotedAttributesContainer.empty(); | ||||||
|  |     $attributeList.hide(); | ||||||
|  |  | ||||||
|     const noteId = getCurrentNoteId(); |     const noteId = getCurrentNoteId(); | ||||||
|  |  | ||||||
|     const labels = await server.get('notes/' + noteId + '/labels'); |     const attributes = await server.get('notes/' + noteId + '/attributes'); | ||||||
|  |  | ||||||
|     $labelListInner.html(''); |     const promoted = attributes.filter(attr => (attr.type === 'label-definition' || attr.type === 'relation-definition') && attr.value.isPromoted); | ||||||
|  |  | ||||||
|     if (labels.length > 0) { |     let idx = 1; | ||||||
|         for (const label of labels) { |  | ||||||
|             $labelListInner.append(utils.formatLabel(label) + " "); |     async function createRow(definitionAttr, valueAttr) { | ||||||
|  |         const definition = definitionAttr.value; | ||||||
|  |         const inputId = "promoted-input-" + idx; | ||||||
|  |         const $tr = $("<tr>"); | ||||||
|  |         const $labelCell = $("<th>").append(valueAttr.name); | ||||||
|  |         const $input = $("<input>") | ||||||
|  |             .prop("id", inputId) | ||||||
|  |             .prop("tabindex", definitionAttr.position) | ||||||
|  |             .prop("attribute-id", valueAttr.isOwned ? valueAttr.attributeId : '') // if not owned, we'll force creation of a new attribute instead of updating the inherited one | ||||||
|  |             .prop("attribute-type", valueAttr.type) | ||||||
|  |             .prop("attribute-name", valueAttr.name) | ||||||
|  |             .prop("value", valueAttr.value) | ||||||
|  |             .addClass("form-control") | ||||||
|  |             .addClass("promoted-attribute-input"); | ||||||
|  |  | ||||||
|  |         idx++; | ||||||
|  |  | ||||||
|  |         const $inputCell = $("<td>").append($("<div>").addClass("input-group").append($input)); | ||||||
|  |  | ||||||
|  |         const $actionCell = $("<td>"); | ||||||
|  |         const $multiplicityCell = $("<td>"); | ||||||
|  |  | ||||||
|  |         $tr | ||||||
|  |             .append($labelCell) | ||||||
|  |             .append($inputCell) | ||||||
|  |             .append($actionCell) | ||||||
|  |             .append($multiplicityCell); | ||||||
|  |  | ||||||
|  |         if (valueAttr.type === 'label') { | ||||||
|  |             if (definition.labelType === 'text') { | ||||||
|  |                 $input.prop("type", "text"); | ||||||
|  |  | ||||||
|  |                 // no need to await for this, can be done asynchronously | ||||||
|  |                 server.get('attributes/values/' + encodeURIComponent(valueAttr.name)).then(attributeValues => { | ||||||
|  |                     if (attributeValues.length === 0) { | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     $input.autocomplete({ | ||||||
|  |                         // shouldn't be required and autocomplete should just accept array of strings, but that fails | ||||||
|  |                         // because we have overriden filter() function in autocomplete.js | ||||||
|  |                         source: attributeValues.map(attribute => { | ||||||
|  |                             return { | ||||||
|  |                                 attribute: attribute, | ||||||
|  |                                 value: attribute | ||||||
|  |                             } | ||||||
|  |                         }), | ||||||
|  |                         minLength: 0 | ||||||
|  |                     }); | ||||||
|  |  | ||||||
|  |                     $input.focus(() => $input.autocomplete("search", "")); | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |             else if (definition.labelType === 'number') { | ||||||
|  |                 $input.prop("type", "number"); | ||||||
|  |             } | ||||||
|  |             else if (definition.labelType === 'boolean') { | ||||||
|  |                 $input.prop("type", "checkbox"); | ||||||
|  |  | ||||||
|  |                 if (valueAttr.value === "true") { | ||||||
|  |                     $input.prop("checked", "checked"); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             else if (definition.labelType === 'date') { | ||||||
|  |                 $input.prop("type", "text"); | ||||||
|  |  | ||||||
|  |                 $input.datepicker({ | ||||||
|  |                     changeMonth: true, | ||||||
|  |                     changeYear: true, | ||||||
|  |                     dateFormat: "yy-mm-dd" | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 const $todayButton = $("<button>").addClass("btn btn-small").text("Today").click(() => { | ||||||
|  |                     $input.val(utils.formatDateISO(new Date())); | ||||||
|  |                     $input.trigger("change"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 $actionCell.append($todayButton); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 messagingService.logError("Unknown labelType=" + definitionAttr.labelType); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else if (valueAttr.type === 'relation') { | ||||||
|  |             if (valueAttr.value) { | ||||||
|  |                 $input.val((await treeUtils.getNoteTitle(valueAttr.value) + " (" + valueAttr.value + ")")); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // no need to wait for this | ||||||
|  |             noteAutocompleteService.initNoteAutocomplete($input); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             messagingService.logError("Unknown attribute type=" + valueAttr.type); | ||||||
|  |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $labelList.show(); |         if (definition.multiplicityType === "multivalue") { | ||||||
|     } |             const addButton = $("<span>") | ||||||
|     else { |                 .addClass("glyphicon glyphicon-plus pointer") | ||||||
|         $labelList.hide(); |                 .prop("title", "Add new attribute") | ||||||
|  |                 .click(async () => { | ||||||
|  |                 const $new = await createRow(definitionAttr, { | ||||||
|  |                     attributeId: "", | ||||||
|  |                     type: valueAttr.type, | ||||||
|  |                     name: definitionAttr.name, | ||||||
|  |                     value: "" | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 $tr.after($new); | ||||||
|  |  | ||||||
|  |                 $new.find('input').focus(); | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             const removeButton = $("<span>") | ||||||
|  |                 .addClass("glyphicon glyphicon-trash pointer") | ||||||
|  |                 .prop("title", "Remove this attribute") | ||||||
|  |                 .click(async () => { | ||||||
|  |                 if (valueAttr.attributeId) { | ||||||
|  |                     await server.remove("notes/" + noteId + "/attributes/" + valueAttr.attributeId); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 $tr.remove(); | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             $multiplicityCell.append(addButton).append("   ").append(removeButton); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return $tr; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return labels; |     if (promoted.length > 0) { | ||||||
|  |         const $tbody = $("<tbody>"); | ||||||
|  |  | ||||||
|  |         for (const definitionAttr of promoted) { | ||||||
|  |             const definitionType = definitionAttr.type; | ||||||
|  |             const valueType = definitionType.substr(0, definitionType.length - 11); | ||||||
|  |  | ||||||
|  |             let valueAttrs = attributes.filter(el => el.name === definitionAttr.name && el.type === valueType); | ||||||
|  |  | ||||||
|  |             if (valueAttrs.length === 0) { | ||||||
|  |                 valueAttrs.push({ | ||||||
|  |                     attributeId: "", | ||||||
|  |                     type: valueType, | ||||||
|  |                     name: definitionAttr.name, | ||||||
|  |                     value: "" | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (definitionAttr.value.multiplicityType === 'singlevalue') { | ||||||
|  |                 valueAttrs = valueAttrs.slice(0, 1); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             for (const valueAttr of valueAttrs) { | ||||||
|  |                 const $tr = await createRow(definitionAttr, valueAttr); | ||||||
|  |  | ||||||
|  |                 $tbody.append($tr); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // we replace the whole content in one step so there can't be any race conditions | ||||||
|  |         // (previously we saw promoted attributes doubling) | ||||||
|  |         $promotedAttributesContainer.empty().append($tbody); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         $attributeListInner.html(''); | ||||||
|  |  | ||||||
|  |         if (attributes.length > 0) { | ||||||
|  |             for (const attribute of attributes) { | ||||||
|  |                 if (attribute.type === 'label') { | ||||||
|  |                     $attributeListInner.append(utils.formatLabel(attribute) + " "); | ||||||
|  |                 } | ||||||
|  |                 else if (attribute.type === 'relation') { | ||||||
|  |                     $attributeListInner.append(attribute.name + "="); | ||||||
|  |                     $attributeListInner.append(await linkService.createNoteLink(attribute.value)); | ||||||
|  |                     $attributeListInner.append(" "); | ||||||
|  |                 } | ||||||
|  |                 else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') { | ||||||
|  |                     $attributeListInner.append(attribute.name + " definition "); | ||||||
|  |                 } | ||||||
|  |                 else { | ||||||
|  |                     messagingService.logError("Unknown attr type: " + attribute.type); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             $attributeList.show(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return attributes; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function loadNote(noteId) { | async function loadNote(noteId) { | ||||||
| @@ -240,7 +433,7 @@ function focus() { | |||||||
|     getComponent(note.type).focus(); |     getComponent(note.type).focus(); | ||||||
| } | } | ||||||
|  |  | ||||||
| messagingService.subscribeToMessages(syncData => { | messagingService.subscribeToSyncMessages(syncData => { | ||||||
|     if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) { |     if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) { | ||||||
|         infoService.showMessage('Reloading note because of background changes'); |         infoService.showMessage('Reloading note because of background changes'); | ||||||
|  |  | ||||||
| @@ -248,6 +441,35 @@ messagingService.subscribeToMessages(syncData => { | |||||||
|     } |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | $promotedAttributesContainer.on('change', '.promoted-attribute-input', async event => { | ||||||
|  |     const $attr = $(event.target); | ||||||
|  |  | ||||||
|  |     let value; | ||||||
|  |  | ||||||
|  |     if ($attr.prop("type") === "checkbox") { | ||||||
|  |         value = $attr.is(':checked') ? "true" : "false"; | ||||||
|  |     } | ||||||
|  |     else if ($attr.prop("attribute-type") === "relation") { | ||||||
|  |         if ($attr.val()) { | ||||||
|  |             value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel($attr.val())); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         value = $attr.val(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     const result = await server.put("notes/" + getCurrentNoteId() + "/attribute", { | ||||||
|  |         attributeId: $attr.prop("attribute-id"), | ||||||
|  |         type: $attr.prop("attribute-type"), | ||||||
|  |         name: $attr.prop("attribute-name"), | ||||||
|  |         value: value | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     $attr.prop("attribute-id", result.attributeId); | ||||||
|  |  | ||||||
|  |     infoService.showMessage("Attribute has been saved."); | ||||||
|  | }); | ||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     $noteTitle.on('input', () => { |     $noteTitle.on('input', () => { | ||||||
|         noteChanged(); |         noteChanged(); | ||||||
| @@ -276,7 +498,7 @@ export default { | |||||||
|     getCurrentNoteId, |     getCurrentNoteId, | ||||||
|     newNoteCreated, |     newNoteCreated, | ||||||
|     focus, |     focus, | ||||||
|     loadLabelList, |     loadAttributes, | ||||||
|     saveNote, |     saveNote, | ||||||
|     saveNoteIfChanged, |     saveNoteIfChanged, | ||||||
|     noteChanged |     noteChanged | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ async function show() { | |||||||
|             lint: true, |             lint: true, | ||||||
|             gutters: ["CodeMirror-lint-markers"], |             gutters: ["CodeMirror-lint-markers"], | ||||||
|             lineNumbers: true, |             lineNumbers: true, | ||||||
|             tabindex: 2 // so that tab from title will lead to code editor focus |             tabindex: 100 | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         codeEditor.on('change', noteDetailService.noteChanged); |         codeEditor.on('change', noteDetailService.noteChanged); | ||||||
| @@ -75,9 +75,7 @@ async function executeCurrentNote() { | |||||||
|     const currentNote = noteDetailService.getCurrentNote(); |     const currentNote = noteDetailService.getCurrentNote(); | ||||||
|  |  | ||||||
|     if (currentNote.mime.endsWith("env=frontend")) { |     if (currentNote.mime.endsWith("env=frontend")) { | ||||||
|         const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId()); |         await bundleService.getAndExecuteBundle(noteDetailService.getCurrentNoteId()); | ||||||
|  |  | ||||||
|         bundleService.executeBundle(bundle); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (currentNote.mime.endsWith("env=backend")) { |     if (currentNote.mime.endsWith("env=backend")) { | ||||||
|   | |||||||
| @@ -14,13 +14,13 @@ const $fileOpen = $("#file-open"); | |||||||
| async function show() { | async function show() { | ||||||
|     const currentNote = noteDetailService.getCurrentNote(); |     const currentNote = noteDetailService.getCurrentNote(); | ||||||
|  |  | ||||||
|     const labels = await server.get('notes/' + currentNote.noteId + '/labels'); |     const attributes = await server.get('notes/' + currentNote.noteId + '/attributes'); | ||||||
|     const labelMap = utils.toObject(labels, l => [l.name, l.value]); |     const attributeMap = utils.toObject(attributes, l => [l.name, l.value]); | ||||||
|  |  | ||||||
|     $noteDetailFile.show(); |     $noteDetailFile.show(); | ||||||
|  |  | ||||||
|     $fileFileName.text(labelMap.original_file_name); |     $fileFileName.text(attributeMap.original_file_name); | ||||||
|     $fileFileSize.text(labelMap.file_size + " bytes"); |     $fileFileSize.text(attributeMap.file_size + " bytes"); | ||||||
|     $fileFileType.text(currentNote.mime); |     $fileFileType.text(currentNote.mime); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,13 @@ async function show() { | |||||||
|  |  | ||||||
|         textEditor = await BalloonEditor.create($noteDetailText[0], {}); |         textEditor = await BalloonEditor.create($noteDetailText[0], {}); | ||||||
|  |  | ||||||
|         textEditor.model.document.on('change', noteDetailService.noteChanged); |         textEditor.model.document.on('change', () => { | ||||||
|  |                 // change is triggered on just marker/selection changes which is not interesting for us | ||||||
|  |                 if (textEditor.model.document.differ.getChanges().length > 0) { | ||||||
|  |                     noteDetailService.noteChanged(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     textEditor.setData(noteDetailService.getCurrentNote().content); |     textEditor.setData(noteDetailService.getCurrentNote().content); | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								src/public/javascripts/services/options_init.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,9 @@ | |||||||
|  | import server from "./server.js"; | ||||||
|  |  | ||||||
|  | const optionsReady = new Promise((resolve, reject) => { | ||||||
|  |     $(document).ready(() => server.get('options').then(resolve)); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     optionsReady | ||||||
|  | } | ||||||
| @@ -39,7 +39,10 @@ function ensureProtectedSession(requireProtectedSession, modal) { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         $dialog.dialog({ |         $dialog.dialog({ | ||||||
|             modal: modal, |             // modal: modal, | ||||||
|  |             // everything is now non-modal, because modal dialog caused weird high CPU usage on opening | ||||||
|  |             // and tearing of text input | ||||||
|  |             modal: false, | ||||||
|             width: 400, |             width: 400, | ||||||
|             open: () => { |             open: () => { | ||||||
|                 if (!modal) { |                 if (!modal) { | ||||||
| @@ -80,11 +83,10 @@ async function setupProtectedSession() { | |||||||
|         $noteDetailWrapper.show(); |         $noteDetailWrapper.show(); | ||||||
|  |  | ||||||
|         protectedSessionDeferred.resolve(); |         protectedSessionDeferred.resolve(); | ||||||
|  |         protectedSessionDeferred = null; | ||||||
|  |  | ||||||
|         $protectedSessionOnButton.addClass('active'); |         $protectedSessionOnButton.addClass('active'); | ||||||
|         $protectedSessionOffButton.removeClass('active'); |         $protectedSessionOffButton.removeClass('active'); | ||||||
|  |  | ||||||
|         protectedSessionDeferred = null; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -105,6 +107,10 @@ async function enterProtectedSessionOnServer(password) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function protectNoteAndSendToServer() { | async function protectNoteAndSendToServer() { | ||||||
|  |     if (noteDetailService.getCurrentNote().isProtected) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     await ensureProtectedSession(true, true); |     await ensureProtectedSession(true, true); | ||||||
|  |  | ||||||
|     const note = noteDetailService.getCurrentNote(); |     const note = noteDetailService.getCurrentNote(); | ||||||
| @@ -118,6 +124,10 @@ async function protectNoteAndSendToServer() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function unprotectNoteAndSendToServer() { | async function unprotectNoteAndSendToServer() { | ||||||
|  |     if (!noteDetailService.getCurrentNote().isProtected) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     await ensureProtectedSession(true, true); |     await ensureProtectedSession(true, true); | ||||||
|  |  | ||||||
|     const note = noteDetailService.getCurrentNote(); |     const note = noteDetailService.getCurrentNote(); | ||||||
|   | |||||||
| @@ -1,13 +1,11 @@ | |||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
| import server from "./server.js"; | import optionsInitService from './options_init.js'; | ||||||
|  |  | ||||||
| let lastProtectedSessionOperationDate = null; | let lastProtectedSessionOperationDate = null; | ||||||
| let protectedSessionTimeout = null; | let protectedSessionTimeout = null; | ||||||
| let protectedSessionId = null; | let protectedSessionId = null; | ||||||
|  |  | ||||||
| $(document).ready(() => { | optionsInitService.optionsReady.then(options => protectedSessionTimeout = options.protectedSessionTimeout); | ||||||
|     server.get('options').then(options => protectedSessionTimeout = options.protectedSessionTimeout); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| setInterval(() => { | setInterval(() => { | ||||||
|     if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) { |     if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) { | ||||||
|   | |||||||
| @@ -2,14 +2,21 @@ import treeService from './tree.js'; | |||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import infoService from './info.js'; | import infoService from './info.js'; | ||||||
|  | import linkService from './link.js'; | ||||||
|  |  | ||||||
| function ScriptApi(startNote, currentNote) { | function ScriptApi(startNote, currentNote, originEntity = null) { | ||||||
|     const $pluginButtons = $("#plugin-buttons"); |     const $pluginButtons = $("#plugin-buttons"); | ||||||
|  |  | ||||||
|     async function activateNote(notePath) { |     async function activateNote(notePath) { | ||||||
|         await treeService.activateNode(notePath); |         await treeService.activateNode(notePath); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async function activateNewNote(notePath) { | ||||||
|  |         await treeService.reload(); | ||||||
|  |  | ||||||
|  |         await treeService.activateNode(notePath, true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     function addButtonToToolbar(buttonId, button) { |     function addButtonToToolbar(buttonId, button) { | ||||||
|         $("#" + buttonId).remove(); |         $("#" + buttonId).remove(); | ||||||
|  |  | ||||||
| @@ -42,7 +49,9 @@ function ScriptApi(startNote, currentNote) { | |||||||
|             script: script, |             script: script, | ||||||
|             params: prepareParams(params), |             params: prepareParams(params), | ||||||
|             startNoteId: startNote.noteId, |             startNoteId: startNote.noteId, | ||||||
|             currentNoteId: currentNote.noteId |             currentNoteId: currentNote.noteId, | ||||||
|  |             originEntityName: originEntity ? originEntity.constructor.tableName : null, | ||||||
|  |             originEntityId: originEntity ? originEntity.noteId : null | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         return ret.executionResult; |         return ret.executionResult; | ||||||
| @@ -51,15 +60,19 @@ function ScriptApi(startNote, currentNote) { | |||||||
|     return { |     return { | ||||||
|         startNote: startNote, |         startNote: startNote, | ||||||
|         currentNote: currentNote, |         currentNote: currentNote, | ||||||
|  |         originEntity: originEntity, | ||||||
|         addButtonToToolbar, |         addButtonToToolbar, | ||||||
|         activateNote, |         activateNote, | ||||||
|  |         activateNewNote, | ||||||
|         getInstanceName: () => window.glob.instanceName, |         getInstanceName: () => window.glob.instanceName, | ||||||
|         runOnServer, |         runOnServer, | ||||||
|         formatDateISO: utils.formatDateISO, |         formatDateISO: utils.formatDateISO, | ||||||
|         parseDate: utils.parseDate, |         parseDate: utils.parseDate, | ||||||
|         showMessage: infoService.showMessage, |         showMessage: infoService.showMessage, | ||||||
|         showError: infoService.showError, |         showError: infoService.showError, | ||||||
|         reloadTree: treeService.reload |         reloadTree: treeService.reload, // deprecated | ||||||
|  |         refreshTree: treeService.reload, | ||||||
|  |         createNoteLink: linkService.createNoteLink | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| import ScriptApi from './script_api.js'; | import ScriptApi from './script_api.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
|  |  | ||||||
| function ScriptContext(startNote, allNotes) { | function ScriptContext(startNote, allNotes, originEntity = null) { | ||||||
|     const modules = {}; |     const modules = {}; | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|         modules: modules, |         modules: modules, | ||||||
|         notes: utils.toObject(allNotes, note => [note.noteId, note]), |         notes: utils.toObject(allNotes, note => [note.noteId, note]), | ||||||
|         apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]), |         apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note, originEntity)]), | ||||||
|         require: moduleNoteIds => { |         require: moduleNoteIds => { | ||||||
|             return moduleName => { |             return moduleName => { | ||||||
|                 const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); |                 const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|  | import treeUtils from "./tree_utils.js"; | ||||||
| 
 | 
 | ||||||
| const $tree = $("#tree"); | const $tree = $("#tree"); | ||||||
| const $searchInput = $("input[name='search-text']"); | const $searchInput = $("input[name='search-text']"); | ||||||
| @@ -7,40 +8,62 @@ const $resetSearchButton = $("#reset-search-button"); | |||||||
| const $doSearchButton = $("#do-search-button"); | const $doSearchButton = $("#do-search-button"); | ||||||
| const $saveSearchButton = $("#save-search-button"); | const $saveSearchButton = $("#save-search-button"); | ||||||
| const $searchBox = $("#search-box"); | const $searchBox = $("#search-box"); | ||||||
|  | const $searchResults = $("#search-results"); | ||||||
|  | const $searchResultsInner = $("#search-results-inner"); | ||||||
|  | const $closeSearchButton = $("#close-search-button"); | ||||||
|  | 
 | ||||||
|  | function showSearch() { | ||||||
|  |     $searchBox.show(); | ||||||
|  |     $searchInput.focus(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function hideSearch() { | ||||||
|  |     resetSearch(); | ||||||
|  | 
 | ||||||
|  |     $searchResults.hide(); | ||||||
|  |     $searchBox.hide(); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| function toggleSearch() { | function toggleSearch() { | ||||||
|     if ($searchBox.is(":hidden")) { |     if ($searchBox.is(":hidden")) { | ||||||
|         $searchBox.show(); |         showSearch(); | ||||||
|         $searchInput.focus(); |  | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         resetSearch(); |         hideSearch(); | ||||||
| 
 |  | ||||||
|         $searchBox.hide(); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function resetSearch() { | function resetSearch() { | ||||||
|     $searchInput.val(""); |     $searchInput.val(""); | ||||||
| 
 |  | ||||||
|     getTree().clearFilter(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getTree() { | function getTree() { | ||||||
|     return $tree.fancytree('getTree'); |     return $tree.fancytree('getTree'); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function doSearch() { | async function doSearch(searchText) { | ||||||
|     const searchText = $searchInput.val(); |     if (searchText) { | ||||||
| 
 |         $searchInput.val(searchText); | ||||||
|     const noteIds = await server.get('search/' + encodeURIComponent(searchText)); |     } | ||||||
| 
 |     else { | ||||||
|     for (const noteId of noteIds) { |         searchText = $searchInput.val(); | ||||||
|         await treeService.expandToNote(noteId, {noAnimation: true, noEvents: true}); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Pass a string to perform case insensitive matching
 |     const results = await server.get('search/' + encodeURIComponent(searchText)); | ||||||
|     getTree().filterBranches(node => noteIds.includes(node.data.noteId)); | 
 | ||||||
|  |     $searchResultsInner.empty(); | ||||||
|  |     $searchResults.show(); | ||||||
|  | 
 | ||||||
|  |     for (const result of results) { | ||||||
|  |         const link = $('<a>', { | ||||||
|  |             href: 'javascript:', | ||||||
|  |             text: result.title | ||||||
|  |         }).attr('action', 'note').attr('note-path', result.path); | ||||||
|  | 
 | ||||||
|  |         const $result = $('<li>').append(link); | ||||||
|  | 
 | ||||||
|  |         $searchResultsInner.append($result); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function saveSearch() { | async function saveSearch() { | ||||||
| @@ -71,6 +94,11 @@ $resetSearchButton.click(resetSearch); | |||||||
| 
 | 
 | ||||||
| $saveSearchButton.click(saveSearch); | $saveSearchButton.click(saveSearch); | ||||||
| 
 | 
 | ||||||
|  | $closeSearchButton.click(hideSearch); | ||||||
|  | 
 | ||||||
| export default { | export default { | ||||||
|     toggleSearch |     toggleSearch, | ||||||
|  |     resetSearch, | ||||||
|  |     showSearch, | ||||||
|  |     doSearch | ||||||
| }; | }; | ||||||
| @@ -5,7 +5,7 @@ import infoService from "./info.js"; | |||||||
| function getHeaders() { | function getHeaders() { | ||||||
|     let protectedSessionId = null; |     let protectedSessionId = null; | ||||||
|  |  | ||||||
|     try { // this is because protected session might not be declared in some cases - like when it's included in migration page |     try { // this is because protected session might not be declared in some cases | ||||||
|         protectedSessionId = protectedSessionHolder.getProtectedSessionId(); |         protectedSessionId = protectedSessionHolder.getProtectedSessionId(); | ||||||
|     } |     } | ||||||
|     catch(e) {} |     catch(e) {} | ||||||
|   | |||||||
| @@ -4,14 +4,30 @@ import linkService from "./link.js"; | |||||||
|  |  | ||||||
| function setupTooltip() { | function setupTooltip() { | ||||||
|     $(document).tooltip({ |     $(document).tooltip({ | ||||||
|         items: "#note-detail-text a", |         items: "body a", | ||||||
|         content: function (callback) { |         content: function (callback) { | ||||||
|             const notePath = linkService.getNotePathFromLink($(this).attr("href")); |             let notePath = linkService.getNotePathFromLink($(this).attr("href")); | ||||||
|  |  | ||||||
|             if (notePath !== null) { |             if (!notePath) { | ||||||
|  |                 notePath = $(this).attr("note-path"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (notePath) { | ||||||
|                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); |                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|                 noteDetailService.loadNote(noteId).then(note => callback(note.content)); |                 noteDetailService.loadNote(noteId).then(note => { | ||||||
|  |                     if (!note.content.trim()) { | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     if (note.type === 'text') { | ||||||
|  |                         callback(note.content); | ||||||
|  |                     } | ||||||
|  |                     else if (note.type === 'code') { | ||||||
|  |                         callback($("<pre>").text(note.content).prop('outerHTML')); | ||||||
|  |                     } | ||||||
|  |                     // other types of notes don't have tooltip preview | ||||||
|  |                 }); | ||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|         close: function (event, ui) { |         close: function (event, ui) { | ||||||
|   | |||||||
| @@ -8,7 +8,6 @@ import treeChangesService from './branches.js'; | |||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| import recentNotesDialog from '../dialogs/recent_notes.js'; |  | ||||||
| import treeCache from './tree_cache.js'; | import treeCache from './tree_cache.js'; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
| import treeBuilder from "./tree_builder.js"; | import treeBuilder from "./tree_builder.js"; | ||||||
| @@ -101,14 +100,22 @@ async function expandToNote(notePath, expandOpts) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| async function activateNode(notePath) { | async function activateNode(notePath, newNote) { | ||||||
|     utils.assertArguments(notePath); |     utils.assertArguments(notePath); | ||||||
|  |  | ||||||
|     const node = await expandToNote(notePath); |     const node = await expandToNote(notePath); | ||||||
|  |  | ||||||
|     await node.setActive(); |     if (newNote) { | ||||||
|  |         noteDetailService.newNoteCreated(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // we use noFocus because when we reload the tree because of background changes | ||||||
|  |     // we don't want the reload event to steal focus from whatever was focused before | ||||||
|  |     await node.setActive(true, { noFocus: true }); | ||||||
|  |  | ||||||
|     clearSelectedNodes(); |     clearSelectedNodes(); | ||||||
|  |  | ||||||
|  |     return node; | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -183,7 +190,7 @@ async function getRunPath(notePath) { | |||||||
|     return effectivePath.reverse(); |     return effectivePath.reverse(); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function showParentList(noteId, node) { | async function showPaths(noteId, node) { | ||||||
|     utils.assertArguments(noteId, node); |     utils.assertArguments(noteId, node); | ||||||
|  |  | ||||||
|     const note = await treeCache.getNote(noteId); |     const note = await treeCache.getNote(noteId); | ||||||
| @@ -191,26 +198,21 @@ async function showParentList(noteId, node) { | |||||||
|  |  | ||||||
|     $notePathCount.html(parents.length + " path" + (parents.length > 0 ? "s" : "")); |     $notePathCount.html(parents.length + " path" + (parents.length > 0 ? "s" : "")); | ||||||
|  |  | ||||||
|     if (parents.length <= 1) { |     $notePathList.empty(); | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         //$notePathList.show(); |  | ||||||
|         $notePathList.empty(); |  | ||||||
|  |  | ||||||
|         for (const parentNote of parents) { |     for (const parentNote of parents) { | ||||||
|             const parentNotePath = await getSomeNotePath(parentNote); |         const parentNotePath = await getSomeNotePath(parentNote); | ||||||
|             // this is to avoid having root notes leading '/' |         // this is to avoid having root notes leading '/' | ||||||
|             const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId; |         const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId; | ||||||
|             const title = await treeUtils.getNotePathTitle(notePath); |         const title = await treeUtils.getNotePathTitle(notePath); | ||||||
|  |  | ||||||
|             const item = $("<li/>").append(await linkService.createNoteLink(notePath, title)); |         const item = $("<li/>").append(await linkService.createNoteLink(notePath, title)); | ||||||
|  |  | ||||||
|             if (node.getParent().data.noteId === parentNote.noteId) { |         if (node.getParent().data.noteId === parentNote.noteId) { | ||||||
|                 item.addClass("current"); |             item.addClass("current"); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             $notePathList.append(item); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         $notePathList.append(item); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -244,6 +246,15 @@ async function setExpandedToServer(branchId, isExpanded) { | |||||||
|     await server.put('branches/' + branchId + '/expanded/' + expandedNum); |     await server.put('branches/' + branchId + '/expanded/' + expandedNum); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function addRecentNote(branchId, notePath) { | ||||||
|  |     setTimeout(async () => { | ||||||
|  |         // we include the note into recent list only if the user stayed on the note at least 5 seconds | ||||||
|  |         if (notePath && notePath === getCurrentNotePath()) { | ||||||
|  |             await server.put('recent-notes/' + branchId + '/' + encodeURIComponent(notePath)); | ||||||
|  |         } | ||||||
|  |     }, 1500); | ||||||
|  | } | ||||||
|  |  | ||||||
| function setCurrentNotePathToHash(node) { | function setCurrentNotePathToHash(node) { | ||||||
|     utils.assertArguments(node); |     utils.assertArguments(node); | ||||||
|  |  | ||||||
| @@ -252,7 +263,7 @@ function setCurrentNotePathToHash(node) { | |||||||
|  |  | ||||||
|     document.location.hash = currentNotePath; |     document.location.hash = currentNotePath; | ||||||
|  |  | ||||||
|     recentNotesDialog.addRecentNote(currentBranchId, currentNotePath); |     addRecentNote(currentBranchId, currentNotePath); | ||||||
| } | } | ||||||
|  |  | ||||||
| function getSelectedNodes(stopOnParents = false) { | function getSelectedNodes(stopOnParents = false) { | ||||||
| @@ -280,11 +291,11 @@ async function treeInitialized() { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (startNotePath) { |     if (startNotePath) { | ||||||
|         await activateNode(startNotePath); |         const node = await activateNode(startNotePath); | ||||||
|  |  | ||||||
|         // looks like this this doesn't work when triggered immediatelly after activating node |         // looks like this this doesn't work when triggered immediatelly after activating node | ||||||
|         // so waiting a second helps |         // so waiting a second helps | ||||||
|         setTimeout(scrollToCurrentNote, 1000); |         setTimeout(() => node.makeVisible({scrollIntoView: true}), 1000); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -323,7 +334,7 @@ function initFancyTree(tree) { | |||||||
|  |  | ||||||
|             noteDetailService.switchToNote(node.noteId); |             noteDetailService.switchToNote(node.noteId); | ||||||
|  |  | ||||||
|             showParentList(node.noteId, data.node); |             showPaths(node.noteId, data.node); | ||||||
|         }, |         }, | ||||||
|         expand: (event, data) => setExpandedToServer(data.node.data.branchId, true), |         expand: (event, data) => setExpandedToServer(data.node.data.branchId, true), | ||||||
|         collapse: (event, data) => setExpandedToServer(data.node.data.branchId, false), |         collapse: (event, data) => setExpandedToServer(data.node.data.branchId, false), | ||||||
| @@ -502,7 +513,13 @@ async function showTree() { | |||||||
|     initFancyTree(tree); |     initFancyTree(tree); | ||||||
| } | } | ||||||
|  |  | ||||||
| messagingService.subscribeToMessages(syncData => { | messagingService.subscribeToMessages(message => { | ||||||
|  |    if (message.type === 'refresh-tree') { | ||||||
|  |        reload(); | ||||||
|  |    } | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | messagingService.subscribeToSyncMessages(syncData => { | ||||||
|     if (syncData.some(sync => sync.entityName === 'branches') |     if (syncData.some(sync => sync.entityName === 'branches') | ||||||
|         || syncData.some(sync => sync.entityName === 'notes')) { |         || syncData.some(sync => sync.entityName === 'notes')) { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -74,14 +74,21 @@ async function prepareRealBranch(parentNote) { | |||||||
|  |  | ||||||
| async function prepareSearchBranch(note) { | async function prepareSearchBranch(note) { | ||||||
|     const fullNote = await noteDetailService.loadNote(note.noteId); |     const fullNote = await noteDetailService.loadNote(note.noteId); | ||||||
|     const noteIds = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString)); |     const results = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString)); | ||||||
|  |  | ||||||
|  |     const noteIds = results.map(res => res.noteId); | ||||||
|  |  | ||||||
|  |     // force to load all the notes at once instead of one by one | ||||||
|  |     await treeCache.getNotes(noteIds); | ||||||
|  |  | ||||||
|  |     for (const result of results) { | ||||||
|  |         const origBranch = await treeCache.getBranch(result.branchId); | ||||||
|  |  | ||||||
|     for (const noteId of noteIds) { |  | ||||||
|         const branch = new Branch(treeCache, { |         const branch = new Branch(treeCache, { | ||||||
|             branchId: "virt" + utils.randomString(10), |             branchId: "virt" + utils.randomString(10), | ||||||
|             noteId: noteId, |             noteId: result.noteId, | ||||||
|             parentNoteId: note.noteId, |             parentNoteId: note.noteId, | ||||||
|             prefix: '', |             prefix: origBranch.prefix, | ||||||
|             virtual: true |             virtual: true | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -108,6 +115,10 @@ async function getExtraClasses(note) { | |||||||
|         extraClasses.push("multiple-parents"); |         extraClasses.push("multiple-parents"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (note.cssClass) { | ||||||
|  |         extraClasses.push(note.cssClass); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     extraClasses.push(note.type); |     extraClasses.push(note.type); | ||||||
|  |  | ||||||
|     return extraClasses.join(" "); |     return extraClasses.join(" "); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import utils from "./utils.js"; | |||||||
| import Branch from "../entities/branch.js"; | import Branch from "../entities/branch.js"; | ||||||
| import NoteShort from "../entities/note_short.js"; | import NoteShort from "../entities/note_short.js"; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
|  | import messagingService from "./messaging.js"; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
|  |  | ||||||
| class TreeCache { | class TreeCache { | ||||||
| @@ -48,12 +49,14 @@ class TreeCache { | |||||||
|  |  | ||||||
|         return noteIds.map(noteId => { |         return noteIds.map(noteId => { | ||||||
|             if (!this.notes[noteId]) { |             if (!this.notes[noteId]) { | ||||||
|                 throw new Error(`Can't find note ${noteId}`); |                 messagingService.logError(`Can't find note ${noteId}`); | ||||||
|  |  | ||||||
|  |                 return null; | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 return this.notes[noteId]; |                 return this.notes[noteId]; | ||||||
|             } |             } | ||||||
|         }); |         }).filter(note => note !== null); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return NoteShort */ |     /** @return NoteShort */ | ||||||
|   | |||||||
| @@ -42,7 +42,7 @@ const keyBindings = { | |||||||
|     }, |     }, | ||||||
|     "shift+up": node => { |     "shift+up": node => { | ||||||
|         node.navigate($.ui.keyCode.UP, true).then(() => { |         node.navigate($.ui.keyCode.UP, true).then(() => { | ||||||
|             const currentNode = getCurrentNode(); |             const currentNode = treeService.getCurrentNode(); | ||||||
|  |  | ||||||
|             if (currentNode.isSelected()) { |             if (currentNode.isSelected()) { | ||||||
|                 node.setSelected(false); |                 node.setSelected(false); | ||||||
|   | |||||||
| @@ -52,6 +52,15 @@ async function getNotePathTitle(notePath) { | |||||||
|  |  | ||||||
|     const titlePath = []; |     const titlePath = []; | ||||||
|  |  | ||||||
|  |     if (notePath.startsWith('root/')) { | ||||||
|  |         notePath = notePath.substr(5); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // special case when we want just root's title | ||||||
|  |     if (notePath === 'root') { | ||||||
|  |         return await getNoteTitle(notePath); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     let parentNoteId = 'root'; |     let parentNoteId = 'root'; | ||||||
|  |  | ||||||
|     for (const noteId of notePath.split('/')) { |     for (const noteId of notePath.split('/')) { | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ function isElectron() { | |||||||
| function assertArguments() { | function assertArguments() { | ||||||
|     for (const i in arguments) { |     for (const i in arguments) { | ||||||
|         if (!arguments[i]) { |         if (!arguments[i]) { | ||||||
|             throw new Error(`Argument idx#${i} should not be falsy: ${arguments[i]}`); |             console.trace(`Argument idx#${i} should not be falsy: ${arguments[i]}`); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										51
									
								
								src/public/javascripts/services/zoom.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,51 @@ | |||||||
|  | import server from "./server.js"; | ||||||
|  | import utils from "./utils.js"; | ||||||
|  | import optionsInitService from "./options_init.js"; | ||||||
|  |  | ||||||
|  | const MIN_ZOOM = 0.5; | ||||||
|  | const MAX_ZOOM = 2.0; | ||||||
|  |  | ||||||
|  | async function decreaseZoomFactor() { | ||||||
|  |     await setZoomFactorAndSave(getCurrentZoom() - 0.1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function increaseZoomFactor() { | ||||||
|  |     await setZoomFactorAndSave(getCurrentZoom() + 0.1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function setZoomFactor(zoomFactor) { | ||||||
|  |     zoomFactor = parseFloat(zoomFactor); | ||||||
|  |  | ||||||
|  |     const webFrame = require('electron').webFrame; | ||||||
|  |     webFrame.setZoomFactor(zoomFactor); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function setZoomFactorAndSave(zoomFactor) { | ||||||
|  |     if (!utils.isElectron()) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (zoomFactor >= MIN_ZOOM && zoomFactor <= MAX_ZOOM) { | ||||||
|  |         setZoomFactor(zoomFactor); | ||||||
|  |  | ||||||
|  |         await server.put('options/zoomFactor/' + zoomFactor); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         console.log(`Zoom factor ${zoomFactor} outside of the range, ignored.`); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function getCurrentZoom() { | ||||||
|  |     return require('electron').webFrame.getZoomFactor(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | if (utils.isElectron()) { | ||||||
|  |     optionsInitService.optionsReady.then(options => setZoomFactor(options.zoomFactor)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |     decreaseZoomFactor, | ||||||
|  |     increaseZoomFactor, | ||||||
|  |     setZoomFactor, | ||||||
|  |     setZoomFactorAndSave | ||||||
|  | } | ||||||