DashboardView.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. WebInspector.DashboardView = function(element)
  26. {
  27. WebInspector.Object.call(this);
  28. this._element = element;
  29. this._items = {
  30. resourcesCount: {
  31. tooltip: WebInspector.UIString("Total number of resources, click to show the Resources navigation sidebar"),
  32. handler: this._resourcesWasClicked
  33. },
  34. resourcesSize: {
  35. tooltip: WebInspector.UIString("Total size of all resources, click to show the Network Requests timeline"),
  36. handler: this._networkItemWasClicked
  37. },
  38. time: {
  39. tooltip: WebInspector.UIString("Time until the load event fired, click to show the Network Requests timeline"),
  40. handler: this._networkItemWasClicked
  41. },
  42. logs: {
  43. tooltip: WebInspector.UIString("Console logs, click to show the Console"),
  44. handler: this._consoleItemWasClicked.bind(this, WebInspector.LogContentView.Scopes.Logs)
  45. },
  46. errors: {
  47. tooltip: WebInspector.UIString("Console errors, click to show the Console"),
  48. handler: this._consoleItemWasClicked.bind(this, WebInspector.LogContentView.Scopes.Errors)
  49. },
  50. issues: {
  51. tooltip: WebInspector.UIString("Console warnings, click to show the Console"),
  52. handler: this._consoleItemWasClicked.bind(this, WebInspector.LogContentView.Scopes.Warnings)
  53. }
  54. };
  55. for (var name in this._items)
  56. this._appendElementForNamedItem(name);
  57. this.resourcesCount = 0;
  58. this.resourcesSize = 0;
  59. this.time = 0;
  60. this.logs = 0;
  61. this.errors = 0;
  62. this.issues = 0;
  63. };
  64. WebInspector.DashboardView.EnabledStyleClassName = "enabled";
  65. WebInspector.DashboardView.prototype = {
  66. constructor: WebInspector.DashboardView,
  67. // Public
  68. get logs()
  69. {
  70. return this._logs;
  71. },
  72. set logs(logs)
  73. {
  74. this._logs = logs;
  75. var item = this._items.logs;
  76. item.text = this._formatPossibleLargeNumber(logs);
  77. this._setItemEnabled(item, logs > 0);
  78. },
  79. get issues()
  80. {
  81. return this._issues;
  82. },
  83. set issues(issues)
  84. {
  85. this._issues = issues;
  86. var item = this._items.issues;
  87. item.text = this._formatPossibleLargeNumber(issues);
  88. this._setItemEnabled(item, issues > 0);
  89. },
  90. get errors()
  91. {
  92. return this._errors;
  93. },
  94. set errors(errors)
  95. {
  96. this._errors = errors;
  97. var item = this._items.errors;
  98. item.text = this._formatPossibleLargeNumber(errors);
  99. this._setItemEnabled(item, errors > 0);
  100. },
  101. set time(time)
  102. {
  103. var item = this._items.time;
  104. item.text = time ? Number.secondsToString(time) : "\u2014";
  105. this._setItemEnabled(item, time > 0);
  106. },
  107. get resourcesCount()
  108. {
  109. return this._resourcesCount;
  110. },
  111. set resourcesCount(resourcesCount)
  112. {
  113. this._resourcesCount = resourcesCount;
  114. var item = this._items.resourcesCount;
  115. item.text = this._formatPossibleLargeNumber(resourcesCount);
  116. this._setItemEnabled(item, resourcesCount > 0);
  117. },
  118. get resourcesSize()
  119. {
  120. return this._resourcesSize;
  121. },
  122. set resourcesSize(resourcesSize)
  123. {
  124. this._resourcesSize = resourcesSize;
  125. var item = this._items.resourcesSize;
  126. item.text = resourcesSize ? Number.bytesToString(resourcesSize, false) : "\u2014";
  127. this._setItemEnabled(item, resourcesSize > 0);
  128. },
  129. // Private
  130. _formatPossibleLargeNumber: function(number)
  131. {
  132. return number > 999 ? WebInspector.UIString("999+") : number;
  133. },
  134. _appendElementForNamedItem: function(name)
  135. {
  136. var item = this._items[name];
  137. item.container = this._element.appendChild(document.createElement("div"));
  138. item.container.className = "item " + name;
  139. item.container.title = item.tooltip;
  140. item.container.appendChild(document.createElement("img"));
  141. item.outlet = item.container.appendChild(document.createElement("div"));
  142. Object.defineProperty(item, "text",
  143. {
  144. set: function(newText)
  145. {
  146. if (newText === item.outlet.textContent)
  147. return;
  148. item.outlet.textContent = newText;
  149. }
  150. });
  151. item.container.addEventListener("click", function(event) {
  152. this._itemWasClicked(name);
  153. }.bind(this));
  154. },
  155. _itemWasClicked: function(name)
  156. {
  157. var item = this._items[name];
  158. if (!item.container.classList.contains(WebInspector.DashboardView.EnabledStyleClassName))
  159. return;
  160. if (item.handler)
  161. item.handler.call(this);
  162. },
  163. _resourcesWasClicked: function()
  164. {
  165. WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.resourceSidebarPanel;
  166. WebInspector.navigationSidebar.collapsed = false;
  167. },
  168. _networkItemWasClicked: function()
  169. {
  170. WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.instrumentSidebarPanel;
  171. WebInspector.instrumentSidebarPanel.showTimelineForRecordType(WebInspector.TimelineRecord.Type.Network);
  172. },
  173. _consoleItemWasClicked: function(scope)
  174. {
  175. WebInspector.showConsoleView(scope);
  176. },
  177. _setItemEnabled: function(item, enabled)
  178. {
  179. if (enabled)
  180. item.container.classList.add(WebInspector.DashboardView.EnabledStyleClassName);
  181. else
  182. item.container.classList.remove(WebInspector.DashboardView.EnabledStyleClassName);
  183. }
  184. };
  185. WebInspector.DashboardView.prototype.__proto__ = WebInspector.Object.prototype;