Show create dialog when accessing unexisting pad (fixes #65)

pull/108/head
Candid Dauth 2017-03-29 16:53:58 +02:00
rodzic 7b3cb71c80
commit 54527f4d0c
5 zmienionych plików z 42 dodań i 18 usunięć

Wyświetl plik

@ -182,7 +182,7 @@ class Socket {
this._receiveMultiple(obj);
}).catch((err) => {
this.serverError = err;
this.disconnect();
throw err;
});
}

Wyświetl plik

@ -372,15 +372,29 @@ fm.app.factory("fmMap", function(fmUtils, fmSocket, fmMapMessages, fmMapMarkers,
var loadedWatcher = map.socket.$watch("padData", function(padData) {
if(padData != null) {
loadedWatcher();
resolve(padData);
}
});
var serverErrorWatcher = map.socket.$watch("serverError", function(serverError) {
if(serverError != null) {
serverErrorWatcher();
if(serverError.indexOf('does not exist') != -1) {
map.socket.serverError = null;
map.padUi.createPad(map.socket.padId, true);
}
if(!map.hashUi.hasLocationHash())
map.displayView(padData.defaultView);
resolve();
}
});
});
} else {
if(!map.hashUi.hasLocationHash()) {
}
}).then((padData) => {
if(!map.hashUi.hasLocationHash()) {
if(padData)
map.displayView(padData.defaultView);
else {
return $q.resolve($.get({
url: "https://freegeoip.net/json/",
dataType: "json"
@ -409,10 +423,13 @@ fm.app.factory("fmMap", function(fmUtils, fmSocket, fmMapMessages, fmMapMarkers,
});
map.socket.$watch("serverError", function(serverError) {
if(serverError) {
errorMessage && errorMessage.close();
map.messages.showMessage("danger", serverError);
if(errorMessage) {
errorMessage.close();
errorMessage = null;
}
if(serverError)
errorMessage = map.messages.showMessage("danger", serverError);
});
map.map.on("moveend", function() {

Wyświetl plik

@ -1,5 +1,5 @@
<div class="modal-header">
<button type="button" class="close" ng-click="$dismiss()"><span aria-hidden="true">&times;</span></button>
<button ng-if="!noCancel" type="button" class="close" ng-click="$dismiss()"><span aria-hidden="true">&times;</span></button>
<h3 class="modal-title">{{create ? 'Start collaborative map' : 'Map settings'}}</h3>
</div>
<div class="modal-body">
@ -67,6 +67,6 @@
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$dismiss()">Cancel</button>
<button ng-if="!noCancel" type="button" class="btn btn-default" ng-click="$dismiss()">Cancel</button>
<button type="submit" class="btn btn-primary" ng-click="save()" ng-disabled="writeError || readError">{{create ? 'Create' : 'Save'}}</button>
</div>

Wyświetl plik

@ -4,10 +4,10 @@ import $ from 'jquery';
fm.app.factory("fmMapPad", function($uibModal, fmUtils) {
return function(map) {
var ret = {
createPad : function() {
ret.editPadSettings(true);
createPad : function(proposedWriteId, noCancel) {
ret.editPadSettings(true, proposedWriteId, noCancel);
},
editPadSettings : function(create) {
editPadSettings : function(create, proposedWriteId, noCancel) {
var scope = map.socket.$new();
var dialog = $uibModal.open({
@ -17,8 +17,12 @@ fm.app.factory("fmMapPad", function($uibModal, fmUtils) {
size: "lg",
resolve: {
map: function() { return map; },
create: function() { return create; }
}
create: function() { return create; },
proposedWriteId: function() { return proposedWriteId; },
noCancel: function() { return noCancel; }
},
keyboard: !noCancel,
backdrop: noCancel ? "static" : true
});
if(!create) {
@ -52,12 +56,13 @@ fm.app.factory("fmMapPad", function($uibModal, fmUtils) {
};
});
fm.app.controller("fmMapPadSettingsCtrl", function($scope, map, create, fmUtils) {
fm.app.controller("fmMapPadSettingsCtrl", function($scope, map, create, proposedWriteId, noCancel, fmUtils) {
$scope.urlPrefix = fm.URL_PREFIX;
$scope.create = create;
$scope.noCancel = noCancel;
if(create) {
$scope.writeId = fmUtils.generateRandomPadId(14);
$scope.writeId = (proposedWriteId || fmUtils.generateRandomPadId(14));
$scope.readId = fmUtils.generateRandomPadId(12);
$scope.padData = {
padName: "New FacilMap",

Wyświetl plik

@ -149,8 +149,10 @@ utils.extend(SocketConnection.prototype, {
return utils.extend(JSON.parse(JSON.stringify(write)), { writable: true });
else if(read)
return utils.extend(JSON.parse(JSON.stringify(read)), { writable: false, writeId: null });
else
else {
this.padId = null;
throw "This pad does not exist";
}
}
}).then(res => {
this.padId = res.pad.id;