Bug 1264582 - Table headers are not removed when selecting an empty storage. r=mratcliffe

MozReview-Commit-ID: Hcfw7dyrDpV

--HG--
extra : transplant_source : %DDH%D0%22%A8%96%C0%F6%EAW%A6%8B%CF%CAA%3Cy%26m%E4
This commit is contained in:
Fischer.json 2016-07-01 17:42:07 +08:00
parent 3f98a1514b
commit d814fd47e3
3 changed files with 111 additions and 46 deletions

View File

@ -225,12 +225,15 @@ StorageUI.prototype = {
return this.storageTypes[type];
},
makeFieldsEditable: function* () {
let actor = this.getCurrentActor();
if (typeof actor.getEditableFields !== "undefined") {
let fields = yield actor.getEditableFields();
this.table.makeFieldsEditable(fields);
/**
* Make column fields editable
*
* @param {Array} editableFields
* An array of keys of columns to be made editable
*/
makeFieldsEditable: function* (editableFields) {
if (editableFields && editableFields.length > 0) {
this.table.makeFieldsEditable(editableFields);
} else if (this.table._editableFieldsEngine) {
this.table._editableFieldsEngine.destroy();
}
@ -486,11 +489,25 @@ StorageUI.prototype = {
}
try {
if (reason === REASON.POPULATE) {
let subType = null;
// The indexedDB type could have sub-type data to fetch.
// If having names specified, then it means
// we are fetching details of specific database or of object store.
if (type == "indexedDB" && names) {
let [ dbName, objectStoreName ] = JSON.parse(names[0]);
if (dbName) {
subType = "database";
}
if (objectStoreName) {
subType = "object store";
}
}
yield this.resetColumns(type, host, subType);
}
let {data} = yield storageType.getStoreObjects(host, names, fetchOpts);
if (data.length) {
if (reason === REASON.POPULATE) {
yield this.resetColumns(data[0], type, host);
}
this.populateTable(data, reason);
}
this.emit("store-objects-updated");
@ -731,36 +748,46 @@ StorageUI.prototype = {
/**
* Resets the column headers in the storage table with the pased object `data`
*
* @param {object} data
* The object from which key and values will be used for naming the
* headers of the columns
* @param {string} type
* The type of storage corresponding to the after-reset columns in the
* table.
* @param {string} host
* The host name corresponding to the table after reset.
*
* @param {string} [subType]
* The sub type under the given type.
*/
resetColumns: function* (data, type, host) {
let columns = {};
resetColumns: function* (type, host, subtype) {
this.table.host = host;
this.table.datatype = type;
let uniqueKey = null;
for (let key in data) {
let columns = {};
let editableFields = [];
let fields = yield this.getCurrentActor().getFields(subtype);
fields.forEach(f => {
if (!uniqueKey) {
this.table.uniqueId = uniqueKey = key;
this.table.uniqueId = uniqueKey = f.name;
}
columns[key] = key;
if (f.editable) {
editableFields.push(f.name);
}
columns[f.name] = f.name;
try {
columns[key] = L10N.getStr("table.headers." + type + "." + key);
columns[f.name] = L10N.getStr("table.headers." + type + "." + f.name);
} catch (e) {
console.error("Unable to localize table header type:" + type +
" key:" + key);
" key:" + f.name);
}
}
});
this.table.setColumns(columns, null, HIDDEN_COLUMNS);
this.table.datatype = type;
this.table.host = host;
this.hideSidebar();
yield this.makeFieldsEditable();
yield this.makeFieldsEditable(editableFields);
},
/**

View File

@ -81,6 +81,10 @@ var StorageActors = {};
* so that it can be transferred over wire.
* - populateStoresForHost : Given a host, populate the map of all store
* objects for it
* - getFields: Given a subType(optional), get an array of objects containing
* column field info. The info includes,
* "name" is name of colume key.
* "editable" is 1 means editable field; 0 means uneditable.
*
* @param {string} typeName
* The typeName of the actor.
@ -548,21 +552,17 @@ StorageActors.createActor({
return null;
},
/**
* This method marks the table as editable.
*
* @return {Array}
* An array of column header ids.
*/
getEditableFields: Task.async(function* () {
getFields: Task.async(function* () {
return [
"name",
"path",
"host",
"expires",
"value",
"isSecure",
"isHttpOnly"
{ name: "name", editable: 1},
{ name: "path", editable: 1},
{ name: "host", editable: 1},
{ name: "expires", editable: 1},
{ name: "lastAccessed", editable: 0},
{ name: "value", editable: 1},
{ name: "isDomain", editable: 0},
{ name: "isSecure", editable: 1},
{ name: "isHttpOnly", editable: 1}
];
}),
@ -1012,16 +1012,10 @@ function getObjectForLocalOrSessionStorage(type) {
}
},
/**
* This method marks the fields as editable.
*
* @return {Array}
* An array of field ids.
*/
getEditableFields: Task.async(function* () {
getFields: Task.async(function* () {
return [
"name",
"value"
{ name: "name", editable: 1},
{ name: "value", editable: 1}
];
}),
@ -1199,6 +1193,13 @@ StorageActors.createActor({
};
}),
getFields: Task.async(function* () {
return [
{ name: "url", editable: 0 },
{ name: "status", editable: 0 }
];
}),
getHostName(location) {
if (!location.host) {
return location.href;
@ -1653,6 +1654,35 @@ StorageActors.createActor({
return deferred.promise;
}
},
getFields: Task.async(function* (subType) {
switch (subType) {
// Detail of database
case "database":
return [
{ name: "objectStore", editable: 0 },
{ name: "keyPath", editable: 0 },
{ name: "autoIncrement", editable: 0 },
{ name: "indexes", editable: 0 },
];
// Detail of object store
case "object store":
return [
{ name: "name", editable: 0 },
{ name: "value", editable: 0 }
];
// Detail of indexedDB for one origin
default:
return [
{ name: "db", editable: 0 },
{ name: "origin", editable: 0 },
{ name: "version", editable: 0 },
{ name: "objectStores", editable: 0 },
];
}
})
});
var indexedDBHelpers = {

View File

@ -18,6 +18,14 @@ function createStorageSpec(options) {
options: Arg(2, "nullable:json")
},
response: RetVal(options.storeObjectType)
},
getFields: {
request: {
subType: Arg(0, "nullable:string")
},
response: {
value: RetVal("json")
}
}
};