Skip to content

Commit

Permalink
Make mime type for imported files.
Browse files Browse the repository at this point in the history
Add more inline editors.

This displays text files.
  • Loading branch information
manthey committed Nov 21, 2022
1 parent d9ac2f0 commit c40a766
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 7 additions & 5 deletions girder/girder_large_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ def handleRemoveFile(event):
ImageItem().delete(item, [fileObj['_id']])


def handleFinalizeUploadBefore(event):
def handleFileSave(event):
"""
When a file is uploaded, mark its mime type based on its extension if we
When a file is first saved, mark its mime type based on its extension if we
would otherwise just mark it as generic application/octet-stream.
"""
fileObj = event.info['file']
if fileObj.get('mimeType', None) in {None, 'application/octet-stream'}:
fileObj = event.info
if fileObj.get('mimeType', None) in {None, ''} or (
'_id' not in fileObj and
fileObj.get('mimeType', None) in {'application/octet-stream'}):
global mimetypes

if not mimetypes:
Expand Down Expand Up @@ -483,7 +485,7 @@ def load(self, info):
events.bind('model.item.remove', 'large_image.removeThumbnails', removeThumbnails)
events.bind('server_fuse.unmount', 'large_image', large_image.cache_util.cachesClear)
events.bind('model.file.remove', 'large_image', handleRemoveFile)
events.bind('model.file.finalizeUpload.before', 'large_image', handleFinalizeUploadBefore)
events.bind('model.file.save', 'large_image', handleFileSave)

search._allowedSearchMode.pop('li_metadata', None)
search.addSearchMode('li_metadata', metadataSearchHandler)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
= ' '
button.g-view-codemirror-revert-button.btn.btn-sm.btn-default Revert
= ' '
button.g-view-codemirror-format-button.btn.btn-sm.btn-default(title='This may remove comments') Format
= ' '
if formatRecord.format
button.g-view-codemirror-format-button.btn.btn-sm.btn-default(title='This may remove comments') Format
= ' '
button.g-view-codemirror-save-button.btn.btn-sm.btn-primary Save
i.icon-edit
span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const Formats = {
* more work. */
format: (val) => jsyaml.dump(val, {lineWidth: -1, noRefs: true})
},
'text/plain': {
name: 'Text',
mode: 'text',
validator: (val) => val,
format: null
},
'application/x-girder-ini': {
name: 'Configuration',
mode: 'properties',
Expand Down Expand Up @@ -198,6 +204,7 @@ var CodemirrorEditWidget = View.extend({
formatName: Formats[this.mimeType].name,
accessLevel: this.accessLevel,
buttonList: Formats[this.mimeType].buttons || [],
formatRecord: Formats[this.mimeType],
AccessType: AccessType
}));
this.code = CodeMirror(this.$el.find('.editor')[0], {
Expand Down

0 comments on commit c40a766

Please sign in to comment.