-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ldp): add stream subscriptions (#9736)
ref: OB-5034 Signed-off-by: Pierre Frayer <[email protected]> Signed-off-by: CDS Translator Agent <[email protected]>
- Loading branch information
Showing
25 changed files
with
459 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...ules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import datagridToIcebergFilter from '../../logs-iceberg.utils'; | ||
|
||
export default class LogsStreamsSubscriptionsCtrl { | ||
/* @ngInject */ | ||
constructor( | ||
$stateParams, | ||
$translate, | ||
ouiDatagridService, | ||
CucCloudMessage, | ||
CucControllerHelper, | ||
LogsHelperService, | ||
LogsStreamsService, | ||
LogsStreamsSubscriptionsService, | ||
) { | ||
this.$stateParams = $stateParams; | ||
this.$translate = $translate; | ||
this.ouiDatagridService = ouiDatagridService; | ||
this.CucCloudMessage = CucCloudMessage; | ||
this.CucControllerHelper = CucControllerHelper; | ||
this.LogsHelperService = LogsHelperService; | ||
this.LogsStreamsService = LogsStreamsService; | ||
this.LogsStreamsSubscriptionsService = LogsStreamsSubscriptionsService; | ||
|
||
this.serviceName = this.$stateParams.serviceName; | ||
this.streamId = this.$stateParams.streamId; | ||
} | ||
|
||
$onInit() { | ||
this.stream = this.CucControllerHelper.request.getHashLoader({ | ||
loaderFunction: () => | ||
this.LogsStreamsService.getStream(this.serviceName, this.streamId), | ||
}); | ||
this.stream.load(); | ||
} | ||
|
||
/** | ||
* Retrieve subscription list, according to pagination/sort/filter | ||
* | ||
* @param offset int element offset to retrieve results from | ||
* @param pageSize int Number of results to retrieve | ||
* @param sort Object Sort object from ovh-ui datagrid | ||
* @param criteria Object Criteria object from ovh-ui datagrid | ||
* @return {*|Promise<any>} | ||
*/ | ||
loadSubscriptions({ offset, pageSize = 1, sort, criteria }) { | ||
const filters = criteria.map((criterion) => { | ||
const name = criterion.property || 'resource.name'; | ||
return datagridToIcebergFilter(name, criterion.operator, criterion.value); | ||
}); | ||
const pageOffset = Math.ceil(offset / pageSize); | ||
return this.LogsStreamsSubscriptionsService.getPaginatedStreamSubscriptions( | ||
this.serviceName, | ||
this.streamId, | ||
pageOffset, | ||
pageSize, | ||
{ name: sort.property, dir: sort.dir === -1 ? 'DESC' : 'ASC' }, | ||
filters, | ||
); | ||
} | ||
|
||
/** | ||
* Display a modal to confirm subscription deletion | ||
* | ||
* @param subscription Object Subscription object from API | ||
* @return {*|Promise<any>} | ||
*/ | ||
showSubscriptionDeleteConfirm(subscription) { | ||
this.CucCloudMessage.flushChildMessage(); | ||
return this.CucControllerHelper.modal | ||
.showDeleteModal({ | ||
titleText: this.$translate.instant( | ||
'streams_subscriptions_delete_modal_title', | ||
), | ||
textHtml: this.$translate.instant( | ||
'streams_subscriptions_delete_modal_content', | ||
{ | ||
resourceName: `<strong>${subscription.resource.name}</strong>`, | ||
}, | ||
), | ||
}) | ||
.then(() => this.removeSubscription(subscription)); | ||
} | ||
|
||
/** | ||
* Delete a subscription on API | ||
* Update datagrid accordingly | ||
* | ||
* @param subscription Object Subscription object from API | ||
*/ | ||
removeSubscription(subscription) { | ||
this.CucCloudMessage.flushChildMessage(); | ||
this.deleteSubscriptionLoading = true; | ||
this.LogsStreamsSubscriptionsService.deleteSubscription( | ||
this.serviceName, | ||
this.streamId, | ||
subscription, | ||
) | ||
.then((operation) => | ||
this.LogsHelperService.handleOperation( | ||
this.serviceName, | ||
operation.data, | ||
'streams_subscriptions_delete_success', | ||
{ resourceName: subscription.resource.name }, | ||
), | ||
) | ||
.catch((err) => { | ||
this.LogsHelperService.handleError( | ||
'streams_subscriptions_delete_error', | ||
err, | ||
{ resourceName: subscription.resource.name }, | ||
); | ||
}) | ||
.finally(() => { | ||
this.deleteSubscriptionLoading = false; | ||
this.ouiDatagridService.refresh('subscriptions-datagrid', true); | ||
this.CucControllerHelper.scrollPageToTop(); | ||
}); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...nager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<section class="subscriptions-home"> | ||
<oui-back-button | ||
><span data-translate="logs_streams_subscriptions"></span | ||
></oui-back-button> | ||
|
||
<h6> | ||
{{'streams_subscriptions_current_title' | translate:{ name: | ||
$ctrl.stream.data.title } }} | ||
</h6> | ||
<p data-translate="streams_subscriptions_intro_text"></p> | ||
|
||
<oui-datagrid | ||
id="subscriptions-datagrid" | ||
rows-loader="$ctrl.loadSubscriptions($config)" | ||
> | ||
<oui-datagrid-topbar> | ||
<oui-spinner | ||
size="s" | ||
data-ng-if="$ctrl.deleteSubscriptionLoading" | ||
></oui-spinner> | ||
</oui-datagrid-topbar> | ||
|
||
<oui-datagrid-column | ||
data-title="::'streams_subscriptions_resource_name_label' | translate" | ||
data-property="resource.name" | ||
data-type="string" | ||
data-sortable | ||
data-searchable | ||
data-filterable | ||
></oui-datagrid-column> | ||
<oui-datagrid-column | ||
data-title="::'streams_subscriptions_resource_type_label' | translate" | ||
data-property="resource.type" | ||
data-type="string" | ||
data-sortable="asc" | ||
data-searchable | ||
data-filterable | ||
> | ||
<span> | ||
{{ ::'streams_subscriptions_resource_products_' + | ||
$row.resource.type | translate }} | ||
</span> | ||
</oui-datagrid-column> | ||
<oui-datagrid-column | ||
data-title="::'logs_col_last_modified' | translate" | ||
data-property="updatedAt" | ||
data-sortable | ||
data-type="date" | ||
> | ||
{{ $row.updatedAt | cucMomentFormat:'L'}} | ||
</oui-datagrid-column> | ||
<oui-datagrid-column> | ||
<button | ||
type="button" | ||
class="btn btn-secondary float-right mr-2" | ||
data-ng-click="$ctrl.showSubscriptionDeleteConfirm($row)" | ||
> | ||
<span | ||
class="oui-icon oui-icon-trash_concept" | ||
aria-hidden="true" | ||
></span> | ||
</button> | ||
</oui-datagrid-column> | ||
</oui-datagrid> | ||
</section> |
60 changes: 60 additions & 0 deletions
60
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export default class LogsStreamsSubscriptionsService { | ||
/* @ngInject */ | ||
constructor($http, iceberg) { | ||
this.$http = $http; | ||
this.iceberg = iceberg; | ||
} | ||
|
||
/** | ||
* Retrieve list of stream's subscription with pagination, sorts, filters etc. | ||
* @param serviceName string LDP service name | ||
* @param streamId string LDP stream UUID | ||
* @param offset int Offset to start from | ||
* @param pageSize int Number of results to retrieve from API | ||
* @param sort string Name of field to sort from | ||
* @param filters Array List of Iceberg filters to apply | ||
* @return {Object} | ||
*/ | ||
getPaginatedStreamSubscriptions( | ||
serviceName, | ||
streamId, | ||
offset = 0, | ||
pageSize = 25, | ||
sort = { name: 'nbArchive', dir: 'desc' }, | ||
filters = null, | ||
) { | ||
let res = this.iceberg( | ||
`/dbaas/logs/${serviceName}/output/graylog/stream/${streamId}/subscription`, | ||
) | ||
.query() | ||
.expand('CachedObjectList-Pages') | ||
.limit(pageSize) | ||
.offset(offset) | ||
.sort(sort.name, sort.dir); | ||
if (filters !== null) { | ||
filters.forEach((filter) => { | ||
res = res.addFilter(filter.name, filter.operator, filter.value); | ||
}); | ||
} | ||
return res.execute().$promise.then((response) => ({ | ||
data: response.data, | ||
meta: { | ||
totalCount: | ||
parseInt(response.headers['x-pagination-elements'], 10) || 0, | ||
}, | ||
})); | ||
} | ||
|
||
/** | ||
* Delete a subscription on the API side | ||
* @param serviceName string LDP service name | ||
* @param streamId string LDP stream UUID | ||
* @param subscription Object Subscription object to delete | ||
* @return {Promise<any>} | ||
*/ | ||
deleteSubscription(serviceName, streamId, subscription) { | ||
return this.$http.delete( | ||
`/dbaas/logs/${serviceName}/output/graylog/stream/${streamId}/subscription/${subscription.subscriptionId}`, | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...nager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import controller from './streams-subscriptions.controller'; | ||
import template from './streams-subscriptions.html'; | ||
|
||
export default { | ||
controller, | ||
template, | ||
}; |
28 changes: 28 additions & 0 deletions
28
.../manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.module.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import angular from 'angular'; | ||
|
||
import '@ovh-ux/manager-core'; | ||
import '@ovh-ux/ng-ovh-cloud-universe-components'; | ||
import '@uirouter/angularjs'; | ||
import 'angular-translate'; | ||
import '@ovh-ux/ui-kit'; | ||
|
||
import component from './subscriptions.component'; | ||
import routing from './subscriptions.routing'; | ||
import service from './streams-subscriptions.service'; | ||
|
||
const moduleName = 'ovhManagerDbaasLogsDetailStreamsSubscriptions'; | ||
|
||
angular | ||
.module(moduleName, [ | ||
'ngOvhCloudUniverseComponents', | ||
'oui', | ||
'ovhManagerCore', | ||
'pascalprecht.translate', | ||
'ui.router', | ||
]) | ||
.config(routing) | ||
.service('LogsStreamsSubscriptionsService', service) | ||
.component('dbaasLogsDetailStreamsSubscriptions', component) | ||
.run(/* @ngTranslationsInject:json ./translations */); | ||
|
||
export default moduleName; |
10 changes: 10 additions & 0 deletions
10
...manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.routing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default /* @ngInject */ ($stateProvider) => { | ||
$stateProvider.state('dbaas-logs.detail.streams.stream.subscriptions', { | ||
url: '/subscriptions', | ||
component: 'dbaasLogsDetailStreamsSubscriptions', | ||
resolve: { | ||
breadcrumb: /* @ngInject */ ($translate) => | ||
$translate.instant('dbaas_logs_streams_subscriptions'), | ||
}, | ||
}); | ||
}; |
3 changes: 3 additions & 0 deletions
3
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_de_DE.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dbaas_logs_streams_subscriptions": "Abonnements" | ||
} |
3 changes: 3 additions & 0 deletions
3
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_en_GB.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dbaas_logs_streams_subscriptions": "Subscriptions" | ||
} |
3 changes: 3 additions & 0 deletions
3
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_es_ES.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dbaas_logs_streams_subscriptions": "Suscripciones" | ||
} |
3 changes: 3 additions & 0 deletions
3
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_CA.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dbaas_logs_streams_subscriptions": "Abonnements" | ||
} |
3 changes: 3 additions & 0 deletions
3
...modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dbaas_logs_streams_subscriptions": "Abonnements" | ||
} |
Oops, something went wrong.