2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.SortableDataGrid}
35 WebInspector
.DirectoryContentView = function()
37 const indexes
= WebInspector
.DirectoryContentView
.columnIndexes
;
39 {id
: indexes
.Name
, title
: WebInspector
.UIString("Name"), sortable
: true, sort
: WebInspector
.DataGrid
.Order
.Ascending
, width
: "20%"},
40 {id
: indexes
.URL
, title
: WebInspector
.UIString("URL"), sortable
: true, width
: "20%"},
41 {id
: indexes
.Type
, title
: WebInspector
.UIString("Type"), sortable
: true, width
: "15%"},
42 {id
: indexes
.Size
, title
: WebInspector
.UIString("Size"), sortable
: true, width
: "10%"},
43 {id
: indexes
.ModificationTime
, title
: WebInspector
.UIString("Modification Time"), sortable
: true, width
: "25%"}
46 WebInspector
.SortableDataGrid
.call(this, columns
);
47 this.addEventListener(WebInspector
.DataGrid
.Events
.SortingChanged
, this._sort
, this);
50 WebInspector
.DirectoryContentView
.columnIndexes
= {
58 WebInspector
.DirectoryContentView
.prototype = {
60 * @param {!Array.<!WebInspector.FileSystemModel.Directory>} entries
62 showEntries: function(entries
)
64 const indexes
= WebInspector
.DirectoryContentView
.columnIndexes
;
65 this.rootNode().removeChildren();
66 for (var i
= 0; i
< entries
.length
; ++i
)
67 this.rootNode().appendChild(new WebInspector
.DirectoryContentView
.Node(entries
[i
]));
72 var column
= this.sortColumnIdentifier();
75 this.sortNodes(WebInspector
.DirectoryContentView
.Node
.comparator(column
), !this.isSortOrderAscending());
78 __proto__
: WebInspector
.SortableDataGrid
.prototype
83 * @extends {WebInspector.SortableDataGridNode}
84 * @param {!WebInspector.FileSystemModel.Entry} entry
86 WebInspector
.DirectoryContentView
.Node = function(entry
)
88 const indexes
= WebInspector
.DirectoryContentView
.columnIndexes
;
90 data
[indexes
.Name
] = entry
.name
;
91 data
[indexes
.URL
] = entry
.url
;
92 data
[indexes
.Type
] = entry
.isDirectory
? WebInspector
.UIString("Directory") : entry
.mimeType
;
93 data
[indexes
.Size
] = "";
94 data
[indexes
.ModificationTime
] = "";
96 WebInspector
.SortableDataGridNode
.call(this, data
);
98 this._metadata
= null;
100 this._entry
.requestMetadata(this._metadataReceived
.bind(this));
104 * @param {string} column
105 * @return {function(!WebInspector.DataGridNode, !WebInspector.DataGridNode):number}
107 WebInspector
.DirectoryContentView
.Node
.comparator = function(column
)
109 const indexes
= WebInspector
.DirectoryContentView
.columnIndexes
;
114 return function(x
, y
)
116 return isDirectoryCompare(x
, y
) || nameCompare(x
, y
);
119 return function(x
, y
)
121 return isDirectoryCompare(x
,y
) || typeCompare(x
, y
) || nameCompare(x
, y
);
124 return function(x
, y
)
126 return isDirectoryCompare(x
, y
) || sizeCompare(x
, y
) || nameCompare(x
, y
);
128 case indexes
.ModificationTime
:
129 return function(x
, y
)
131 return isDirectoryCompare(x
, y
) || modificationTimeCompare(x
, y
) || nameCompare(x
, y
);
134 return WebInspector
.SortableDataGrid
.TrivialComparator
;
137 function isDirectoryCompare(x
, y
)
139 if (x
._entry
.isDirectory
!= y
._entry
.isDirectory
)
140 return y
._entry
.isDirectory
? 1 : -1;
144 function nameCompare(x
, y
)
146 return x
._entry
.name
.compareTo(y
._entry
.name
);
149 function typeCompare(x
, y
)
151 return (x
._entry
.mimeType
|| "").compareTo(y
._entry
.mimeType
|| "");
154 function sizeCompare(x
, y
)
156 return ((x
._metadata
? x
._metadata
.size
: 0) - (y
._metadata
? y
._metadata
.size
: 0));
159 function modificationTimeCompare(x
, y
)
161 return ((x
._metadata
? x
._metadata
.modificationTime
: 0) - (y
._metadata
? y
._metadata
.modificationTime
: 0));
165 WebInspector
.DirectoryContentView
.Node
.prototype = {
167 * @param {number} errorCode
168 * @param {!FileSystemAgent.Metadata} metadata
170 _metadataReceived: function(errorCode
, metadata
)
172 const indexes
= WebInspector
.DirectoryContentView
.columnIndexes
;
176 this._metadata
= metadata
;
177 var data
= this.data
;
178 if (this._entry
.isDirectory
)
179 data
[indexes
.Size
] = WebInspector
.UIString("-");
181 data
[indexes
.Size
] = Number
.bytesToString(metadata
.size
);
182 data
[indexes
.ModificationTime
] = new Date(metadata
.modificationTime
).toISOString();
186 __proto__
: WebInspector
.SortableDataGridNode
.prototype