Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
9400f27f
Commit
9400f27f
authored
5 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
basic asset manager for file objects
parent
c176313f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-plugin-state/transforms/data.ts
+19
-2
19 additions, 2 deletions
src/mol-plugin-state/transforms/data.ts
src/mol-plugin/context.ts
+3
-1
3 additions, 1 deletion
src/mol-plugin/context.ts
src/mol-plugin/util/asset-manager.ts
+73
-0
73 additions, 0 deletions
src/mol-plugin/util/asset-manager.ts
with
95 additions
and
3 deletions
src/mol-plugin-state/transforms/data.ts
+
19
−
2
View file @
9400f27f
...
...
@@ -18,6 +18,7 @@ import * as DSN6 from '../../mol-io/reader/dsn6/parser';
import
*
as
PLY
from
'
../../mol-io/reader/ply/parser
'
;
import
{
parsePsf
}
from
'
../../mol-io/reader/psf/parser
'
;
import
{
isTypedArray
}
from
'
../../mol-data/db/column-helpers
'
;
import
{
AssetManager
}
from
'
../../mol-plugin/util/asset-manager
'
;
export
{
Download
};
type
Download
=
typeof
Download
...
...
@@ -149,10 +150,26 @@ const ReadFile = PluginStateTransform.BuiltIn({
plugin
.
log
.
error
(
'
No file(s) selected
'
);
return
StateObject
.
Null
;
}
const
data
=
await
readFromFile
(
p
.
file
,
p
.
isBinary
?
'
binary
'
:
'
string
'
).
runInContext
(
ctx
);
return
p
.
isBinary
let
file
:
File
;
if
(
AssetManager
.
isItem
(
p
.
file
))
{
if
(
!
plugin
.
managers
.
asset
.
has
(
p
.
file
.
id
))
{
throw
new
Error
(
`No asset found for '
${
p
.
file
.
name
}
'`
);
}
file
=
plugin
.
managers
.
asset
.
get
(
p
.
file
.
id
)
!
;
// will be added again below with new id
plugin
.
managers
.
asset
.
remove
(
p
.
file
.
id
);
}
else
{
file
=
p
.
file
;
}
const
data
=
await
readFromFile
(
file
,
p
.
isBinary
?
'
binary
'
:
'
string
'
).
runInContext
(
ctx
);
const
o
=
p
.
isBinary
?
new
SO
.
Data
.
Binary
(
data
as
Uint8Array
,
{
label
:
p
.
label
?
p
.
label
:
p
.
file
.
name
})
:
new
SO
.
Data
.
String
(
data
as
string
,
{
label
:
p
.
label
?
p
.
label
:
p
.
file
.
name
});
plugin
.
managers
.
asset
.
set
(
o
.
id
,
file
);
return
o
;
});
},
update
({
oldParams
,
newParams
,
b
})
{
...
...
This diff is collapsed.
Click to expand it.
src/mol-plugin/context.ts
+
3
−
1
View file @
9400f27f
...
...
@@ -53,6 +53,7 @@ import { TaskManager } from './util/task-manager';
import
{
PluginToastManager
}
from
'
./util/toast
'
;
import
{
ViewportScreenshotHelper
}
from
'
./util/viewport-screenshot
'
;
import
{
PLUGIN_VERSION
,
PLUGIN_VERSION_DATE
}
from
'
./version
'
;
import
{
AssetManager
}
from
'
./util/asset-manager
'
;
export
class
PluginContext
{
runTask
=
<
T
>
(
task
:
Task
<
T
>
)
=>
this
.
tasks
.
run
(
task
);
...
...
@@ -150,7 +151,8 @@ export class PluginContext {
interactivity
:
void
0
as
any
as
InteractivityManager
,
camera
:
new
CameraManager
(
this
),
lociLabels
:
void
0
as
any
as
LociLabelManager
,
toast
:
new
PluginToastManager
(
this
)
toast
:
new
PluginToastManager
(
this
),
asset
:
new
AssetManager
(
this
)
}
as const
readonly
customModelProperties
=
new
CustomProperty
.
Registry
<
Model
>
();
...
...
This diff is collapsed.
Click to expand it.
src/mol-plugin/util/asset-manager.ts
0 → 100644
+
73
−
0
View file @
9400f27f
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import
{
UUID
}
from
'
../../mol-util
'
;
import
{
PluginContext
}
from
'
../context
'
;
import
{
iterableToArray
}
from
'
../../mol-data/util
'
;
export
{
AssetManager
};
class
AssetManager
{
private
files
=
new
Map
<
UUID
,
File
>
()
private
ids
=
new
Map
<
File
,
UUID
>
()
get
list
()
{
return
iterableToArray
(
this
.
ids
.
entries
());
}
set
(
id
:
UUID
,
file
:
File
)
{
this
.
files
.
set
(
id
,
file
);
this
.
ids
.
set
(
file
,
id
);
}
remove
(
id
:
UUID
)
{
if
(
this
.
files
.
has
(
id
))
{
const
file
=
this
.
files
.
get
(
id
)
!
;
this
.
files
.
delete
(
id
);
this
.
ids
.
delete
(
file
);
}
}
has
(
id
:
UUID
)
{
return
this
.
files
.
has
(
id
);
}
get
(
id
:
UUID
)
{
return
this
.
files
.
get
(
id
);
}
/** For use with `JSON.stringify` */
replacer
=
(
key
:
string
,
value
:
any
)
=>
{
if
(
value
instanceof
File
)
{
const
id
=
this
.
ids
.
get
(
value
);
if
(
!
id
)
{
// TODO throw?
console
.
warn
(
`No asset found for '
${
value
.
name
}
'`
);
}
return
id
?
AssetManager
.
Item
(
id
,
value
.
name
)
:
{};
}
else
{
return
value
;
}
}
constructor
(
public
ctx
:
PluginContext
)
{
ctx
.
state
.
data
.
events
.
object
.
removed
.
subscribe
(
e
=>
{
const
id
=
e
.
obj
?.
id
;
if
(
id
)
ctx
.
managers
.
asset
.
remove
(
id
);
});
}
}
namespace
AssetManager
{
export
type
Item
=
{
kind
:
'
asset-item
'
,
id
:
UUID
,
name
:
string
};
export
function
Item
(
id
:
UUID
,
name
:
string
):
Item
{
return
{
kind
:
'
asset-item
'
,
id
,
name
};
}
export
function
isItem
(
x
?:
any
):
x
is
Item
{
return
!!
x
&&
x
?.
kind
===
'
asset-item
'
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment