File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -166,6 +166,22 @@ define(["sugar-web/datastore"], function(datastore) {
166166 return entries . filter ( ( entry ) => entry . metadata . activity == activity ) ;
167167 }
168168
169+ // Get entries by objectId
170+ journal . getByObjectId = function ( objectId ) {
171+ if ( ! objectId ) return null ;
172+ for ( var i = 0 ; i < entries . length ; i ++ ) {
173+ if ( entries [ i ] . objectId == objectId ) {
174+ return entries [ i ] ;
175+ }
176+ }
177+ return null ;
178+ }
179+
180+ // Generate UUID
181+ journal . generateUUID = function ( ) {
182+ return datastore . createUUID ( ) ;
183+ }
184+
169185 // Copy & Duplicate Operations
170186 journal . copyToLocal = async function ( entry , journalId ) {
171187 const { metadata, text } = await journal . loadEntry ( entry , journalId ) ;
Original file line number Diff line number Diff line change @@ -258,17 +258,16 @@ const MainScreen = {
258258 if ( activityExist ) {
259259 let objectId = redirectUrl . searchParams . get ( "o" ) ;
260260 if ( objectId ) {
261- let data = datastore . find ( activityId ) . filter ( function ( o ) {
262- return o . objectId == objectId ;
263- } ) ;
264- if ( data . length == 0 ) {
261+ let data = sugarizer . modules . journal . getByObjectId ( objectId ) ;
262+ if ( ! data ) {
265263 redirectUrl . searchParams . delete ( "o" ) ;
266264 redirectUrl . searchParams . set ( "n" , sugarizer . modules . activities . getById ( activityId ) . name ) ;
267265 console . log ( "Redirect object not found" ) ;
268266 }
269267 } else {
270268 redirectUrl . searchParams . set ( "n" , sugarizer . modules . activities . getById ( activityId ) . name ) ;
271269 }
270+ redirectUrl . searchParams . set ( "aid" , sugarizer . modules . journal . generateUUID ( ) ) ;
272271 window . location = decodeURIComponent ( redirectUrl . href ) ;
273272 return ;
274273 } else {
Original file line number Diff line number Diff line change @@ -71,6 +71,15 @@ function LoadFile(event, file) {
7171 } ) ;
7272}
7373
74+ // Generate a fake UUID v4
75+ function uuidv4 ( ) {
76+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
77+ var r = Math . random ( ) * 16 | 0 ,
78+ v = c === 'x' ? r : ( r & 0x3 | 0x8 ) ;
79+ return v . toString ( 16 ) ;
80+ } ) ;
81+ }
82+
7483function createWindow ( ) {
7584 // Process argument
7685 for ( var i = 0 ; i < process . argv . length ; i ++ ) {
@@ -98,7 +107,9 @@ function createWindow() {
98107 "/index.html?n=" +
99108 activities [ j ] . name +
100109 "&a=" +
101- process . argv [ i + 1 ] ;
110+ process . argv [ i + 1 ] +
111+ "&aid=" +
112+ uuidv4 ( ) ;
102113 break ;
103114 }
104115 }
You can’t perform that action at this time.
0 commit comments