Skip to content

Commit

Permalink
Merge branch 'support_view'
Browse files Browse the repository at this point in the history
  • Loading branch information
yoichiro committed Sep 1, 2014
2 parents 8237a2d + d071edc commit 78005ba
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 130 deletions.
2 changes: 1 addition & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ChromeMyAdmin",
"short_name": "MyAdmin",
"description": "This application provides you 'MySQL GUI Admin console' windows.",
"version": "2.4.0",
"version": "2.5.0",
"author": "Yoichiro Tanaka",
"app": {
"background": {
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/window/controllers/add_index_dialog_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ chromeMyAdmin.controller("AddIndexDialogController", ["$scope", "Events", "mySQL
var sql = "";
var columnListString = "(" + createColumnListString($scope.selectedColumns) + ")";
if ($scope.keyType === "PRIMARY") {
sql += "ALTER TABLE `" + $scope.selectedTable + "` ADD PRIMARY KEY ";
sql += "ALTER TABLE `" + $scope.selectedTable.name + "` ADD PRIMARY KEY ";
sql += columnListString;
} else if ($scope.keyType === "INDEX") {
sql += "ALTER TABLE `" + $scope.selectedTable + "` ADD INDEX ";
sql += "ALTER TABLE `" + $scope.selectedTable.name + "` ADD INDEX ";
if ($scope.keyName) {
sql += "`" + $scope.keyName + "` ";
}
sql += columnListString;
} else if ($scope.keyType === "UNIQUE") {
sql += "ALTER TABLE `" + $scope.selectedTable + "` ADD UNIQUE INDEX ";
sql += "ALTER TABLE `" + $scope.selectedTable.name + "` ADD UNIQUE INDEX ";
if ($scope.keyName) {
sql += "`" + $scope.keyName + "` ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ chromeMyAdmin.controller("CreateTableDialogController", ["$scope", "targetObject
} else {
$("#createTableDialog").modal("hide");
targetObjectService.refreshTableList();
targetObjectService.changeTable(tableName);
targetObjectService.changeTable({
name: tableName,
type: "BASE TABLE",
className: "glyphicon-th-large"
});
modeService.changeMode(Modes.STRUCTURE);
}
}, function(reason) {
Expand Down
60 changes: 50 additions & 10 deletions app/scripts/window/controllers/database_object_list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chromeMyAdmin.directive("databaseObjectListPanel", function() {
};
});

chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClientService", "targetObjectService", "modeService", "Events", "Modes", "mySQLQueryService", "UIConstants", function($scope, mySQLClientService, targetObjectService, modeService, Events, Modes, mySQLQueryService, UIConstants) {
chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClientService", "targetObjectService", "modeService", "Events", "Modes", "mySQLQueryService", "UIConstants", "TableTypes", function($scope, mySQLClientService, targetObjectService, modeService, Events, Modes, mySQLQueryService, UIConstants, TableTypes) {
"use strict";

var assignWindowResizeEventHandler = function() {
Expand Down Expand Up @@ -47,7 +47,18 @@ chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClient
var updateTableList = function(columnDefinition, resultsetRows) {
var tables = [];
for (var i = 0; i < resultsetRows.length; i++) {
tables.push(resultsetRows[i].values[0]);
var type = resultsetRows[i].values[1];
var className;
if (type === "VIEW") {
className = "glyphicon-eye-open";
} else {
className = "glyphicon-th-large";
}
tables.push({
name: resultsetRows[i].values[0],
type: type,
className: className
});
}
$scope.tables = tables;
};
Expand All @@ -68,15 +79,25 @@ chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClient
};

var doDropTable = function() {
var sql = "DROP TABLE `" + targetObjectService.getTable() + "`";
var table = targetObjectService.getTable();
var type;
if (table.type === TableTypes.BASE_TABLE) {
type = "TABLE";
} else if (table.type === TableTypes.VIEW) {
type = "VIEW";
} else {
console.log("Warning: Invalid table type: " + table.type);
type = table.type;
}
var sql = "DROP " + type + " `" + table.name + "`";
mySQLClientService.query(sql).then(function(result) {
if (result.hasResultsetRows) {
$scope.fatalErrorOccurred("Dropping table failed.");
$scope.fatalErrorOccurred("Dropping " + type + " failed.");
} else {
doRefresh();
}
}, function(reason) {
$scope.showErrorDialog("Dropping table failed.", reason);
$scope.showErrorDialog("Dropping " + type + " failed.", reason);
doRefresh();
});
};
Expand All @@ -103,16 +124,17 @@ chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClient
adjustObjectListHeight();
};

$scope.selectTable = function(tableName) {
targetObjectService.changeTable(tableName);
$scope.selectTable = function(table) {
targetObjectService.changeTable(table);
if (modeService.getMode() === Modes.DATABASE ||
modeService.getMode() === Modes.QUERY) {
modeService.changeMode(Modes.ROWS);
}
};

$scope.isTableActive = function(tableName) {
return tableName === targetObjectService.getTable();
var table = targetObjectService.getTable();
return table && tableName === table.name;
};

$scope.refresh = function() {
Expand All @@ -132,12 +154,30 @@ chromeMyAdmin.controller("DatabaseObjectListController", ["$scope", "mySQLClient
};

$scope.isTableSelection = function() {
return targetObjectService.getTable() !== null;
var table = targetObjectService.getTable();
return table && table.name !== null;
};

$scope.canDelete = function() {
var table = targetObjectService.getTable();
if (table) {
return table.type === TableTypes.BASE_TABLE ||
table.type === TableTypes.VIEW;
} else {
return false;
}
};

$scope.confirmDropSelectedTable = function() {
var table = targetObjectService.getTable();
var type;
if (table.type === TableTypes.BASE_TABLE) {
type = "table";
} else if (table.type === TableTypes.VIEW) {
type = "view";
}
$scope.showConfirmDialog(
"Would you really like to drop the selected table from MySQL server?",
"Would you really like to drop the selected " + type + " from MySQL server?",
"Yes",
"No",
Events.DROP_SELECTED_TABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ chromeMyAdmin.controller("EditColumnDialogController", ["$scope", "Events", "myS
};

$scope.editColumn = function() {
var sql = "ALTER TABLE `" + $scope.selectedTable + "` ";
var sql = "ALTER TABLE `" + $scope.selectedTable.name + "` ";
sql += "CHANGE COLUMN `" + $scope.originalColumnStructure.Field + "` `";
sql += $scope.columnName + "` ";
sql += $scope.type;
Expand Down
42 changes: 26 additions & 16 deletions app/scripts/window/controllers/information_panel_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chromeMyAdmin.directive("informationPanel", function() {
};
});

chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientService", "modeService", "Events", "Modes", "targetObjectService", "Engines", "UIConstants", "mySQLQueryService", function($scope, mySQLClientService, modeService, Events, Modes, targetObjectService, Engines, UIConstants, mySQLQueryService) {
chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientService", "modeService", "Events", "Modes", "targetObjectService", "Engines", "UIConstants", "mySQLQueryService", "TableTypes", function($scope, mySQLClientService, modeService, Events, Modes, targetObjectService, Engines, UIConstants, mySQLQueryService, TableTypes) {
"use strict";

var _isInformationPanelVisible = function() {
Expand Down Expand Up @@ -64,22 +64,23 @@ chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientSe

var onModeChanged = function(mode) {
if (mode === Modes.INFORMATION) {
var tableName = targetObjectService.getTable();
if (tableName) {
$scope.tableName = tableName;
loadCollations(tableName);
var table = targetObjectService.getTable();
if (table) {
$scope.selectedTable = table;
loadCollations(table.name);
} else {
$scope.tableName = null;
$scope.selectedTable = null;
}
}
};

var onTableChanged = function(tableName) {
var onTableChanged = function(table) {
if (_isInformationPanelVisible()) {
$scope.tableName = tableName;
if (tableName) {
loadCollations(tableName);
if (table) {
$scope.selectedTable = table;
loadCollations(table.name);
} else {
$scope.selectedTable = null;
resetDiplayedValues();
}
}
Expand All @@ -92,8 +93,8 @@ chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientSe
$scope.$on(Events.DATABASE_CHANGED, function(event, database) {
resetDiplayedValues();
});
$scope.$on(Events.TABLE_CHANGED, function(event, tableName) {
onTableChanged(tableName);
$scope.$on(Events.TABLE_CHANGED, function(event, table) {
onTableChanged(table);
});
$scope.$on(Events.MODE_CHANGED, function(event, mode) {
onModeChanged(mode);
Expand Down Expand Up @@ -138,13 +139,13 @@ chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientSe
$scope.onCollationChanged = function() {
var collation = $scope["tableStatus_Collation"];
var encoding = collation.split("_")[0];
var sql = "ALTER TABLE `" + targetObjectService.getTable() + "` " +
var sql = "ALTER TABLE `" + targetObjectService.getTable().name + "` " +
"CHARACTER SET " + encoding + " COLLATE " + collation;
mySQLClientService.query(sql).then(function(result) {
if (result.hasResultsetRows) {
$scope.fatalErrorOccurred("Changing table character set and collation failed.");
} else {
loadCollations(targetObjectService.getTable());
loadCollations(targetObjectService.getTable().name);
}
}, function(reason) {
$scope.fatalErrorOccurred(reason);
Expand All @@ -153,13 +154,13 @@ chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientSe

$scope.onEngineChanged = function() {
var engine = $scope["tableStatus_Engine"];
var sql = "ALTER TABLE `" + targetObjectService.getTable() + "` " +
var sql = "ALTER TABLE `" + targetObjectService.getTable().name + "` " +
"ENGINE = " + engine;
mySQLClientService.query(sql).then(function(result) {
if (result.hasResultsetRows) {
$scope.fatalErrorOccurred("Changing table engine failed.");
} else {
loadCollations(targetObjectService.getTable());
loadCollations(targetObjectService.getTable().name);
}
}, function(reason) {
$scope.fatalErrorOccurred(reason);
Expand All @@ -172,6 +173,15 @@ chromeMyAdmin.controller("InformationPanelController", ["$scope", "mySQLClientSe
editor.setShowPrintMargin(false);
editor.setShowInvisibles(true);
editor.setReadOnly(true);
editor.getSession().setUseWrapMode(true);
};

$scope.isTable = function() {
if ($scope.selectedTable) {
return $scope.selectedTable.type === TableTypes.BASE_TABLE;
} else {
return false;
}
};

}]);
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ chromeMyAdmin.controller("InsertRowDialogController", ["$scope", "targetObjectSe
$scope.insertRow = function() {
resetErrorMessage();
var sql = sqlExpressionService.createInsertStatement(
targetObjectService.getTable(), $scope.values, $scope.valueTypes);
targetObjectService.getTable().name, $scope.values, $scope.valueTypes);
if (sql) {
mySQLClientService.query(sql).then(function(result) {
if (result.hasResultsetRows) {
Expand Down
52 changes: 36 additions & 16 deletions app/scripts/window/controllers/main_footer_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chromeMyAdmin.directive("mainFooter", function() {
};
});

chromeMyAdmin.controller("MainFooterController", ["$scope", "modeService", "mySQLClientService", "rowsPagingService", "rowsSelectionService", "targetObjectService", "Events", "Modes", "relationSelectionService", function($scope, modeService, mySQLClientService, rowsPagingService, rowsSelectionService, targetObjectService, Events, Modes, relationSelectionService) {
chromeMyAdmin.controller("MainFooterController", ["$scope", "modeService", "mySQLClientService", "rowsPagingService", "rowsSelectionService", "targetObjectService", "Events", "Modes", "relationSelectionService", "TableTypes", function($scope, modeService, mySQLClientService, rowsPagingService, rowsSelectionService, targetObjectService, Events, Modes, relationSelectionService, TableTypes) {
"use strict";

var showMainStatusMessage = function(message) {
Expand Down Expand Up @@ -92,24 +92,39 @@ chromeMyAdmin.controller("MainFooterController", ["$scope", "modeService", "mySQ
};

$scope.confirmDeleteSelectedRow = function() {
$scope.showConfirmDialog(
"Would you really like to delete the selected row from MySQL server?",
"Yes",
"No",
Events.DELETE_SELECTED_ROW
);
if ($scope.isTable() && $scope.isRowSelection()) {
$scope.showConfirmDialog(
"Would you really like to delete the selected row from MySQL server?",
"Yes",
"No",
Events.DELETE_SELECTED_ROW
);
}
};

$scope.isTableSelection = function() {
return targetObjectService.getTable();
};

$scope.isTable = function() {
var table = targetObjectService.getTable();
if (table) {
return table.type === TableTypes.BASE_TABLE;
} else {
return false;
}
};

$scope.insertRow = function() {
targetObjectService.requestInsertRow();
if ($scope.isTable()) {
targetObjectService.requestInsertRow();
}
};

$scope.updateRow = function() {
targetObjectService.requestUpdateRow();
if ($scope.isTable() && $scope.isRowSelection()) {
targetObjectService.requestUpdateRow();
}
};

$scope.createDatabase = function() {
Expand Down Expand Up @@ -142,16 +157,21 @@ chromeMyAdmin.controller("MainFooterController", ["$scope", "modeService", "mySQ
};

$scope.confirmDeleteSelectedRelation = function() {
$scope.showConfirmDialog(
"Would you really like to delete the selected relation from the database?",
"Yes",
"No",
Events.DELETE_SELECTED_RELATION
);
if ($scope.isTable() && $scope.isRelationSelection()) {
$scope.showConfirmDialog(
"Would you really like to delete the selected relation from the database?",
"Yes",
"No",
Events.DELETE_SELECTED_RELATION
);
}
};

$scope.addRelation = function() {
targetObjectService.showAddRelationDialog(targetObjectService.getTable());
var table = targetObjectService.getTable();
if (table && table.type === TableTypes.BASE_TABLE) {
targetObjectService.showAddRelationDialog(table.name);
}
};

}]);
Loading

0 comments on commit 78005ba

Please sign in to comment.