| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- /*
- Copyright (C) 2017 Cloudbase Solutions SRL
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- import Reflux from 'reflux';
- import UserActions from '../../actions/UserActions';
- import NotificationActions from '../../actions/NotificationActions';
- import ConnectionsActions from '../../actions/ConnectionsActions';
- import MigrationActions from '../../actions/MigrationActions';
- import Location from '../../core/Location';
- class NotificationsStore extends Reflux.Store
- {
- constructor() {
- super()
- this.listenables = [UserActions, NotificationActions, ConnectionsActions, MigrationActions]
- this.state = {
- notifications: [],
- allNotifications: []
- }
- }
- onLoginScopeSuccess() {
- let notifications = [{
- message: "Signed in",
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onTokenLoginFailed() {
- let notifications = [
- {
- message: "Session expired, please sign in",
- type: 'error'
- }
- ]
- this.setState({ notifications: notifications })
- }
- onLogout() {
- let notifications = [
- {
- message: "You have been signed out",
- type: 'info'
- }
- ]
- this.setState({ notifications: notifications })
- }
- onSaveEndpoint() {
- let notifications = [{
- title: "New Connection",
- message: "Connection added successfully",
- type: 'success',
- keep: true
- }]
- this.setState({ notifications: notifications })
- }
- onAddMigrationCompleted(response) {
- let notifications = null
- if (response.data.migration) {
- notifications = [{
- title: "New Migration",
- message: "Migration created successfully",
- type: 'success',
- keep: true,
- action: {
- label: "View Migration Status",
- callback: () => {
- Location.push("/migration/tasks/" + response.data.migration.id + "/")
- }
- }
- }]
- } else {
- notifications = [{
- title: "New Replica",
- message: "Replica created successfully",
- type: 'success',
- keep: true,
- action: {
- label: "View Replica Status",
- callback: () => {
- Location.push("/replica/executions/" + response.data.replica.id + "/")
- }
- }
- }]
- }
- this.setState({ notifications: notifications })
- }
- onDeleteConnection() {
- let notifications = [{
- message: "Connection deleted successfully",
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onDeleteMigrationCompleted() {
- let notifications = [{
- message: "Migration deleted successfully",
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onDeleteMigrationFailed() {
- let notifications = [{
- message: "Could not delete migration",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onDeleteReplicaCompleted() {
- let notifications = [{
- message: "Replica deleted successfully",
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onDeleteReplicaFailed() {
- let notifications = [{
- message: "Could not delete replica",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onLoginFailed() {
- let notifications = [{
- message: "Login failed",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onExecuteReplicaCompleted() {
- let notifications = [{
- message: "Executing replica",
- type: 'info'
- }]
- this.setState({ notifications: notifications })
- }
- onDeleteReplicaExecutionCompleted() {
- let notifications = [{
- message: "Execution deleted",
- type: 'info'
- }]
- this.setState({ notifications: notifications })
- }
- onCancelMigrationCompleted(migration) {
- let message = "Canceled"
- if (migration.type == "migration") {
- message = "Migration canceled successful"
- }
- let notifications = [{
- message: message,
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onCreateMigrationFromReplicaCompleted(response) {
- let notifications = [{
- title: "New Migration",
- message: "Migration successfully created from replica.",
- type: 'success',
- hideDelay: 10000,
- keep: true,
- action: {
- label: "View Migration Status",
- callback: () => {
- Location.push("/migration/tasks/" + response.data.migration.id + "/")
- }
- }
- }]
- this.setState({ notifications: notifications })
- }
- onLoadInstancesFailed() {
- let notifications = [{
- message: "Could not load instances.",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onNewEndpoint() {
- let notifications = [{
- message: "Saving endpoint...",
- type: 'info'
- }]
- this.setState({ notifications: notifications })
- }
- onEditEndpoint() {
- let notifications = [{
- message: "Saving endpoint...",
- type: 'info'
- }]
- this.setState({ notifications: notifications })
- }
- onEditEndpointFailed() {
- let notifications = [{
- message: "Could not save endpoint",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onSaveEditEndpointSuccess() {
- let notifications = [{
- message: "Endpoint saved!",
- type: 'success'
- }]
- this.setState({ notifications: notifications })
- }
- onSaveEditEndpointFailed() {
- let notifications = [{
- message: "Could not save endpoint",
- type: 'error'
- }]
- this.setState({ notifications: notifications })
- }
- onNotify(message, type = "info", title = null) {
- this.setState({
- notifications: [
- {
- message: message,
- type: type,
- title: title
- }
- ]
- })
- }
- onMarkAsRead() {
- let allNotifications = this.state.allNotifications
- allNotifications.forEach(notification => {
- notification.unread = false
- })
- this.setState({ allNotifications: allNotifications })
- }
- onKeepNotification(notification) {
- let allNotifications = this.state.allNotifications
- allNotifications.unshift(notification)
- this.setState({ allNotifications: allNotifications })
- }
- onRemoveNotification() {
- this.setState({ notifications: [] })
- }
- onSwitchProject() {
- let notifications = [{
- message: "Switching project",
- type: 'info'
- }]
- this.setState({ notifications: notifications })
- }
- }
- export default NotificationsStore;
|