Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
138
Merge Requests
138
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
30161fc5
Commit
30161fc5
authored
Feb 17, 2020
by
Gabriel Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_document_scanner: Optimize code to reduce image size before crop
parent
4c3ab064
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
130 deletions
+37
-130
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.js
...ateItem/web_page_module/rjs_gadget_document_scanner_js.js
+20
-18
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.xml
...teItem/web_page_module/rjs_gadget_document_scanner_js.xml
+2
-2
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_storeDocumentFromCameraInActiveProcess.py
...nt_scanner/Base_storeDocumentFromCameraInActiveProcess.py
+0
-47
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_storeDocumentFromCameraInActiveProcess.xml
...t_scanner/Base_storeDocumentFromCameraInActiveProcess.xml
+0
-62
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_uploadDocumentFromCameraByActivity.py
...cument_scanner/Base_uploadDocumentFromCameraByActivity.py
+14
-0
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_viewUploadDocumentFromCameraDialog/your_document_scanner_gadget.xml
...DocumentFromCameraDialog/your_document_scanner_gadget.xml
+1
-1
No files found.
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.js
View file @
30161fc5
...
...
@@ -211,7 +211,7 @@
text
:
'
New Page
'
,
// Do not allow to show again the current image
disabled
:
(
len
===
gadget
.
state
.
page
-
1
),
class
:
'
new-btn ui-btn-icon-left ui-icon-plus
'
"
class
"
:
'
new-btn ui-btn-icon-left ui-icon-plus
'
}));
return
domsugar
(
'
ol
'
,
{
"
class
"
:
"
thumbnail-list
"
},
thumbnail_dom_list
);
});
...
...
@@ -303,28 +303,31 @@
return
image_capture
.
takePhoto
({
imageWidth
:
capabilities
.
imageWidth
.
max
});
})
.
push
(
function
(
blob
)
{
return
createImageBitmap
(
blob
);
return
RSVP
.
all
([
createImageBitmap
(
blob
),
jIO
.
util
.
readBlobAsDataURL
(
blob
)
]);
})
.
push
(
function
(
bitmap
)
{
var
canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
});
.
push
(
function
(
result_list
)
{
var
bitmap
=
result_list
[
0
],
canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
});
canvas
.
width
=
bitmap
.
width
;
canvas
.
height
=
bitmap
.
height
;
canvas
.
getContext
(
'
2d
'
).
drawImage
(
bitmap
,
0
,
0
);
return
canvas
;
return
[
canvas
,
result_list
[
1
].
target
.
result
]
;
})
.
push
(
function
(
canvas
)
{
var
new_canvas
;
.
push
(
function
(
result_list
)
{
var
new_canvas
,
canvas
=
result_list
[
0
],
data_url
=
result_list
[
1
];
gadget
.
detached_promise_dict
.
media_stream
.
cancel
(
'
Not needed anymore, as captured
'
);
if
(
settings
.
brightness
||
settings
.
contrast
||
settings
.
enable_greyscale
||
settings
.
compression
)
{
new_canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
,
'
width
'
:
canvas
.
width
,
'
height
'
:
canvas
.
height
});
new_canvas
=
domsugar
(
'
canvas
'
,
{
'
class
'
:
'
canvas
'
});
return
new
RSVP
.
Queue
()
.
push
(
function
(
result
)
{
return
new
Promise
(
function
(
resolve
)
{
// XXX the correct usage is `new Caman()` but the library does not support it
caman
(
new_canvas
,
canvas
.
toDataURL
()
,
function
()
{
caman
(
new_canvas
,
data_url
,
function
()
{
if
(
settings
.
brightness
&&
settings
.
brightness
!==
0
)
{
this
.
brightness
(
settings
.
brightness
);
}
...
...
@@ -347,16 +350,16 @@
return
RSVP
.
all
([
gadget
.
getTranslationList
([
"
Delete
"
,
"
Save
"
]),
new
Promise
(
function
(
resolve
)
{
resolve
(
canvas
);
resolve
(
canvas
.
toDataURL
(
"
image/jpeg
"
)
);
}),
buildPreviousThumbnailDom
(
gadget
)
]);
})
.
push
(
function
(
result_list
)
{
var
canvas
=
result_list
[
1
],
var
data_url
=
result_list
[
1
],
img
=
domsugar
(
"
img
"
,
{
"
src
"
:
data_url
}),
defer
=
RSVP
.
defer
();
// Prepare the cropper canvas
div
=
domsugar
(
'
div
'
,
{
'
class
'
:
'
camera
'
},
[
domsugar
(
'
div
'
,
{
'
class
'
:
'
camera-header
'
},
[
domsugar
(
'
h4
'
,
[
...
...
@@ -364,7 +367,7 @@
domsugar
(
'
label
'
,
{
'
class
'
:
'
page-number
'
,
text
:
gadget
.
state
.
page
})
])
]),
canvas
,
img
,
domsugar
(
'
div
'
,
{
'
class
'
:
'
edit-picture
'
},
[
domsugar
(
'
button
'
,
{
type
:
'
button
'
,
'
class
'
:
'
reset-btn ui-btn-icon-left ui-icon-times
'
,
...
...
@@ -382,7 +385,7 @@
// For now, it needs to access dom element size
gadget
.
element
.
replaceChild
(
div
,
gadget
.
element
.
firstElementChild
);
addDetachedPromise
(
gadget
,
'
cropper
'
,
handleCropper
(
canvas
,
handleCropper
(
img
,
gadget
.
state
.
preferred_cropped_canvas_data
,
defer
.
resolve
));
return
defer
.
promise
;
...
...
@@ -477,7 +480,6 @@
return
selectMediaDevice
(
gadget
.
state
.
device_id
,
false
)
.
push
(
function
(
device_id
)
{
return
gadget
.
changeState
({
dialog_method
:
options
.
dialog_method
,
store_new_image_cropped_method
:
options
.
store_new_image_cropped_method
,
active_process
:
default_value
.
active_process
,
image_list
:
default_value
.
image_list
,
...
...
bt5/erp5_document_scanner/PathTemplateItem/web_page_module/rjs_gadget_document_scanner_js.xml
View file @
30161fc5
...
...
@@ -244,7 +244,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
981.5
7848.5692.33382
</string>
</value>
<value>
<string>
981.5
8568.65411.58828
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>
1581
860732.16
</float>
<float>
1581
903960.55
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_storeDocumentFromCameraInActiveProcess.py
deleted
100644 → 0
View file @
4c3ab064
import
json
from
base64
import
decodestring
portal
=
context
.
getPortalObject
()
translateString
=
portal
.
Base_translateString
gadget_data
=
json
.
loads
(
document_scanner_gadget
)
image_str
=
decodestring
(
gadget_data
.
pop
(
"input_value"
))
preferred_cropped_canvas_data
=
gadget_data
[
"preferred_cropped_canvas_data"
]
or
{}
selection_mapping
=
portal
.
portal_selections
.
getSelectionParamsFor
(
context
.
Base_getDocumentScannerSelectionName
(),
REQUEST
=
context
.
REQUEST
)
or
{}
http_user_agent
=
context
.
REQUEST
[
"HTTP_USER_AGENT"
]
selection_mapping
[
http_user_agent
]
=
preferred_cropped_canvas_data
or
{}
portal
.
portal_selections
.
setSelectionParamsFor
(
context
.
Base_getDocumentScannerSelectionName
(),
selection_mapping
,
context
.
REQUEST
)
if
not
image_str
:
if
batch_mode
:
if
active_process_url
:
return
portal
.
restrictedTraverse
(
active_process_url
)
return
None
return
context
.
Base_renderForm
(
'Base_viewUploadDocumentFromCameraDialog'
,
message
=
translateString
(
'Nothing to capture'
))
active_process
,
_
=
context
.
Base_postDataToActiveResult
(
active_process_url
,
image_str
)
# We need it to fill the form rendered by renderjs
context
.
REQUEST
.
form
[
"your_active_process_url"
]
=
active_process
.
getRelativeUrl
()
# We remove it to reduce the size of the response
context
.
REQUEST
.
form
.
pop
(
"field_your_document_scanner_gadget"
)
context
.
REQUEST
.
form
.
pop
(
'document_scanner_gadget'
)
if
batch_mode
:
return
active_process
return
context
.
Base_renderForm
(
'Base_viewUploadDocumentFromCameraDialog'
,
message
=
translateString
(
'Captured'
))
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_storeDocumentFromCameraInActiveProcess.xml
deleted
100644 → 0
View file @
4c3ab064
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
classification=None, synchronous_metadata_discovery=None, cancel_url=None, batch_mode=False, editable_mode=1, group=None, publication_section=None, document_scanner_gadget=None, active_process_url=None, **kw
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Base_storeDocumentFromCameraInActiveProcess
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_uploadDocumentFromCameraByActivity.py
View file @
30161fc5
...
...
@@ -7,6 +7,20 @@ translateString = portal.Base_translateString
active_process_url
=
data_dict
.
pop
(
"active_process"
)
image_list
=
data_dict
.
pop
(
"image_list"
)
preferred_cropped_canvas_data
=
data_dict
.
pop
(
"preferred_cropped_canvas_data"
)
or
{}
selection_mapping
=
portal
.
portal_selections
.
getSelectionParamsFor
(
context
.
Base_getDocumentScannerSelectionName
(),
REQUEST
=
context
.
REQUEST
)
or
{}
http_user_agent
=
context
.
REQUEST
[
"HTTP_USER_AGENT"
]
selection_mapping
[
http_user_agent
]
=
preferred_cropped_canvas_data
or
{}
portal
.
portal_selections
.
setSelectionParamsFor
(
context
.
Base_getDocumentScannerSelectionName
(),
selection_mapping
,
context
.
REQUEST
)
# Avoid to pass huge images to the activity
kw
.
pop
(
"your_document_scanner_gadget"
,
None
)
...
...
bt5/erp5_document_scanner/SkinTemplateItem/portal_skins/erp5_document_scanner/Base_viewUploadDocumentFromCameraDialog/your_document_scanner_gadget.xml
View file @
30161fc5
...
...
@@ -165,7 +165,7 @@
<dictionary>
<item>
<key>
<string>
_text
</string>
</key>
<value>
<string>
python: [(\'
dialog_method\', \'Base_storeDocumentFromCameraInActiveProcess\'), (\'
preferred_image_settings_data\', context.Base_getPreferredImageSettingsFromPreference()), (\'preferred_cropped_canvas_data\', context.Base_getPreferredCropperSettingsFromSelection()), ("store_new_image_cropped_method", \'Base_storeNewImageCropped\')]
</string>
</value>
<value>
<string>
python: [(\'preferred_image_settings_data\', context.Base_getPreferredImageSettingsFromPreference()), (\'preferred_cropped_canvas_data\', context.Base_getPreferredCropperSettingsFromSelection()), ("store_new_image_cropped_method", \'Base_storeNewImageCropped\')]
</string>
</value>
</item>
</dictionary>
</pickle>
...
...
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