Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cribjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
cribjs
Commits
d756e23e
Commit
d756e23e
authored
Jun 10, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Upload from Zip file functionnal on landing page
parent
2f90a5af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
44 deletions
+86
-44
gadget/gadget_landing_cribjs.js
gadget/gadget_landing_cribjs.js
+66
-41
landing.js
landing.js
+20
-3
No files found.
gadget/gadget_landing_cribjs.js
View file @
d756e23e
...
...
@@ -19,8 +19,71 @@
return
default_value
;
}
function
loadZipIntoCrib
(
crib_sw_gadget
,
zip
,
from_path
,
path_to_load
)
{
var
promise_list
=
[],
url_number
=
0
;
zip
.
forEach
(
function
(
relativePath
,
zipEntry
)
{
var
end_url
;
url_number
+=
1
;
if
(
zipEntry
.
dir
)
{
return
}
if
(
!
relativePath
.
startsWith
(
from_path
)
)
{
return
}
relativePath
=
relativePath
.
substring
(
from_path
.
length
);
if
(
!
relativePath
.
startsWith
(
"
/
"
)
&&
!
path_to_load
.
endsWith
(
"
/
"
))
{
end_url
=
path_to_load
+
"
/
"
+
relativePath
}
else
if
(
relativePath
.
startsWith
(
"
/
"
)
&&
path_to_load
.
endsWith
(
"
/
"
))
{
end_url
=
path_to_load
+
relativePath
.
substring
(
1
);
}
else
{
end_url
=
path_to_load
+
relativePath
}
promise_list
.
push
(
new
RSVP
.
Queue
().
push
(
function
()
{
return
zipEntry
.
async
(
'
blob
'
);
})
.
push
(
function
(
result
)
{
if
(
end_url
.
endsWith
(
"
.js
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
application/javascript
"
)
}
else
if
(
end_url
.
endsWith
(
"
.html
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
text/html
"
)
}
else
if
(
end_url
.
endsWith
(
"
.css
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
text/css
"
)
}
return
crib_sw_gadget
.
put
(
end_url
,
{
blob
:
result
})
})
)
})
return
RSVP
.
all
(
promise_list
)
}
function
loadContentFromZIPFile
(
gadget
,
options
)
{
var
path_to_load
=
options
.
to_path
,
from_path
=
options
.
from_path
,
file_list
=
options
.
file_list
;
if
(
file_list
.
length
===
0
)
{
return
"
No File to Load
"
;
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
gadget
.
getDeclaredGadget
(
'
crib_sw_gadget
'
),
JSZip
.
loadAsync
(
file_list
[
0
])
]);
})
.
push
(
function
(
result_list
)
{
return
loadZipIntoCrib
(
result_list
[
0
],
result_list
[
1
],
from_path
,
path_to_load
);
})
.
push
(
console
.
log
,
console
.
log
)
}
function
loadContentFromZIPURL
(
gadget
,
options
)
{
var
path_to_load
=
options
.
to_path
,
path_to_load_length
,
file_list
,
crib_sw_gadget
,
var
path_to_load
=
options
.
to_path
,
file_list
,
crib_sw_gadget
,
from_path
=
options
.
from_path
,
zip_url
=
options
.
zip_url
,
jio_gadget
,
url_list
=
[],
url_number
=
0
;
return
new
RSVP
.
Queue
()
...
...
@@ -40,45 +103,7 @@
})
.
push
(
JSZip
.
loadAsync
)
.
push
(
function
(
zip
)
{
var
promise_list
=
[];
zip
.
forEach
(
function
(
relativePath
,
zipEntry
)
{
var
end_url
;
url_number
+=
1
;
if
(
zipEntry
.
dir
)
{
return
}
if
(
!
relativePath
.
startsWith
(
from_path
)
)
{
return
}
relativePath
=
relativePath
.
substring
(
from_path
.
length
);
if
(
!
relativePath
.
startsWith
(
"
/
"
)
&&
!
path_to_load
.
endsWith
(
"
/
"
))
{
end_url
=
path_to_load
+
"
/
"
+
relativePath
}
else
if
(
relativePath
.
startsWith
(
"
/
"
)
&&
path_to_load
.
endsWith
(
"
/
"
))
{
end_url
=
path_to_load
+
relativePath
.
substring
(
1
);
}
else
{
end_url
=
path_to_load
+
relativePath
}
promise_list
.
push
(
new
RSVP
.
Queue
().
push
(
function
()
{
return
zipEntry
.
async
(
'
blob
'
);
})
.
push
(
function
(
result
)
{
if
(
end_url
.
endsWith
(
"
.js
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
application/javascript
"
)
}
else
if
(
end_url
.
endsWith
(
"
.html
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
text/html
"
)
}
else
if
(
end_url
.
endsWith
(
"
.css
"
)
)
{
// This is a ugly hack as mimetype needs to be correct for JS
result
=
result
.
slice
(
0
,
result
.
size
,
"
text/css
"
)
}
return
crib_sw_gadget
.
put
(
end_url
,
{
blob
:
result
})
})
)
})
return
RSVP
.
all
(
promise_list
)
return
loadZipIntoCrib
(
crib_sw_gadget
,
zip
,
from_path
,
path_to_load
);
})
.
push
(
console
.
log
,
console
.
log
)
}
...
...
@@ -91,7 +116,7 @@
return
loadContentFromZIPURL
(
this
,
options
);
})
.
declareMethod
(
'
loadFromZipFile
'
,
function
(
options
)
{
return
loadContentFromZIP
URL
(
gadget
,
options
);
return
loadContentFromZIP
File
(
this
,
options
);
})
.
allowPublicAcquisition
(
"
getSetting
"
,
function
(
argument_list
)
{
return
getSetting
(
this
,
argument_list
[
0
],
argument_list
[
1
]);
...
...
landing.js
View file @
d756e23e
...
...
@@ -13,9 +13,6 @@
return
params
;
}
function
loadCribJSFromZipFile
(
gadget
,
event
)
{
}
function
makeid
(
length
)
{
var
result
=
''
;
var
characters
=
'
abcdefghijklmnopqrstuvwxyz0123456789
'
;
...
...
@@ -26,6 +23,26 @@
return
result
;
}
function
loadCribJSFromZipFile
(
gadget
,
event
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
"
jio_cribjs
"
);
})
.
push
(
function
(
jio_cribjs_gadget
)
{
return
jio_cribjs_gadget
.
loadFromZipFile
({
path
:
document
.
location
.
href
,
file_list
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip-file .load-zip-file
"
).
files
,
from_path
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip-file .load-from-zip-path
"
).
value
,
to_path
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip-file .load-zip-to-path
"
).
value
,
application_id
:
"
cribjs
"
})
})
.
push
(
function
(
url_list
)
{
document
.
location
=
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip-file .redirect-url
"
).
value
;
})
.
push
(
console
.
log
,
console
.
log
);
}
function
loadCribJSFromZipUrl
(
gadget
,
event
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment