Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kpwebb committed Aug 4, 2015
1 parent de419b1 commit 6729b31
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/SnapshotController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void createSnapshot () {
try {
// create a dummy snapshot from which to get values
Snapshot original = Base.mapper.readValue(params.get("body"), Snapshot.class);
Snapshot s = VersionedDataStore.takeSnapshot(original.agencyId, original.name);
Snapshot s = VersionedDataStore.takeSnapshot(original.agencyId, original.name, original.comment);
s.validFrom = original.validFrom;
s.validTo = original.validTo;
gtx = VersionedDataStore.getGlobalTx();
Expand Down
3 changes: 2 additions & 1 deletion app/datastore/VersionedDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static DB getRawAgencyTx (String agencyId) {
}

/** Take a snapshot of an agency database. The snapshot will be saved in the global database. */
public static Snapshot takeSnapshot (String agencyId, String name) {
public static Snapshot takeSnapshot (String agencyId, String name, String comment) {
AgencyTx tx = getAgencyTx(agencyId);
GlobalTx gtx = getGlobalTx();
int version = -1;
Expand All @@ -97,6 +97,7 @@ public static Snapshot takeSnapshot (String agencyId, String name) {

ret.snapshotTime = System.currentTimeMillis();
ret.name = name;
ret.comment = comment;
ret.current = true;

snapshot = getSnapshotDb(agencyId, version, false);
Expand Down
5 changes: 4 additions & 1 deletion app/models/Snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class Snapshot implements Cloneable, Serializable {

/** The name of this snapshot */
public String name;


/** The comment of this snapshot */
public String comment;

/** ID: agency ID, version */
@JsonSerialize(using=JacksonSerializers.Tuple2IntSerializer.class)
@JsonDeserialize(using=JacksonSerializers.Tuple2IntDeserializer.class)
Expand Down
7 changes: 6 additions & 1 deletion app/views/Application/snapshots.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ <h2>&{'snapshot.for'} {{ agencyName }}</h2>
</p>
<table class="table table-striped">
<thead>
<th>&{'snapshot.name'}</th><th>&{'snapshot.version'}</th><th>&{'snapshot.valid-from'}</th><th>&{'snapshot.valid-to'}</th><th>&{'snapshot.date'}</th><th>&{'snapshot.current'}<th>&{'snapshot.restore'}</th>
<th>&{'snapshot.name'}</th><th>&{'snapshot.comment'}</th><th>&{'snapshot.version'}</th><th>&{'snapshot.valid-from'}</th><th>&{'snapshot.valid-to'}</th><th>&{'snapshot.date'}</th><th>&{'snapshot.current'}<th>&{'snapshot.restore'}</th>
</thead>
<tbody>
{{#snapshots}}
<tr>
<td>{{name}}</td>
<td>{{comment}}</td>
<td>{{version}}</td>
<td>{{validFrom}} <button class="btn btn-link edit-from" data-snapshot="{{id}}"><i class="icon-pencil"></i><span class="sr-only">&{'shared.button.edit'}</span></button></td>
<td>{{validTo}} <button class="btn btn-link edit-to" data-snapshot="{{id}}"><i class="icon-pencil"></i><span class="sr-only">&{'shared.button.edit'}</span></button></td>
Expand All @@ -43,6 +44,7 @@ <h2>&{'snapshot.for'} {{ agencyName }}</h2>
<td><button class="btn btn-link restore-snapshot" data-snapshot="{{id}}"><i class="icon-refresh"></i>&nbsp;&{'snapshot.restore'}</button></td>
<td><a class="btn btn-link export-snapshot" href="api/snapshot/{{id}}.zip"><i class="icon-download"></i>&nbsp;&{'snapshot.download'}</button></td>
</tr>

{{/snapshots}}
</tbody>
</table>
Expand All @@ -64,6 +66,9 @@ <h3>&{'snapshot.take-snapshot'}</h3>
<label for="snapshot-name">&{'snapshot.name'}</label>
<input type="text" id="snapshot-name" />

<label for="snapshot-name">&{'snapshot.comment'}</label>
<textarea type="text" id="snapshot-comment"></textarea>

<label for="valid-from">&{'snapshot.valid-from'}</label>
<div class="input-append date" id="valid-from">
<input size="96" type="text" />
Expand Down
1 change: 1 addition & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ snapshot.for=Snapshots for
snapshot.new=Take snapshot
snapshot.restore=Restore snapshot
snapshot.name=Name
snapshot.comment=Comment
snapshot.date=Snapshot date
snapshot.snapshots=Snapshots
snapshot.take-before-restore=You must create a snapshot of the current state of the database before you can restore a previous version.
Expand Down
1 change: 1 addition & 0 deletions public/javascripts/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ G.Trip = Backbone.Model.extend({
G.Snapshot = Backbone.Model.extend({
defaults: {
name: null,
comment: null,
id: null,
agencyId: null,
snapshotTime: null,
Expand Down
17 changes: 10 additions & 7 deletions public/javascripts/pages/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,26 @@ var GtfsEditor = GtfsEditor || {};
takeSnapshot: function () {
var instance = this;
var name = this.$('#snapshot-name').val();
var comment = this.$('#snapshot-comment').val();
var dfrom = this.toIso(this.$('#valid-from').data('datepicker').getDate());
var dto = this.toIso(this.$('#valid-to').data('datepicker').getDate());

this.$('#modal-container button.snapshot').prop('disabled', true).text('Saving . . .');

this.collection.create({
name: name,
comment: comment,
validFrom: dfrom,
validTo: dto,
agencyId: G.session.agencyId
}, {
wait: true,


success: function () {
this.$('#modal-container > .modal').modal('hide').remove();
instance.collection.fetch({reset: true, data: {agencyId: G.session.agencyId}});
}});
success: function () {
this.$('#modal-container > .modal').modal('hide').remove();
instance.collection.fetch({reset: true, data: {agencyId: G.session.agencyId}});
}
}
);
},

/** convert a local date to an iso date */
Expand All @@ -134,8 +136,9 @@ var GtfsEditor = GtfsEditor || {};
takeSnapshotAndRestore: function (e) {
var instance = this;
var name = this.$('#snapshot-name').val();
var comment = this.$('#snapshot-comment').val();
this.$('#modal-container button.snapshot').prop('disabled', true).text('Saving . . .');
this.collection.create({name: name, agencyId: G.session.agencyId},
this.collection.create({name: name, comment: comment, agencyId: G.session.agencyId},
{wait: true, success: function () {
var id = $(e.target).attr('data-snapshot');
instance.$('.restore-snapshot').prop('disabled', true);
Expand Down

0 comments on commit 6729b31

Please sign in to comment.