mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Refactor content editor - Allow loading resources from existing json files.
This commit is contained in:
@@ -236,22 +236,34 @@ var ATEditor = (function(ATEditor, model, importExport, exampleData) {
|
|||||||
$scope.sections = model.sections;
|
$scope.sections = model.sections;
|
||||||
$scope.content = "";
|
$scope.content = "";
|
||||||
$scope.selectedSection = $scope.selectedSection || model.items;
|
$scope.selectedSection = $scope.selectedSection || model.items;
|
||||||
|
$scope.importType = $scope.importType || 'paste';
|
||||||
|
$scope.availableFiles = ATEditor.exampleData.resources;
|
||||||
|
|
||||||
$scope.importData = function() {
|
var countBefore = 0;
|
||||||
|
function success() {
|
||||||
|
var section = $scope.selectedSection;
|
||||||
|
var countAfter = section.items.length;
|
||||||
|
$scope.importedMsg = "Imported " + (countAfter - countBefore) + " " + section.name;
|
||||||
|
}
|
||||||
|
function error(msg) {
|
||||||
|
$scope.errorMsg = "Error importing data: " + msg;
|
||||||
|
}
|
||||||
|
$scope.importPastedData = function() {
|
||||||
$scope.errorMsg = "";
|
$scope.errorMsg = "";
|
||||||
$scope.importedMsg = "";
|
$scope.importedMsg = "";
|
||||||
|
|
||||||
var section = $scope.selectedSection;
|
var section = $scope.selectedSection;
|
||||||
var countBefore = section.items.length;
|
countBefore = section.items.length;
|
||||||
function success() {
|
|
||||||
var countAfter = section.items.length;
|
|
||||||
$scope.importedMsg = "Imported " + (countAfter - countBefore) + " " + section.name;
|
|
||||||
}
|
|
||||||
function error(msg) {
|
|
||||||
$scope.errorMsg = "Error importing data: " + msg;
|
|
||||||
}
|
|
||||||
importExport.importText(section, $scope.content, success, error);
|
importExport.importText(section, $scope.content, success, error);
|
||||||
};
|
};
|
||||||
|
$scope.importExistingData = function() {
|
||||||
|
$scope.errorMsg = "";
|
||||||
|
$scope.importedMsg = "";
|
||||||
|
var section = $scope.selectedSection;
|
||||||
|
countBefore = section.items.length;
|
||||||
|
ATEditor.exampleData.loadUrlFromGit("AndorsTrail/res/raw/" + $scope.selectedFile, function(data) {
|
||||||
|
importExport.importDataObjects(section, data, success, error);
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
controllers.ExportController = function($scope) {
|
controllers.ExportController = function($scope) {
|
||||||
$scope.sections = model.sections;
|
$scope.sections = model.sections;
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ var ATEditor = (function(ATEditor, _) {
|
|||||||
};
|
};
|
||||||
this.remove = function(o) {
|
this.remove = function(o) {
|
||||||
var idx = items.indexOf(o);
|
var idx = items.indexOf(o);
|
||||||
items.splice(idx, 1);
|
if (idx >= 0) {
|
||||||
|
items.splice(idx, 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.findFirstFreeId = function(id) {
|
this.findFirstFreeId = function(id) {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ var ATEditor = (function(ATEditor, model, utils, _, $) {
|
|||||||
parseListOfResourceFiles("loadresource_droplists", model.droplists);
|
parseListOfResourceFiles("loadresource_droplists", model.droplists);
|
||||||
parseListOfResourceFiles("loadresource_quests", model.quests);
|
parseListOfResourceFiles("loadresource_quests", model.quests);
|
||||||
parseListOfResourceFiles("loadresource_conversationlists", model.dialogue);
|
parseListOfResourceFiles("loadresource_conversationlists", model.dialogue);
|
||||||
|
parseListOfResourceFiles("loadresource_monsters", model.monsters);
|
||||||
|
|
||||||
_.each(resources['itemcategory'], function(file) {
|
_.each(resources['itemcategory'], function(file) {
|
||||||
loadUrlFromGit("AndorsTrail/res/raw/" + file, function(data) {
|
loadUrlFromGit("AndorsTrail/res/raw/" + file, function(data) {
|
||||||
@@ -74,6 +75,7 @@ var ATEditor = (function(ATEditor, model, utils, _, $) {
|
|||||||
ATEditor.exampleData = {
|
ATEditor.exampleData = {
|
||||||
init: init
|
init: init
|
||||||
,resources: resources
|
,resources: resources
|
||||||
|
,loadUrlFromGit: loadUrlFromGit
|
||||||
};
|
};
|
||||||
|
|
||||||
return ATEditor;
|
return ATEditor;
|
||||||
|
|||||||
@@ -2,13 +2,32 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<p>Data to import can be found in the files named <a href="http://code.google.com/p/andors-trail/source/browse/#git%2FAndorsTrail%2Fres">res/raw/*.json</a> in the source code.</p>
|
<p>Data to import can be found in the files named <a href="http://code.google.com/p/andors-trail/source/browse/#git%2FAndorsTrail%2Fres">res/raw/*.json</a> in the source code.</p>
|
||||||
Import as
|
Import as
|
||||||
<select ng-model="selectedSection" ng-options="s.name for s in sections">
|
<select ng-model="selectedSection" ng-options="s.name for s in sections"></select>
|
||||||
</select>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<textarea id="importExportTextArea" rows="9" cols="80" ng-model="content" placeholder="paste json data here"></textarea>
|
<label for="importExisting">
|
||||||
|
<input type="radio" name="importType" id="importExisting" value="existing" ng-model="importType"></input>
|
||||||
|
Import content from existing files
|
||||||
|
</label>
|
||||||
|
<label for="importPasted">
|
||||||
|
<input type="radio" name="importType" id="importPasted" value="paste" ng-model="importType"></input>
|
||||||
|
Paste data to import
|
||||||
|
</label>
|
||||||
</p>
|
</p>
|
||||||
<button ng-click="importData()" class="btn btn-primary pull-right"><i class="icon-upload"></i> Import</button>
|
|
||||||
|
<div ng-show="importType == 'paste'">
|
||||||
|
<p>
|
||||||
|
<textarea id="importExportTextArea" rows="9" cols="80" ng-model="content" placeholder="paste json data here"></textarea>
|
||||||
|
</p>
|
||||||
|
<button ng-click="importPastedData()" class="btn btn-primary pull-right"><i class="icon-upload"></i> Import</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div ng-show="importType == 'existing'">
|
||||||
|
<p>
|
||||||
|
<select ng-model="selectedFile" ng-options="f for f in availableFiles[selectedSection.id]"></select>
|
||||||
|
</p>
|
||||||
|
<button ng-click="importExistingData()" class="btn btn-primary pull-right"><i class="icon-upload"></i> Import</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="color: red;" ng-ds-fade="errorMsg">{{errorMsg}}</div>
|
<div style="color: red;" ng-ds-fade="errorMsg">{{errorMsg}}</div>
|
||||||
<div style="color: green;" ng-ds-fade="importedMsg">{{importedMsg}}</div>
|
<div style="color: green;" ng-ds-fade="importedMsg">{{importedMsg}}</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user