Skip to content

Commit 2d45da6

Browse files
committed
Extend item actions to catalogs and collections
1 parent f3519fd commit 2d45da6

File tree

10 files changed

+67
-32
lines changed

10 files changed

+67
-32
lines changed

docs/actions.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Actions <!-- omit in toc -->
22

3-
STAC Browser has a pluggable interface to share or open assets, items and links with other services, which we call "actions".
3+
STAC Browser has a pluggable interface to share or open assets, catalogs, collections, items and links with other services, which we call "actions".
44

5-
An action adds a button to an asset, item or link if certain requirements are met, which can then be executed by users.
5+
An action adds a button to an asset, catalog, collection, item or link if certain requirements are met, which can then be executed by users.
66
For example, you could open COPC files in a dedicated COPC Viewer, which otherwise you could only download.
77

88
- [User Guide](#user-guide)
99
- [Assets](#assets)
10-
- [Items](#items)
10+
- [Catalogs, Collections and Items](#catalogs-collections-and-items)
1111
- [Links](#links)
1212
- [Developer Guide](#developer-guide)
1313

@@ -51,25 +51,25 @@ export default {
5151

5252
Save the file and restart / rebuild STAC Browser.
5353

54-
### Items
54+
### Catalogs, Collections and Items
5555

5656
The following actions are available:
5757

5858
- `stac-map`: Allows to open items through stac-map at <https://developmentseed.org/stac-map/>.
5959

60-
All actions for items are stored in the folder [`src/actions/objects`](../src/actions/objects) if you want to inspect them.
60+
All actions for catalogs, collections and items are stored in the folder [`src/actions/stac`](../src/actions/stac) if you want to inspect them.
6161

62-
The actions can be enabled by adding them to the [`objectActions.config.js`](../objectActions.config.js) file.
62+
The actions can be enabled by adding them to the [`stacActions.config.js`](../stacActions.config.js) file.
6363
Open the file and you'll see a number of imports and exports.
6464
Import the file for the action that you want to enable, e.g. for stac-map:
6565

6666
```js
67-
import StacMap from './src/actions/objects/StacMap.js';
67+
import StacMap from './src/actions/stac/StacMap.js';
6868
```
6969

70-
The path is fixed to `./src/actions/objects/`, the file extension is always `.js`.
70+
The path is fixed to `./src/actions/stac/`, the file extension is always `.js`.
7171
In-between add the file name from the list above.
72-
The import name should be the file name without extension (i.e. `Stacmap` again).
72+
The import name should be the file name without extension (i.e. `StacMap` again).
7373

7474
Lastly, add the import name to the list of exports, e.g.
7575

@@ -121,17 +121,17 @@ Save the file and rebuild / restart STAC Browser.
121121
Implementing actions for assets, items and links follows a very similar pattern.
122122
The main difference is that each action implements its own interface:
123123
- assets implement the [`AssetActionPlugin` interface](../src/actions/AssetActionPlugin.js)
124-
- items implement the [`ObjectActionPlugin` interface](../src/actions/ObjectActionPlugin.js)
124+
- catalogs, collections and items implement the [`StacActionPlugin` interface](../src/actions/StacActionPlugin.js)
125125
- links implement the [`LinkActionPlugin` interface](../src/actions/LinkActionPlugin.js)
126126
Similarly, actions are stored in their own folder:
127127
- assets are stored in the folder [`src/actions/assets`](../src/actions/assets)
128-
- items are stored in the folder [`src/actions/objects`](../src/actions/objects)
128+
- catalogs, collections and items are stored in the folder [`src/actions/stac`](../src/actions/stac)
129129
- links are stored in the folder [`src/actions/links`](../src/actions/links)
130130

131131
All interfaces look as follows:
132132

133133
- `constructor(data: object, component: Vue, id: string)`
134-
- `data`: The asset, item or link object, it is available in the class through `this.asset` (for assets), `this.object` (for items) and `this.link` (for links).
134+
- `data`: The asset, catalog, collection, item or link object, it is available in the class through `this.asset` (for assets), `this.object` (for items) and `this.link` (for links).
135135
- `component`: The parent Asset/Item/Link Vue component (available in the class through `this.component`)
136136
- `id`: Internal ID of the asset, item or link, not meant to be used.
137137
- `get btnOptions() : object`

objectActions.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/actions/ObjectActionPlugin.js renamed to src/actions/StacActionPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ActionPlugin from './ActionPlugin';
22

3-
export default class ObjectActionPlugin extends ActionPlugin {
3+
export default class StacActionPlugin extends ActionPlugin {
44

55
constructor(object, component, id) {
66
super(id, component);

src/actions/objects/StacMap.js renamed to src/actions/stac/StacMap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ObjectActionPlugin from "../ObjectActionPlugin";
1+
import StacActionPlugin from "../StacActionPlugin";
22
import URI from 'urijs';
33
import i18n from "../../i18n";
44

5-
export default class StacMap extends ObjectActionPlugin {
5+
export default class StacMap extends StacActionPlugin {
66

77
get show() {
88
return this.object.isItem();

src/components/Item.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
</small>
2020
</b-card-text>
2121
</b-card-body>
22-
<ObjectActions :data="item" size="sm" />
22+
<StacActions :data="item" footer vertical size="sm" />
2323
</b-card>
2424
</template>
2525

2626
<script>
2727
import { mapState, mapGetters } from 'vuex';
2828
import FileFormatsMixin from './FileFormatsMixin';
2929
import ThumbnailCardMixin from './ThumbnailCardMixin';
30-
import ObjectActions from './ObjectActions.vue';
30+
import StacActions from './StacActions.vue';
3131
import StacLink from './StacLink.vue';
3232
import { STAC } from 'stac-js';
3333
import { formatTemporalExtent, formatTimestamp, formatMediaType } from '@radiantearth/stac-fields/formatters';
@@ -40,7 +40,7 @@ export default {
4040
name: 'Item',
4141
components: {
4242
StacLink,
43-
ObjectActions,
43+
StacActions,
4444
Keywords: () => import('./Keywords.vue')
4545
},
4646
filters: {

src/components/ObjectActions.vue renamed to src/components/StacActions.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<template>
2-
<b-button-group class="obj-actions" :vertical="vertical" :size="size" v-if="hasButtons">
2+
<!-- add card footer (for items search) -->
3+
<b-card-footer v-if="footer && hasButtons">
4+
<b-button-group class="obj-actions" :vertical="vertical" :size="size">
5+
<b-button v-for="action of actions" v-bind="action.btnOptions" :key="action.id" variant="primary" @click="action.onClick">
6+
<component v-if="action.icon" :is="action.icon" class="mr-1" />
7+
{{ action.text }}
8+
</b-button>
9+
</b-button-group>
10+
</b-card-footer>
11+
<!-- add only button group (for item/collection vue) -->
12+
<b-button-group v-else-if="hasButtons" class="obj-actions" :vertical="vertical" :size="size">
313
<b-button v-for="action of actions" v-bind="action.btnOptions" :key="action.id" variant="primary" @click="action.onClick">
414
<component v-if="action.icon" :is="action.icon" class="mr-1" />
515
{{ action.text }}
@@ -10,12 +20,12 @@
1020

1121
<script>
1222
import { BIconBoxArrowUpRight } from 'bootstrap-vue';
13-
import ObjectActions from '../../objectActions.config';
23+
import StacActions from '../../stacActions.config';
1424
1525
let i = 0;
1626
1727
export default {
18-
name: 'ObjectActions',
28+
name: 'StacActions',
1929
components: {
2030
BIconBoxArrowUpRight
2131
},
@@ -24,6 +34,10 @@ export default {
2434
type: Object,
2535
required: true
2636
},
37+
footer: {
38+
type: Boolean,
39+
default: false
40+
},
2741
vertical: {
2842
type: Boolean,
2943
default: false
@@ -40,7 +54,7 @@ export default {
4054
},
4155
computed: {
4256
actions() {
43-
return Object.entries(ObjectActions)
57+
return Object.entries(StacActions)
4458
.map(([id, plugin]) => new plugin(this.data, this, id))
4559
.filter(plugin => plugin.show);
4660
},

src/views/Catalog.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</b-tabs>
3636
</b-card>
3737
</section>
38+
<StacActions :data="data" />
3839
<Assets v-if="hasAssets" :assets="assets" :context="data" :shown="selectedReferences" @showAsset="showAsset" />
3940
<Assets v-if="hasItemAssets && !hasItems" :assets="itemAssets" :context="data" :definition="true" />
4041
<Providers v-if="providers" :providers="providers" />
@@ -63,6 +64,7 @@
6364
import { mapState, mapGetters } from 'vuex';
6465
import Catalogs from '../components/Catalogs.vue';
6566
import Description from '../components/Description.vue';
67+
import StacActions from '../components/StacActions.vue';
6668
import Items from '../components/Items.vue';
6769
import ReadMore from "vue-read-more-smooth";
6870
import ShowAssetLinkMixin from '../components/ShowAssetLinkMixin';
@@ -85,6 +87,7 @@ export default {
8587
CollectionLink: () => import('../components/CollectionLink.vue'),
8688
DeprecationNotice: () => import('../components/DeprecationNotice.vue'),
8789
Description,
90+
StacActions,
8891
Items,
8992
Keywords: () => import('../components/Keywords.vue'),
9093
Links: () => import('../components/Links.vue'),
@@ -439,6 +442,10 @@ export default {
439442
}
440443
}
441444
445+
.obj-actions + .assets, .obj-actions + .providers, .obj-actions + .metadata {
446+
margin-top: 1rem;
447+
}
448+
442449
.metadata .card-columns {
443450
column-count: 1;
444451

src/views/Item.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</b-tabs>
1515
</b-card>
1616
</section>
17-
<ObjectActions :data="data" />
17+
<StacActions :data="data" />
1818
<Assets v-if="hasAssets" :assets="assets" :context="data" :shown="selectedReferences" @showAsset="showAsset" />
1919
<Links v-if="additionalLinks.length > 0" :title="$t('additionalResources')" :links="additionalLinks" :context="data" />
2020
</b-col>
@@ -39,7 +39,7 @@
3939
<script>
4040
import { mapState, mapGetters } from 'vuex';
4141
import Description from '../components/Description.vue';
42-
import ObjectActions from '../components/ObjectActions.vue';
42+
import StacActions from '../components/StacActions.vue';
4343
import ReadMore from "vue-read-more-smooth";
4444
import ShowAssetLinkMixin from '../components/ShowAssetLinkMixin';
4545
import DeprecationMixin from '../components/DeprecationMixin';
@@ -55,7 +55,7 @@ export default {
5555
BTab,
5656
CollectionLink: () => import('../components/CollectionLink.vue'),
5757
Description,
58-
ObjectActions,
58+
StacActions,
5959
DeprecationNotice: () => import('../components/DeprecationNotice.vue'),
6060
Keywords: () => import('../components/Keywords.vue'),
6161
Links: () => import('../components/Links.vue'),

src/views/Search.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@
3535
:count="totalCount" :apiFilters="collectionFilters"
3636
>
3737
<template #catalogFooter="slot">
38-
<b-button-group v-if="itemSearch || canFilterItems(slot.data)" vertical size="sm">
38+
<b-button-group v-if="itemSearch || canFilterItems(slot.data) || hasActions(slot.data)" vertical size="sm">
3939
<b-button v-if="itemSearch" variant="outline-primary" :pressed="selectedCollections[slot.data.id]" @click="selectForItemSearch(slot.data)">
4040
<b-icon-check-square v-if="selectedCollections[slot.data.id]" />
4141
<b-icon-square v-else />
4242
<span class="ml-2">{{ $t('search.selectForItemSearch') }}</span>
4343
</b-button>
4444
<StacLink :button="{variant: 'outline-primary', disabled: !canFilterItems(slot.data)}" :data="slot.data" :title="$t('search.filterCollection')" :state="{itemFilterOpen: 1}" />
45+
<b-button v-for="action of actions(slot.data)" v-bind="action.btnOptions" :key="action.id" variant="outline-primary" @click="action.onClick">
46+
<component v-if="action.icon" :is="action.icon" class="mr-1" />
47+
{{ action.text }}
48+
</b-button>
4549
</b-button-group>
4650
</template>
4751
</Catalogs>
@@ -68,14 +72,16 @@ import Utils from '../utils';
6872
import SearchFilter from '../components/SearchFilter.vue';
6973
import Loading from '../components/Loading.vue';
7074
import ErrorAlert from '../components/ErrorAlert.vue';
75+
import StacActions from '../../stacActions.config';
7176
import { getDisplayTitle, createSTAC, ItemCollection } from '../models/stac';
7277
import { STAC } from 'stac-js';
73-
import { BIconCheckSquare, BIconSquare, BTabs, BTab } from 'bootstrap-vue';
78+
import { BIconBoxArrowUpRight, BIconCheckSquare, BIconSquare, BTabs, BTab } from 'bootstrap-vue';
7479
import { getErrorCode, getErrorMessage, processSTAC, stacRequest } from '../store/utils';
7580
7681
export default {
7782
name: "Search",
7883
components: {
84+
BIconBoxArrowUpRight,
7985
BIconCheckSquare,
8086
BIconSquare,
8187
BTab,
@@ -242,6 +248,14 @@ export default {
242248
}
243249
return false;
244250
},
251+
actions(data) {
252+
return Object.entries(StacActions)
253+
.map(([id, plugin]) => new plugin(data, this, id))
254+
.filter(plugin => plugin.show);
255+
},
256+
hasActions(data) {
257+
return this.actions(data).length > 0;
258+
},
245259
async loadResults(link) {
246260
this.error = null;
247261
this.errorId = null;

stacActions.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// import StacMap from './src/actions/stac/StacMap.js';
2+
3+
export default {
4+
// StacMap,
5+
};

0 commit comments

Comments
 (0)