Skip to content

Commit

Permalink
client-side logic to properly set/unset Vs in SkipIndexReplication se…
Browse files Browse the repository at this point in the history
…tting in replication destination UI
  • Loading branch information
myarichuk committed Jul 26, 2015
1 parent 973f148 commit 3b12ddf
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 178 deletions.
2 changes: 2 additions & 0 deletions Raven.Studio.Html5/App/models/replicationDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class replicationDestination {
} else if (this.apiKey()) {
this.isApiKeyCredentials(true);
}

this.skipIndexReplication.subscribe(() => ko.postbox.publish('skip-index-replication'));
}

static empty(databaseName: string): replicationDestination {
Expand Down
66 changes: 59 additions & 7 deletions Raven.Studio.Html5/App/viewmodels/replications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,48 @@ class replications extends viewModelBase {
replicationConfig = ko.observable<replicationConfig>(new replicationConfig({ DocumentConflictResolution: "None", AttachmentConflictResolution: "None" }));
replicationsSetup = ko.observable<replicationsSetup>(new replicationsSetup({ Destinations: [], Source: null }));


serverPrefixForHiLoDirtyFlag = new ko.DirtyFlag([]);
replicationConfigDirtyFlag = new ko.DirtyFlag([]);
replicationsSetupDirtyFlag = new ko.DirtyFlag([]);

isServerPrefixForHiLoSaveEnabled: KnockoutComputed<boolean>;
isConfigSaveEnabled: KnockoutComputed<boolean>;
isSetupSaveEnabled: KnockoutComputed<boolean>;
isReplicateIndexesToAllEnabled : KnockoutComputed<boolean>;

skipIndexReplicationForAllDestinationsStatus = ko.observable<string>();

skipIndexReplicationForAll = ko.observable<boolean>();

private skipIndexReplicationForAllSubscription : KnockoutSubscription;

private refereshSkipIndexReplicationForAllDestinations() {
if (this.skipIndexReplicationForAllSubscription != null)
this.skipIndexReplicationForAllSubscription.dispose();

var newStatus = this.getIndexReplicationStatusForAllDestinations();
this.skipIndexReplicationForAll(newStatus === 'all');

this.skipIndexReplicationForAllSubscription = this.skipIndexReplicationForAll.subscribe(newValue => this.toggleIndexReplication(newValue));
}

private getIndexReplicationStatusForAllDestinations(): string {
var countOfSkipIndexReplication: number = 0;
ko.utils.arrayForEach(this.replicationsSetup().destinations(), dest => {
if (dest.skipIndexReplication() === true) {
countOfSkipIndexReplication++;
}
});

if (countOfSkipIndexReplication === this.replicationsSetup().destinations().length)
return 'all';

// ReSharper disable once ConditionIsAlwaysConst
if (countOfSkipIndexReplication === 0)
return 'none';

return 'mixed';
}

readFromAllAllowWriteToSecondaries = ko.computed(() => {
var behaviour = this.replicationsSetup().clientFailoverBehaviour();
Expand All @@ -53,15 +87,14 @@ class replications extends viewModelBase {
activate(args) {
super.activate(args);
this.updateHelpLink('7K1KES');

this.serverPrefixForHiLoDirtyFlag = new ko.DirtyFlag([this.prefixForHilo]);
this.isServerPrefixForHiLoSaveEnabled = ko.computed(() => this.serverPrefixForHiLoDirtyFlag().isDirty());
this.replicationConfigDirtyFlag = new ko.DirtyFlag([this.replicationConfig]);
this.isConfigSaveEnabled = ko.computed(() => this.replicationConfigDirtyFlag().isDirty());
this.replicationsSetupDirtyFlag = new ko.DirtyFlag([this.replicationsSetup, this.replicationsSetup().destinations(), this.replicationConfig, this.replicationsSetup().clientFailoverBehaviour]);
this.replicationsSetupDirtyFlag = new ko.DirtyFlag([this.replicationsSetup, this.replicationsSetup().destinations(), this.skipIndexReplicationForAll, this.replicationConfig, this.replicationsSetup().clientFailoverBehaviour]);
this.isSetupSaveEnabled = ko.computed(() => this.replicationsSetupDirtyFlag().isDirty());

this.isReplicateIndexesToAllEnabled = ko.computed(() => this.replicationsSetup().destinations().length > 0);
var combinedFlag = ko.computed(() => {
return (this.replicationConfigDirtyFlag().isDirty() || this.replicationsSetupDirtyFlag().isDirty() || this.serverPrefixForHiLoDirtyFlag().isDirty());
});
Expand Down Expand Up @@ -90,14 +123,28 @@ class replications extends viewModelBase {
var deferred = $.Deferred();
new getReplicationsCommand(db)
.execute()
.done(repSetup => this.replicationsSetup(new replicationsSetup(repSetup)))
.done(repSetup =>
{
this.replicationsSetup(new replicationsSetup(repSetup));

ko.postbox.subscribe('skip-index-replication',() => this.refereshSkipIndexReplicationForAllDestinations());

var status = this.getIndexReplicationStatusForAllDestinations();
if (status === 'all')
this.skipIndexReplicationForAll(true);
else
this.skipIndexReplicationForAll(false);

this.skipIndexReplicationForAllSubscription = this.skipIndexReplicationForAll.subscribe(newValue => this.toggleIndexReplication(newValue));
})
.always(() => deferred.resolve({ can: true }));
return deferred;
}

createNewDestination() {
var db = this.activeDatabase();
this.replicationsSetup().destinations.unshift(replicationDestination.empty(db.name));
this.refereshSkipIndexReplicationForAllDestinations();
}

removeDestination(repl: replicationDestination) {
Expand Down Expand Up @@ -137,7 +184,13 @@ class replications extends viewModelBase {
}
}

sendReplicateCommand(destination: replicationDestination,parentClass: replications) {
toggleIndexReplication(skipReplicationValue : boolean) {
this.replicationsSetup().destinations().forEach(dest => {
dest.skipIndexReplication(skipReplicationValue);
});
}

sendReplicateCommand(destination: replicationDestination, parentClass: replications) {
var db = parentClass.activeDatabase();
if (db) {
new replicateIndexesCommand(db, destination).execute();
Expand All @@ -155,7 +208,6 @@ class replications extends viewModelBase {
} else {
alert('No database selected! This error should not be seen.'); //precaution to ease debugging - in case something bad happens
}

}

saveServerPrefixForHiLo() {
Expand Down
Loading

0 comments on commit 3b12ddf

Please sign in to comment.