mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-16 00:33:16 +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.content = "";
|
||||
$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.importedMsg = "";
|
||||
|
||||
var section = $scope.selectedSection;
|
||||
var 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;
|
||||
}
|
||||
countBefore = section.items.length;
|
||||
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) {
|
||||
$scope.sections = model.sections;
|
||||
|
||||
@@ -44,7 +44,9 @@ var ATEditor = (function(ATEditor, _) {
|
||||
};
|
||||
this.remove = function(o) {
|
||||
var idx = items.indexOf(o);
|
||||
items.splice(idx, 1);
|
||||
if (idx >= 0) {
|
||||
items.splice(idx, 1);
|
||||
}
|
||||
};
|
||||
|
||||
this.findFirstFreeId = function(id) {
|
||||
|
||||
@@ -44,6 +44,7 @@ var ATEditor = (function(ATEditor, model, utils, _, $) {
|
||||
parseListOfResourceFiles("loadresource_droplists", model.droplists);
|
||||
parseListOfResourceFiles("loadresource_quests", model.quests);
|
||||
parseListOfResourceFiles("loadresource_conversationlists", model.dialogue);
|
||||
parseListOfResourceFiles("loadresource_monsters", model.monsters);
|
||||
|
||||
_.each(resources['itemcategory'], function(file) {
|
||||
loadUrlFromGit("AndorsTrail/res/raw/" + file, function(data) {
|
||||
@@ -74,6 +75,7 @@ var ATEditor = (function(ATEditor, model, utils, _, $) {
|
||||
ATEditor.exampleData = {
|
||||
init: init
|
||||
,resources: resources
|
||||
,loadUrlFromGit: loadUrlFromGit
|
||||
};
|
||||
|
||||
return ATEditor;
|
||||
|
||||
@@ -2,13 +2,32 @@
|
||||
<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>
|
||||
Import as
|
||||
<select ng-model="selectedSection" ng-options="s.name for s in sections">
|
||||
</select>
|
||||
<select ng-model="selectedSection" ng-options="s.name for s in sections"></select>
|
||||
|
||||
<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>
|
||||
<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: green;" ng-ds-fade="importedMsg">{{importedMsg}}</div>
|
||||
|
||||
Reference in New Issue
Block a user