diff --git a/src/css/ui-grid.cellnav.css b/src/css/ui-grid.cellnav.css new file mode 100644 index 0000000000..6c2ccdd1c4 --- /dev/null +++ b/src/css/ui-grid.cellnav.css @@ -0,0 +1,25 @@ +.ui-grid-cell-focus { + outline: 0; + background-color: #b3c4c7; +} +.ui-grid-focuser { + position: absolute; + left: 0; + top: 0; + z-index: -1; + width: 100%; + height: 100%; +} +.ui-grid-focuser:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-offscreen { + display: block; + position: absolute; + left: -10000px; + top: -10000px; + clip: rect(0px, 0px, 0px, 0px); +} diff --git a/src/css/ui-grid.cellnav.min.css b/src/css/ui-grid.cellnav.min.css new file mode 100644 index 0000000000..0d826950c6 --- /dev/null +++ b/src/css/ui-grid.cellnav.min.css @@ -0,0 +1 @@ +.ui-grid-cell-focus{outline:0;background-color:#b3c4c7}.ui-grid-focuser{position:absolute;left:0;top:0;z-index:-1;width:100%;height:100%}.ui-grid-focuser:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-offscreen{display:block;position:absolute;left:-10000px;top:-10000px;clip:rect(0, 0, 0, 0)} \ No newline at end of file diff --git a/src/css/ui-grid.core.css b/src/css/ui-grid.core.css new file mode 100644 index 0000000000..3205bcde54 --- /dev/null +++ b/src/css/ui-grid.core.css @@ -0,0 +1,865 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ +.ui-grid { + border: 1px solid #d4d4d4; + box-sizing: content-box; + -webkit-border-radius: 0px; + -moz-border-radius: 0px; + border-radius: 0px; + -webkit-transform: translateZ(0); + -moz-transform: translateZ(0); + -o-transform: translateZ(0); + -ms-transform: translateZ(0); + transform: translateZ(0); +} +.ui-grid-vertical-bar { + position: absolute; + right: 0; + width: 0; +} +.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar, +.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-scrollbar-placeholder { + background-color: transparent; +} +.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-header-cell:last-child .ui-grid-vertical-bar { + right: -1px; + width: 1px; + background-color: #d4d4d4; +} +.ui-grid-clearfix:before, +.ui-grid-clearfix:after { + content: ""; + display: table; +} +.ui-grid-clearfix:after { + clear: both; +} +.ui-grid-invisible { + visibility: hidden; +} +.ui-grid-contents-wrapper { + position: relative; + height: 100%; + width: 100%; +} +.ui-grid-sr-only { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip: rect(0, 0, 0, 0); + border: 0; +} +.ui-grid-icon-button { + background-color: transparent; + border: none; + padding: 0; +} +.clickable { + cursor: pointer; +} +.ui-grid-top-panel-background { + background-color: #f3f3f3; +} +.ui-grid-header { + border-bottom: 1px solid #d4d4d4; + box-sizing: border-box; +} +.ui-grid-top-panel { + position: relative; + overflow: hidden; + font-weight: bold; + background-color: #f3f3f3; + -webkit-border-top-right-radius: -1px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: -1px; + -moz-border-radius-topright: -1px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: -1px; + border-top-right-radius: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: -1px; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-header-viewport { + overflow: hidden; +} +.ui-grid-header-canvas:before, +.ui-grid-header-canvas:after { + content: ""; + display: -ms-flexbox; + display: flex; + line-height: 0; +} +.ui-grid-header-canvas:after { + clear: both; +} +.ui-grid-header-cell-wrapper { + position: relative; + display: -ms-flexbox; + display: flex; + box-sizing: border-box; + height: 100%; + width: 100%; +} +.ui-grid-header-cell-row { + display: -ms-flexbox; + display: flex; + -ms-flex-direction: row; + flex-direction: row; + -ms-flex-wrap: wrap; + flex-wrap: wrap; +} +.ui-grid-header-cell { + position: relative; + box-sizing: border-box; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + width: 0; +} +.ui-grid-header-cell:last-child { + border-right: 0; +} +.ui-grid-header-cell .sortable { + cursor: pointer; +} +.ui-grid-header-cell .ui-grid-sort-priority-number { + margin-left: -8px; +} +/* Fixes IE word-wrap if needed on header cells */ +.ui-grid-header-cell > div { + -ms-flex-basis: 100%; + flex-basis: 100%; +} +.ui-grid-header .ui-grid-vertical-bar { + top: 0; + bottom: 0; +} +.ui-grid-column-menu-button { + position: absolute; + right: 1px; + top: 0; +} +.ui-grid-column-menu-button .ui-grid-icon-angle-down { + vertical-align: sub; +} +.ui-grid-header-cell-last-col .ui-grid-cell-contents, +.ui-grid-header-cell-last-col .ui-grid-filter-container, +.ui-grid-header-cell-last-col .ui-grid-column-menu-button, +.ui-grid-header-cell-last-col + .ui-grid-column-resizer.right { + margin-right: 13px; +} +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-cell-contents, +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-filter-container, +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-column-menu-button, +.ui-grid-render-container-right .ui-grid-header-cell-last-col + .ui-grid-column-resizer.right { + margin-right: 28px; +} +.ui-grid-column-menu { + position: absolute; +} +/* Slide up/down animations */ +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transition: all 0.04s linear; + -moz-transition: all 0.04s linear; + -o-transition: all 0.04s linear; + transition: all 0.04s linear; + display: block !important; +} +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transform: translateY(-100%); + -moz-transform: translateY(-100%); + -o-transform: translateY(-100%); + -ms-transform: translateY(-100%); + transform: translateY(-100%); +} +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active { + -webkit-transform: translateY(0); + -moz-transform: translateY(0); + -o-transform: translateY(0); + -ms-transform: translateY(0); + transform: translateY(0); +} +/* Slide up/down animations */ +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transition: all 0.04s linear; + -moz-transition: all 0.04s linear; + -o-transition: all 0.04s linear; + transition: all 0.04s linear; + display: block !important; +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transform: translateY(-100%); + -moz-transform: translateY(-100%); + -o-transform: translateY(-100%); + -ms-transform: translateY(-100%); + transform: translateY(-100%); +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active { + -webkit-transform: translateY(0); + -moz-transform: translateY(0); + -o-transform: translateY(0); + -ms-transform: translateY(0); + transform: translateY(0); +} +.ui-grid-filter-container { + padding: 4px 10px; + position: relative; +} +.ui-grid-filter-container .ui-grid-filter-button { + position: absolute; + top: 0; + bottom: 0; + right: 0; +} +.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"] { + position: absolute; + top: 50%; + line-height: 32px; + margin-top: -16px; + right: 10px; + opacity: 0.66; +} +.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]:hover { + opacity: 1; +} +.ui-grid-filter-container .ui-grid-filter-button-select { + position: absolute; + top: 0; + bottom: 0; + right: 0; +} +.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"] { + position: absolute; + top: 50%; + line-height: 32px; + margin-top: -16px; + right: 0px; + opacity: 0.66; +} +.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]:hover { + opacity: 1; +} +input[type="text"].ui-grid-filter-input { + box-sizing: border-box; + padding: 0 18px 0 0; + margin: 0; + width: 100%; + border: 1px solid #d4d4d4; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +input[type="text"].ui-grid-filter-input:hover { + border: 1px solid #d4d4d4; +} +select.ui-grid-filter-select { + padding: 0; + margin: 0; + border: 0; + width: 90%; + border: 1px solid #d4d4d4; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +select.ui-grid-filter-select:hover { + border: 1px solid #d4d4d4; +} +.ui-grid-filter-cancel-button-hidden select.ui-grid-filter-select { + width: 100%; +} +.ui-grid-render-container { + position: inherit; + -webkit-border-top-right-radius: 0; + -webkit-border-bottom-right-radius: 0px; + -webkit-border-bottom-left-radius: 0px; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0; + -moz-border-radius-bottomright: 0px; + -moz-border-radius-bottomleft: 0px; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0; + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-render-container:focus { + outline: none; +} +.ui-grid-viewport { + min-height: 20px; + position: relative; + overflow-y: scroll; + -webkit-overflow-scrolling: touch; +} +.ui-grid-viewport:focus { + outline: none !important; +} +.ui-grid-canvas { + position: relative; + padding-top: 1px; + min-height: 1px; +} +.ui-grid-row { + clear: both; +} +.ui-grid-row:nth-child(odd) .ui-grid-cell { + background-color: #fdfdfd; +} +.ui-grid-row:nth-child(even) .ui-grid-cell { + background-color: #f3f3f3; +} +.ui-grid-row:last-child .ui-grid-cell { + border-bottom-color: #d4d4d4; + border-bottom-style: solid; +} +.ui-grid-row:hover > [ui-grid-row] > .ui-grid-cell:hover .ui-grid-cell, +.ui-grid-row:nth-child(odd):hover .ui-grid-cell, +.ui-grid-row:nth-child(even):hover .ui-grid-cell { + background-color: #d5eaee; +} +.ui-grid-no-row-overlay { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + margin: 10%; + background-color: #f3f3f3; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; + border: 1px solid #d4d4d4; + font-size: 2em; + text-align: center; +} +.ui-grid-no-row-overlay > * { + position: absolute; + display: table; + margin: auto 0; + width: 100%; + top: 0; + bottom: 0; + left: 0; + right: 0; + opacity: 0.66; +} +.ui-grid-cell { + overflow: hidden; + float: left; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + box-sizing: border-box; +} +.ui-grid-cell:last-child { + border-right: 0; +} +.ui-grid-cell-contents { + padding: 5px; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + white-space: nowrap; + -ms-text-overflow: ellipsis; + -o-text-overflow: ellipsis; + text-overflow: ellipsis; + overflow: hidden; + height: 100%; +} +.ui-grid-cell-contents-hidden { + visibility: hidden; + width: 0; + height: 0; + display: none; +} +.ui-grid-row .ui-grid-cell.ui-grid-row-header-cell { + background-color: #F0F0EE; + border-bottom: solid 1px #d4d4d4; +} +.ui-grid-cell-empty { + display: inline-block; + width: 10px; + height: 10px; +} +.ui-grid-footer-info { + padding: 5px 10px; +} +.ui-grid-footer-panel-background { + background-color: #f3f3f3; +} +.ui-grid-footer-panel { + position: relative; + border-bottom: 1px solid #d4d4d4; + border-top: 1px solid #d4d4d4; + overflow: hidden; + font-weight: bold; + background-color: #f3f3f3; + -webkit-border-top-right-radius: -1px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: -1px; + -moz-border-radius-topright: -1px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: -1px; + border-top-right-radius: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: -1px; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-grid-footer { + float: left; + width: 100%; +} +.ui-grid-footer-viewport, +.ui-grid-footer-canvas { + height: 100%; +} +.ui-grid-footer-viewport { + overflow: hidden; +} +.ui-grid-footer-canvas { + position: relative; +} +.ui-grid-footer-canvas:before, +.ui-grid-footer-canvas:after { + content: ""; + display: table; + line-height: 0; +} +.ui-grid-footer-canvas:after { + clear: both; +} +.ui-grid-footer-cell-wrapper { + position: relative; + display: table; + box-sizing: border-box; + height: 100%; +} +.ui-grid-footer-cell-row { + display: table-row; +} +.ui-grid-footer-cell { + overflow: hidden; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + box-sizing: border-box; + display: table-cell; +} +.ui-grid-footer-cell:last-child { + border-right: 0; +} +.ui-grid-menu-button { + z-index: 2; + position: absolute; + right: 0; + top: 0; + background: #f3f3f3; + border: 0; + border-left: 1px solid #d4d4d4; + border-bottom: 1px solid #d4d4d4; + cursor: pointer; + height: 32px; + font-weight: normal; +} +.ui-grid-menu-button .ui-grid-icon-container { + margin-top: 5px; + margin-left: 2px; +} +.ui-grid-menu-button .ui-grid-menu { + right: 0; +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid { + overflow: scroll; +} +.ui-grid-menu { + overflow: hidden; + max-width: 320px; + z-index: 2; + position: absolute; + right: 100%; + padding: 0 10px 20px 10px; + cursor: pointer; + box-sizing: border-box; +} +.ui-grid-menu-item { + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.ui-grid-menu .ui-grid-menu-inner { + background: #fff; + border: 1px solid #d4d4d4; + position: relative; + white-space: nowrap; + -webkit-border-radius: 0px; + -moz-border-radius: 0px; + border-radius: 0px; +} +.ui-grid-menu .ui-grid-menu-inner ul { + margin: 0; + padding: 0; + list-style-type: none; +} +.ui-grid-menu .ui-grid-menu-inner ul li { + padding: 0; +} +.ui-grid-menu .ui-grid-menu-inner ul li .ui-grid-menu-item { + color: #000; + min-width: 100%; + padding: 8px; + text-align: left; + background: transparent; + border: none; + cursor: default; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item { + cursor: pointer; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:hover, +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:focus { + background-color: #b3c4c7; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item.ui-grid-menu-item-active { + background-color: #9cb2b6; +} +.ui-grid-menu .ui-grid-menu-inner ul li:not(:last-child) > .ui-grid-menu-item { + border-bottom: 1px solid #d4d4d4; +} +.ui-grid-sortarrow { + right: 5px; + position: absolute; + width: 20px; + top: 0; + bottom: 0; + background-position: center; +} +.ui-grid-sortarrow.down { + -webkit-transform: rotate(180deg); + -moz-transform: rotate(180deg); + -o-transform: rotate(180deg); + -ms-transform: rotate(180deg); + transform: rotate(180deg); +} +@font-face { + font-family: 'ui-grid'; + src: url('../fonts/ui-grid.eot'); + src: url('../fonts/ui-grid.eot#iefix') format('embedded-opentype'), url('../fonts/ui-grid.woff') format('woff'), url('../fonts/ui-grid.ttf') format('truetype'), url('../fonts/ui-grid.svg?#ui-grid') format('svg'); + font-weight: normal; + font-style: normal; +} +/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */ +/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */ +/* +@media screen and (-webkit-min-device-pixel-ratio:0) { + @font-face { + font-family: 'ui-grid'; + src: url('@{font-path}ui-grid.svg?12312827#ui-grid') format('svg'); + } +} +*/ +[class^="ui-grid-icon"]:before, +[class*=" ui-grid-icon"]:before { + font-family: "ui-grid"; + font-style: normal; + font-weight: normal; + speak: none; + display: inline-block; + text-decoration: inherit; + width: 1em; + margin-right: 0.2em; + text-align: center; + /* opacity: .8; */ + /* For safety - reset parent styles, that can break glyph codes*/ + font-variant: normal; + text-transform: none; + /* fix buttons height, for twitter bootstrap */ + line-height: 1em; + /* Animation center compensation - margins should be symmetric */ + /* remove if not needed */ + margin-left: 0.2em; + /* you can be more comfortable with increased icons size */ + /* font-size: 120%; */ + /* Uncomment for 3D effect */ + /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */ +} +.ui-grid-icon-blank::before { + width: 1em; + content: ' '; +} +.ui-grid-icon-plus-squared:before { + content: '\c350'; +} +.ui-grid-icon-minus-squared:before { + content: '\c351'; +} +.ui-grid-icon-search:before { + content: '\c352'; +} +.ui-grid-icon-cancel:before { + content: '\c353'; +} +.ui-grid-icon-info-circled:before { + content: '\c354'; +} +.ui-grid-icon-lock:before { + content: '\c355'; +} +.ui-grid-icon-lock-open:before { + content: '\c356'; +} +.ui-grid-icon-pencil:before { + content: '\c357'; +} +.ui-grid-icon-down-dir:before { + content: '\c358'; +} +.ui-grid-icon-up-dir:before { + content: '\c359'; +} +.ui-grid-icon-left-dir:before { + content: '\c35a'; +} +.ui-grid-icon-right-dir:before { + content: '\c35b'; +} +.ui-grid-icon-left-open:before { + content: '\c35c'; +} +.ui-grid-icon-right-open:before { + content: '\c35d'; +} +.ui-grid-icon-angle-down:before { + content: '\c35e'; +} +.ui-grid-icon-filter:before { + content: '\c35f'; +} +.ui-grid-icon-sort-alt-up:before { + content: '\c360'; +} +.ui-grid-icon-sort-alt-down:before { + content: '\c361'; +} +.ui-grid-icon-ok:before { + content: '\c362'; +} +.ui-grid-icon-menu:before { + content: '\c363'; +} +.ui-grid-icon-indent-left:before { + content: '\e800'; +} +.ui-grid-icon-indent-right:before { + content: '\e801'; +} +.ui-grid-icon-spin5:before { + content: '\ea61'; +} +/* +* RTL Styles +*/ +.ui-grid[dir=rtl] .ui-grid-header-cell, +.ui-grid[dir=rtl] .ui-grid-footer-cell, +.ui-grid[dir=rtl] .ui-grid-cell { + float: right !important; +} +.ui-grid[dir=rtl] .ui-grid-column-menu-button { + position: absolute; + left: 1px; + top: 0; + right: inherit; +} +.ui-grid[dir=rtl] .ui-grid-cell:first-child, +.ui-grid[dir=rtl] .ui-grid-header-cell:first-child, +.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child { + border-right: 0; +} +.ui-grid[dir=rtl] .ui-grid-cell:last-child, +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child { + border-right: 1px solid #d4d4d4; + border-left: 0; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:first-child .ui-grid-vertical-bar, +.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child .ui-grid-vertical-bar, +.ui-grid[dir=rtl] .ui-grid-cell:first-child .ui-grid-vertical-bar { + width: 0; +} +.ui-grid[dir=rtl] .ui-grid-menu-button { + z-index: 2; + position: absolute; + left: 0; + right: auto; + background: #f3f3f3; + border: 1px solid #d4d4d4; + cursor: pointer; + min-height: 27px; + font-weight: normal; +} +.ui-grid[dir=rtl] .ui-grid-menu-button .ui-grid-menu { + left: 0; + right: auto; +} +.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button { + right: initial; + left: 0; +} +.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"] { + right: initial; + left: 10px; +} +/* + Animation example, for spinners +*/ +.ui-grid-animate-spin { + -moz-animation: ui-grid-spin 2s infinite linear; + -o-animation: ui-grid-spin 2s infinite linear; + -webkit-animation: ui-grid-spin 2s infinite linear; + animation: ui-grid-spin 2s infinite linear; + display: inline-block; +} +@-moz-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-webkit-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-o-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-ms-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} diff --git a/src/css/ui-grid.core.min.css b/src/css/ui-grid.core.min.css new file mode 100644 index 0000000000..a5cde24597 --- /dev/null +++ b/src/css/ui-grid.core.min.css @@ -0,0 +1,4 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */.ui-grid{border:1px solid #d4d4d4;box-sizing:content-box;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-transform:translateZ(0);-moz-transform:translateZ(0);-o-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0)}.ui-grid-vertical-bar{position:absolute;right:0;width:0}.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar,.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{width:1px}.ui-grid-scrollbar-placeholder{background-color:transparent}.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-header-cell:last-child .ui-grid-vertical-bar{right:-1px;width:1px;background-color:#d4d4d4}.ui-grid-clearfix:before,.ui-grid-clearfix:after{content:"";display:table}.ui-grid-clearfix:after{clear:both}.ui-grid-invisible{visibility:hidden}.ui-grid-contents-wrapper{position:relative;height:100%;width:100%}.ui-grid-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0, 0, 0, 0);border:0}.ui-grid-icon-button{background-color:transparent;border:none;padding:0}.clickable{cursor:pointer}.ui-grid-top-panel-background{background-color:#f3f3f3}.ui-grid-header{border-bottom:1px solid #d4d4d4;box-sizing:border-box}.ui-grid-top-panel{position:relative;overflow:hidden;font-weight:bold;background-color:#f3f3f3;-webkit-border-top-right-radius:-1px;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:-1px;-moz-border-radius-topright:-1px;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:-1px;border-top-right-radius:-1px;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:-1px;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-header-viewport{overflow:hidden}.ui-grid-header-canvas:before,.ui-grid-header-canvas:after{content:"";display:-ms-flexbox;display:flex;line-height:0}.ui-grid-header-canvas:after{clear:both}.ui-grid-header-cell-wrapper{position:relative;display:-ms-flexbox;display:flex;box-sizing:border-box;height:100%;width:100%}.ui-grid-header-cell-row{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap}.ui-grid-header-cell{position:relative;box-sizing:border-box;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:0}.ui-grid-header-cell:last-child{border-right:0}.ui-grid-header-cell .sortable{cursor:pointer}.ui-grid-header-cell .ui-grid-sort-priority-number{margin-left:-8px}.ui-grid-header-cell>div{-ms-flex-basis:100%;flex-basis:100%}.ui-grid-header .ui-grid-vertical-bar{top:0;bottom:0}.ui-grid-column-menu-button{position:absolute;right:1px;top:0}.ui-grid-column-menu-button .ui-grid-icon-angle-down{vertical-align:sub}.ui-grid-header-cell-last-col .ui-grid-cell-contents,.ui-grid-header-cell-last-col .ui-grid-filter-container,.ui-grid-header-cell-last-col .ui-grid-column-menu-button,.ui-grid-header-cell-last-col+.ui-grid-column-resizer.right{margin-right:13px}.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-cell-contents,.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-filter-container,.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-column-menu-button,.ui-grid-render-container-right .ui-grid-header-cell-last-col+.ui-grid-column-resizer.right{margin-right:28px}.ui-grid-column-menu{position:absolute}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transition:all .04s linear;-moz-transition:all .04s linear;-o-transition:all .04s linear;transition:all .04s linear;display:block !important}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transform:translateY(-100%);-moz-transform:translateY(-100%);-o-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active{-webkit-transform:translateY(0);-moz-transform:translateY(0);-o-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0)}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transition:all .04s linear;-moz-transition:all .04s linear;-o-transition:all .04s linear;transition:all .04s linear;display:block !important}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transform:translateY(-100%);-moz-transform:translateY(-100%);-o-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active{-webkit-transform:translateY(0);-moz-transform:translateY(0);-o-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0)}.ui-grid-filter-container{padding:4px 10px;position:relative}.ui-grid-filter-container .ui-grid-filter-button{position:absolute;top:0;bottom:0;right:0}.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]{position:absolute;top:50%;line-height:32px;margin-top:-16px;right:10px;opacity:.66}.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]:hover{opacity:1}.ui-grid-filter-container .ui-grid-filter-button-select{position:absolute;top:0;bottom:0;right:0}.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]{position:absolute;top:50%;line-height:32px;margin-top:-16px;right:0px;opacity:.66}.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]:hover{opacity:1}input[type="text"].ui-grid-filter-input{box-sizing:border-box;padding:0 18px 0 0;margin:0;width:100%;border:1px solid #d4d4d4;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}input[type="text"].ui-grid-filter-input:hover{border:1px solid #d4d4d4}select.ui-grid-filter-select{padding:0;margin:0;border:0;width:90%;border:1px solid #d4d4d4;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}select.ui-grid-filter-select:hover{border:1px solid #d4d4d4}.ui-grid-filter-cancel-button-hidden select.ui-grid-filter-select{width:100%}.ui-grid-render-container{position:inherit;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-render-container:focus{outline:none}.ui-grid-viewport{min-height:20px;position:relative;overflow-y:scroll;-webkit-overflow-scrolling:touch}.ui-grid-viewport:focus{outline:none !important}.ui-grid-canvas{position:relative;padding-top:1px;min-height:1px}.ui-grid-row{clear:both}.ui-grid-row:nth-child(odd) .ui-grid-cell{background-color:#fdfdfd}.ui-grid-row:nth-child(even) .ui-grid-cell{background-color:#f3f3f3}.ui-grid-row:last-child .ui-grid-cell{border-bottom-color:#d4d4d4;border-bottom-style:solid}.ui-grid-row:hover>[ui-grid-row]>.ui-grid-cell:hover .ui-grid-cell,.ui-grid-row:nth-child(odd):hover .ui-grid-cell,.ui-grid-row:nth-child(even):hover .ui-grid-cell{background-color:#d5eaee}.ui-grid-no-row-overlay{position:absolute;top:0;bottom:0;left:0;right:0;margin:10%;background-color:#f3f3f3;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #d4d4d4;font-size:2em;text-align:center}.ui-grid-no-row-overlay>*{position:absolute;display:table;margin:auto 0;width:100%;top:0;bottom:0;left:0;right:0;opacity:.66}.ui-grid-cell{overflow:hidden;float:left;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;box-sizing:border-box}.ui-grid-cell:last-child{border-right:0}.ui-grid-cell-contents{padding:5px;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;white-space:nowrap;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;overflow:hidden;height:100%}.ui-grid-cell-contents-hidden{visibility:hidden;width:0;height:0;display:none}.ui-grid-row .ui-grid-cell.ui-grid-row-header-cell{background-color:#F0F0EE;border-bottom:solid 1px #d4d4d4}.ui-grid-cell-empty{display:inline-block;width:10px;height:10px}.ui-grid-footer-info{padding:5px 10px}.ui-grid-footer-panel-background{background-color:#f3f3f3}.ui-grid-footer-panel{position:relative;border-bottom:1px solid #d4d4d4;border-top:1px solid #d4d4d4;overflow:hidden;font-weight:bold;background-color:#f3f3f3;-webkit-border-top-right-radius:-1px;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:-1px;-moz-border-radius-topright:-1px;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:-1px;border-top-right-radius:-1px;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:-1px;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-grid-footer{float:left;width:100%}.ui-grid-footer-viewport,.ui-grid-footer-canvas{height:100%}.ui-grid-footer-viewport{overflow:hidden}.ui-grid-footer-canvas{position:relative}.ui-grid-footer-canvas:before,.ui-grid-footer-canvas:after{content:"";display:table;line-height:0}.ui-grid-footer-canvas:after{clear:both}.ui-grid-footer-cell-wrapper{position:relative;display:table;box-sizing:border-box;height:100%}.ui-grid-footer-cell-row{display:table-row}.ui-grid-footer-cell{overflow:hidden;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;box-sizing:border-box;display:table-cell}.ui-grid-footer-cell:last-child{border-right:0}.ui-grid-menu-button{z-index:2;position:absolute;right:0;top:0;background:#f3f3f3;border:0;border-left:1px solid #d4d4d4;border-bottom:1px solid #d4d4d4;cursor:pointer;height:32px;font-weight:normal}.ui-grid-menu-button .ui-grid-icon-container{margin-top:5px;margin-left:2px}.ui-grid-menu-button .ui-grid-menu{right:0}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid{overflow:scroll}.ui-grid-menu{overflow:hidden;max-width:320px;z-index:2;position:absolute;right:100%;padding:0 10px 20px 10px;cursor:pointer;box-sizing:border-box}.ui-grid-menu-item{width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-grid-menu .ui-grid-menu-inner{background:#fff;border:1px solid #d4d4d4;position:relative;white-space:nowrap;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.ui-grid-menu .ui-grid-menu-inner ul{margin:0;padding:0;list-style-type:none}.ui-grid-menu .ui-grid-menu-inner ul li{padding:0}.ui-grid-menu .ui-grid-menu-inner ul li .ui-grid-menu-item{color:#000;min-width:100%;padding:8px;text-align:left;background:transparent;border:none;cursor:default}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item{cursor:pointer}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:hover,.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:focus{background-color:#b3c4c7}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item.ui-grid-menu-item-active{background-color:#9cb2b6}.ui-grid-menu .ui-grid-menu-inner ul li:not(:last-child)>.ui-grid-menu-item{border-bottom:1px solid #d4d4d4}.ui-grid-sortarrow{right:5px;position:absolute;width:20px;top:0;bottom:0;background-position:center}.ui-grid-sortarrow.down{-webkit-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}@font-face{font-family:'ui-grid';src:url('../fonts/ui-grid.eot');src:url('../fonts/ui-grid.eot#iefix') format('embedded-opentype'),url('../fonts/ui-grid.woff') format('woff'),url('../fonts/ui-grid.ttf') format('truetype'),url('../fonts/ui-grid.svg?#ui-grid') format('svg');font-weight:normal;font-style:normal}[class^="ui-grid-icon"]:before,[class*=" ui-grid-icon"]:before{font-family:"ui-grid";font-style:normal;font-weight:normal;speak:none;display:inline-block;text-decoration:inherit;width:1em;margin-right:.2em;text-align:center;font-variant:normal;text-transform:none;line-height:1em;margin-left:.2em}.ui-grid-icon-blank::before{width:1em;content:' '}.ui-grid-icon-plus-squared:before{content:'\c350'}.ui-grid-icon-minus-squared:before{content:'\c351'}.ui-grid-icon-search:before{content:'\c352'}.ui-grid-icon-cancel:before{content:'\c353'}.ui-grid-icon-info-circled:before{content:'\c354'}.ui-grid-icon-lock:before{content:'\c355'}.ui-grid-icon-lock-open:before{content:'\c356'}.ui-grid-icon-pencil:before{content:'\c357'}.ui-grid-icon-down-dir:before{content:'\c358'}.ui-grid-icon-up-dir:before{content:'\c359'}.ui-grid-icon-left-dir:before{content:'\c35a'}.ui-grid-icon-right-dir:before{content:'\c35b'}.ui-grid-icon-left-open:before{content:'\c35c'}.ui-grid-icon-right-open:before{content:'\c35d'}.ui-grid-icon-angle-down:before{content:'\c35e'}.ui-grid-icon-filter:before{content:'\c35f'}.ui-grid-icon-sort-alt-up:before{content:'\c360'}.ui-grid-icon-sort-alt-down:before{content:'\c361'}.ui-grid-icon-ok:before{content:'\c362'}.ui-grid-icon-menu:before{content:'\c363'}.ui-grid-icon-indent-left:before{content:'\e800'}.ui-grid-icon-indent-right:before{content:'\e801'}.ui-grid-icon-spin5:before{content:'\ea61'}.ui-grid[dir=rtl] .ui-grid-header-cell,.ui-grid[dir=rtl] .ui-grid-footer-cell,.ui-grid[dir=rtl] .ui-grid-cell{float:right !important}.ui-grid[dir=rtl] .ui-grid-column-menu-button{position:absolute;left:1px;top:0;right:inherit}.ui-grid[dir=rtl] .ui-grid-cell:first-child,.ui-grid[dir=rtl] .ui-grid-header-cell:first-child,.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child{border-right:0}.ui-grid[dir=rtl] .ui-grid-cell:last-child,.ui-grid[dir=rtl] .ui-grid-header-cell:last-child{border-right:1px solid #d4d4d4;border-left:0}.ui-grid[dir=rtl] .ui-grid-header-cell:first-child .ui-grid-vertical-bar,.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child .ui-grid-vertical-bar,.ui-grid[dir=rtl] .ui-grid-cell:first-child .ui-grid-vertical-bar{width:0}.ui-grid[dir=rtl] .ui-grid-menu-button{z-index:2;position:absolute;left:0;right:auto;background:#f3f3f3;border:1px solid #d4d4d4;cursor:pointer;min-height:27px;font-weight:normal}.ui-grid[dir=rtl] .ui-grid-menu-button .ui-grid-menu{left:0;right:auto}.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button{right:initial;left:0}.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]{right:initial;left:10px}.ui-grid-animate-spin{-moz-animation:ui-grid-spin 2s infinite linear;-o-animation:ui-grid-spin 2s infinite linear;-webkit-animation:ui-grid-spin 2s infinite linear;animation:ui-grid-spin 2s infinite linear;display:inline-block}@-moz-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-webkit-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-o-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-ms-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}} \ No newline at end of file diff --git a/src/css/ui-grid.edit.css b/src/css/ui-grid.edit.css new file mode 100644 index 0000000000..be3d1461c4 --- /dev/null +++ b/src/css/ui-grid.edit.css @@ -0,0 +1,23 @@ +.ui-grid-cell input { + border-radius: inherit; + padding: 0; + width: 100%; + color: inherit; + height: auto; + font: inherit; + outline: none; +} +.ui-grid-cell input:focus { + color: inherit; + outline: none; +} +.ui-grid-cell input[type="checkbox"] { + margin: 9px 0 0 6px; + width: auto; +} +.ui-grid-cell input.ng-invalid { + border: 1px solid #fc8f8f; +} +.ui-grid-cell input.ng-valid { + border: 1px solid #d4d4d4; +} diff --git a/src/css/ui-grid.edit.min.css b/src/css/ui-grid.edit.min.css new file mode 100644 index 0000000000..64ea11477a --- /dev/null +++ b/src/css/ui-grid.edit.min.css @@ -0,0 +1 @@ +.ui-grid-cell input{border-radius:inherit;padding:0;width:100%;color:inherit;height:auto;font:inherit;outline:none}.ui-grid-cell input:focus{color:inherit;outline:none}.ui-grid-cell input[type="checkbox"]{margin:9px 0 0 6px;width:auto}.ui-grid-cell input.ng-invalid{border:1px solid #fc8f8f}.ui-grid-cell input.ng-valid{border:1px solid #d4d4d4} \ No newline at end of file diff --git a/src/css/ui-grid.empty-base-layer.css b/src/css/ui-grid.empty-base-layer.css new file mode 100644 index 0000000000..0bb8c09ae1 --- /dev/null +++ b/src/css/ui-grid.empty-base-layer.css @@ -0,0 +1,6 @@ +.ui-grid-viewport .ui-grid-empty-base-layer-container { + position: absolute; + overflow: hidden; + pointer-events: none; + z-index: -1; +} diff --git a/src/css/ui-grid.empty-base-layer.min.css b/src/css/ui-grid.empty-base-layer.min.css new file mode 100644 index 0000000000..f89c68ac33 --- /dev/null +++ b/src/css/ui-grid.empty-base-layer.min.css @@ -0,0 +1 @@ +.ui-grid-viewport .ui-grid-empty-base-layer-container{position:absolute;overflow:hidden;pointer-events:none;z-index:-1} \ No newline at end of file diff --git a/src/css/ui-grid.expandable.css b/src/css/ui-grid.expandable.css new file mode 100644 index 0000000000..5413490490 --- /dev/null +++ b/src/css/ui-grid.expandable.css @@ -0,0 +1,16 @@ +.expandableRow .ui-grid-row:nth-child(odd) .ui-grid-cell { + background-color: #fdfdfd; +} +.expandableRow .ui-grid-row:nth-child(even) .ui-grid-cell { + background-color: #f3f3f3; +} +.ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell { + pointer-events: none; +} +.ui-grid-expandable-buttons-cell i { + pointer-events: all; +} +.scrollFiller { + float: left; + border: 1px solid #d4d4d4; +} diff --git a/src/css/ui-grid.expandable.min.css b/src/css/ui-grid.expandable.min.css new file mode 100644 index 0000000000..2c133841a1 --- /dev/null +++ b/src/css/ui-grid.expandable.min.css @@ -0,0 +1 @@ +.expandableRow .ui-grid-row:nth-child(odd) .ui-grid-cell{background-color:#fdfdfd}.expandableRow .ui-grid-row:nth-child(even) .ui-grid-cell{background-color:#f3f3f3}.ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell{pointer-events:none}.ui-grid-expandable-buttons-cell i{pointer-events:all}.scrollFiller{float:left;border:1px solid #d4d4d4} \ No newline at end of file diff --git a/src/css/ui-grid.exporter.css b/src/css/ui-grid.exporter.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/css/ui-grid.exporter.min.css b/src/css/ui-grid.exporter.min.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/css/ui-grid.grouping.css b/src/css/ui-grid.grouping.css new file mode 100644 index 0000000000..e0ba6cd1e0 --- /dev/null +++ b/src/css/ui-grid.grouping.css @@ -0,0 +1,3 @@ +.ui-grid-tree-header-row { + font-weight: bold !important; +} diff --git a/src/css/ui-grid.grouping.min.css b/src/css/ui-grid.grouping.min.css new file mode 100644 index 0000000000..599cde6669 --- /dev/null +++ b/src/css/ui-grid.grouping.min.css @@ -0,0 +1 @@ +.ui-grid-tree-header-row{font-weight:bold !important} \ No newline at end of file diff --git a/src/css/ui-grid.importer.css b/src/css/ui-grid.importer.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/css/ui-grid.importer.min.css b/src/css/ui-grid.importer.min.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/css/ui-grid.move-columns.css b/src/css/ui-grid.move-columns.css new file mode 100644 index 0000000000..2c8fa80dc4 --- /dev/null +++ b/src/css/ui-grid.move-columns.css @@ -0,0 +1,9 @@ +.movingColumn { + position: absolute; + top: 0; + border: 1px solid #d4d4d4; + box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.2); +} +.movingColumn .ui-grid-icon-angle-down { + display: none; +} diff --git a/src/css/ui-grid.move-columns.min.css b/src/css/ui-grid.move-columns.min.css new file mode 100644 index 0000000000..064caf5e51 --- /dev/null +++ b/src/css/ui-grid.move-columns.min.css @@ -0,0 +1 @@ +.movingColumn{position:absolute;top:0;border:1px solid #d4d4d4;box-shadow:inset 0 0 14px rgba(0,0,0,0.2)}.movingColumn .ui-grid-icon-angle-down{display:none} \ No newline at end of file diff --git a/src/css/ui-grid.pagination.css b/src/css/ui-grid.pagination.css new file mode 100644 index 0000000000..9799fa37ea --- /dev/null +++ b/src/css/ui-grid.pagination.css @@ -0,0 +1,299 @@ +/* This file contains variable declarations (do not remove this line) */ +/*-- VARIABLES (DO NOT REMOVE THESE COMMENTS) --*/ +/** +* @section Grid styles +*/ +/** +* @section Header styles +*/ +/** @description Colors for header gradient */ +/** +* @section Grid body styles +*/ +/** @description Colors used for row alternation */ +/** +* @section Grid Menu colors +*/ +/** +* @section Sort arrow colors +*/ +/** +* @section Scrollbar styles +*/ +/** +* @section font library path +*/ +/*-- END VARIABLES (DO NOT REMOVE THESE COMMENTS) --*/ +/*--------------------------------------------------- + LESS Elements 0.9 + --------------------------------------------------- + A set of useful LESS mixins + More info at: http://lesselements.com + ---------------------------------------------------*/ +.ui-grid-pager-panel { + display: flex; + justify-content: space-between; + align-items: center; + position: absolute; + left: 0; + bottom: 0; + width: 100%; + padding-top: 3px; + padding-bottom: 3px; + box-sizing: content-box; +} +.ui-grid-pager-container { + float: left; +} +.ui-grid-pager-control { + padding: 5px 0; + display: flex; + flex-flow: row nowrap; + align-items: center; + margin-right: 10px; + margin-left: 10px; + min-width: 135px; + float: left; +} +.ui-grid-pager-control button, +.ui-grid-pager-control span, +.ui-grid-pager-control input { + margin-right: 4px; +} +.ui-grid-pager-control button { + height: 25px; + min-width: 26px; + display: inline-block; + margin-bottom: 0; + font-weight: normal; + text-align: center; + vertical-align: middle; + touch-action: manipulation; + cursor: pointer; + background: #f3f3f3; + border: 1px solid #ccc; + white-space: nowrap; + padding: 6px 12px; + font-size: 14px; + line-height: 1.42857143; + border-radius: 4px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + color: #eee; +} +.ui-grid-pager-control button:hover { + border-color: #adadad; + text-decoration: none; +} +.ui-grid-pager-control button:focus { + border-color: #8c8c8c; + text-decoration: none; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; +} +.ui-grid-pager-control button:active { + border-color: #adadad; + outline: 0; + -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); + box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); +} +.ui-grid-pager-control button:active:focus { + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; +} +.ui-grid-pager-control button:active:hover, +.ui-grid-pager-control button:active:focus { + background-color: #c8c8c8; + border-color: #8c8c8c; +} +.ui-grid-pager-control button:hover, +.ui-grid-pager-control button:focus, +.ui-grid-pager-control button:active { + color: #eee; + background: #dadada; +} +.ui-grid-pager-control button[disabled] { + cursor: not-allowed; + opacity: 0.65; + filter: alpha(opacity=65); + -webkit-box-shadow: none; + box-shadow: none; +} +.ui-grid-pager-control button[disabled]:hover, +.ui-grid-pager-control button[disabled]:focus { + background-color: #f3f3f3; + border-color: #ccc; +} +.ui-grid-pager-control input { + display: inline; + height: 26px; + width: 50px; + vertical-align: top; + color: #555555; + background: #fff; + border: 1px solid #ccc; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + -o-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + padding: 5px 10px; + font-size: 12px; + line-height: 1.5; + border-radius: 3px; +} +.ui-grid-pager-control input:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-pager-control input[disabled], +.ui-grid-pager-control input[readonly], +.ui-grid-pager-control input::-moz-placeholder { + opacity: 1; +} +.ui-grid-pager-control input::-moz-placeholder, +.ui-grid-pager-control input:-ms-input-placeholder, +.ui-grid-pager-control input::-webkit-input-placeholder { + color: #999; +} +.ui-grid-pager-control input::-ms-expand { + border: 0; + background-color: transparent; +} +.ui-grid-pager-control input[disabled], +.ui-grid-pager-control input[readonly] { + background-color: #eeeeee; +} +.ui-grid-pager-control input[disabled] { + cursor: not-allowed; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number { + vertical-align: bottom; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number > * { + vertical-align: bottom; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number abbr { + border-bottom: none; + text-decoration: none; +} +.ui-grid-pager-control .first-bar { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-left: -3px; +} +.ui-grid-pager-control .first-bar-rtl { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-right: -7px; +} +.ui-grid-pager-control .first-triangle { + width: 0; + height: 0; + border-style: solid; + border-width: 5px 8.7px 5px 0; + border-color: transparent #4d4d4d transparent transparent; + margin-left: 2px; +} +.ui-grid-pager-control .next-triangle { + margin-left: 1px; +} +.ui-grid-pager-control .prev-triangle { + margin-left: 0; +} +.ui-grid-pager-control .last-triangle { + width: 0; + height: 0; + border-style: solid; + border-width: 5px 0 5px 8.7px; + border-color: transparent transparent transparent #4d4d4d; + margin-left: -1px; +} +.ui-grid-pager-control .last-bar { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-left: 1px; +} +.ui-grid-pager-control .last-bar-rtl { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-right: -11px; +} +.ui-grid-pager-row-count-picker { + float: left; + padding: 5px 10px; +} +.ui-grid-pager-row-count-picker select { + color: #555555; + background: #fff; + border: 1px solid #ccc; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + -o-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + padding: 5px 10px; + font-size: 12px; + line-height: 1.5; + border-radius: 3px; + height: 25px; + width: 67px; + display: inline; + vertical-align: middle; +} +.ui-grid-pager-row-count-picker select:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-pager-row-count-picker select[disabled], +.ui-grid-pager-row-count-picker select[readonly], +.ui-grid-pager-row-count-picker select::-moz-placeholder { + opacity: 1; +} +.ui-grid-pager-row-count-picker select::-moz-placeholder, +.ui-grid-pager-row-count-picker select:-ms-input-placeholder, +.ui-grid-pager-row-count-picker select::-webkit-input-placeholder { + color: #999; +} +.ui-grid-pager-row-count-picker select::-ms-expand { + border: 0; + background-color: transparent; +} +.ui-grid-pager-row-count-picker select[disabled], +.ui-grid-pager-row-count-picker select[readonly] { + background-color: #eeeeee; +} +.ui-grid-pager-row-count-picker select[disabled] { + cursor: not-allowed; +} +.ui-grid-pager-row-count-picker .ui-grid-pager-row-count-label { + margin-top: 3px; +} +.ui-grid-pager-count-container { + float: right; + margin-top: 4px; + min-width: 50px; +} +.ui-grid-pager-count-container .ui-grid-pager-count { + margin-right: 10px; + margin-left: 10px; + float: right; +} +.ui-grid-pager-count-container .ui-grid-pager-count abbr { + border-bottom: none; + text-decoration: none; +} diff --git a/src/css/ui-grid.pagination.min.css b/src/css/ui-grid.pagination.min.css new file mode 100644 index 0000000000..395aec9880 --- /dev/null +++ b/src/css/ui-grid.pagination.min.css @@ -0,0 +1 @@ +.ui-grid-pager-panel{display:flex;justify-content:space-between;align-items:center;position:absolute;left:0;bottom:0;width:100%;padding-top:3px;padding-bottom:3px;box-sizing:content-box}.ui-grid-pager-container{float:left}.ui-grid-pager-control{padding:5px 0;display:flex;flex-flow:row nowrap;align-items:center;margin-right:10px;margin-left:10px;min-width:135px;float:left}.ui-grid-pager-control button,.ui-grid-pager-control span,.ui-grid-pager-control input{margin-right:4px}.ui-grid-pager-control button{height:25px;min-width:26px;display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;touch-action:manipulation;cursor:pointer;background:#f3f3f3;border:1px solid #ccc;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#eee}.ui-grid-pager-control button:hover{border-color:#adadad;text-decoration:none}.ui-grid-pager-control button:focus{border-color:#8c8c8c;text-decoration:none;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.ui-grid-pager-control button:active{border-color:#adadad;outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.ui-grid-pager-control button:active:focus{outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.ui-grid-pager-control button:active:hover,.ui-grid-pager-control button:active:focus{background-color:#c8c8c8;border-color:#8c8c8c}.ui-grid-pager-control button:hover,.ui-grid-pager-control button:focus,.ui-grid-pager-control button:active{color:#eee;background:#dadada}.ui-grid-pager-control button[disabled]{cursor:not-allowed;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none}.ui-grid-pager-control button[disabled]:hover,.ui-grid-pager-control button[disabled]:focus{background-color:#f3f3f3;border-color:#ccc}.ui-grid-pager-control input{display:inline;height:26px;width:50px;vertical-align:top;color:#555555;background:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.ui-grid-pager-control input:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-pager-control input[disabled],.ui-grid-pager-control input[readonly],.ui-grid-pager-control input::-moz-placeholder{opacity:1}.ui-grid-pager-control input::-moz-placeholder,.ui-grid-pager-control input:-ms-input-placeholder,.ui-grid-pager-control input::-webkit-input-placeholder{color:#999}.ui-grid-pager-control input::-ms-expand{border:0;background-color:transparent}.ui-grid-pager-control input[disabled],.ui-grid-pager-control input[readonly]{background-color:#eeeeee}.ui-grid-pager-control input[disabled]{cursor:not-allowed}.ui-grid-pager-control .ui-grid-pager-max-pages-number{vertical-align:bottom}.ui-grid-pager-control .ui-grid-pager-max-pages-number>*{vertical-align:bottom}.ui-grid-pager-control .ui-grid-pager-max-pages-number abbr{border-bottom:none;text-decoration:none}.ui-grid-pager-control .first-bar{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-left:-3px}.ui-grid-pager-control .first-bar-rtl{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-right:-7px}.ui-grid-pager-control .first-triangle{width:0;height:0;border-style:solid;border-width:5px 8.7px 5px 0;border-color:transparent #4d4d4d transparent transparent;margin-left:2px}.ui-grid-pager-control .next-triangle{margin-left:1px}.ui-grid-pager-control .prev-triangle{margin-left:0}.ui-grid-pager-control .last-triangle{width:0;height:0;border-style:solid;border-width:5px 0 5px 8.7px;border-color:transparent transparent transparent #4d4d4d;margin-left:-1px}.ui-grid-pager-control .last-bar{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-left:1px}.ui-grid-pager-control .last-bar-rtl{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-right:-11px}.ui-grid-pager-row-count-picker{float:left;padding:5px 10px}.ui-grid-pager-row-count-picker select{color:#555555;background:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px;height:25px;width:67px;display:inline;vertical-align:middle}.ui-grid-pager-row-count-picker select:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-pager-row-count-picker select[disabled],.ui-grid-pager-row-count-picker select[readonly],.ui-grid-pager-row-count-picker select::-moz-placeholder{opacity:1}.ui-grid-pager-row-count-picker select::-moz-placeholder,.ui-grid-pager-row-count-picker select:-ms-input-placeholder,.ui-grid-pager-row-count-picker select::-webkit-input-placeholder{color:#999}.ui-grid-pager-row-count-picker select::-ms-expand{border:0;background-color:transparent}.ui-grid-pager-row-count-picker select[disabled],.ui-grid-pager-row-count-picker select[readonly]{background-color:#eeeeee}.ui-grid-pager-row-count-picker select[disabled]{cursor:not-allowed}.ui-grid-pager-row-count-picker .ui-grid-pager-row-count-label{margin-top:3px}.ui-grid-pager-count-container{float:right;margin-top:4px;min-width:50px}.ui-grid-pager-count-container .ui-grid-pager-count{margin-right:10px;margin-left:10px;float:right}.ui-grid-pager-count-container .ui-grid-pager-count abbr{border-bottom:none;text-decoration:none} \ No newline at end of file diff --git a/src/css/ui-grid.pinning.css b/src/css/ui-grid.pinning.css new file mode 100644 index 0000000000..9c5eb1ae17 --- /dev/null +++ b/src/css/ui-grid.pinning.css @@ -0,0 +1,67 @@ +.ui-grid-pinned-container { + position: absolute; + display: inline; + top: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left { + float: left; + left: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right { + float: right; + right: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child { + box-sizing: border-box; + border-right: 1px solid; + border-width: 1px; + border-right-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:last-child { + box-sizing: border-box; + border-right: 1px solid; + border-width: 1px; + border-right-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar, +.ui-grid-pinned-container .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child .ui-grid-vertical-bar { + right: -1px; + width: 1px; + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:first-child { + box-sizing: border-box; + border-left: 1px solid; + border-width: 1px; + border-left-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:first-child { + box-sizing: border-box; + border-left: 1px solid; + border-width: 1px; + border-left-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar, +.ui-grid-pinned-container .ui-grid-cell:not(:first-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-first .ui-grid-header-cell:first-child .ui-grid-vertical-bar { + left: -1px; + width: 1px; + background-color: #aeaeae; +} diff --git a/src/css/ui-grid.pinning.min.css b/src/css/ui-grid.pinning.min.css new file mode 100644 index 0000000000..7068b8340c --- /dev/null +++ b/src/css/ui-grid.pinning.min.css @@ -0,0 +1 @@ +.ui-grid-pinned-container{position:absolute;display:inline;top:0}.ui-grid-pinned-container.ui-grid-pinned-container-left{float:left;left:0}.ui-grid-pinned-container.ui-grid-pinned-container-right{float:right;right:0}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child{box-sizing:border-box;border-right:1px solid;border-width:1px;border-right-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:last-child{box-sizing:border-box;border-right:1px solid;border-width:1px;border-right-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar,.ui-grid-pinned-container .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{width:1px}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child .ui-grid-vertical-bar{right:-1px;width:1px;background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:first-child{box-sizing:border-box;border-left:1px solid;border-width:1px;border-left-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:first-child{box-sizing:border-box;border-left:1px solid;border-width:1px;border-left-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar,.ui-grid-pinned-container .ui-grid-cell:not(:first-child) .ui-grid-vertical-bar{width:1px}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-first .ui-grid-header-cell:first-child .ui-grid-vertical-bar{left:-1px;width:1px;background-color:#aeaeae} \ No newline at end of file diff --git a/src/css/ui-grid.resize-columns.css b/src/css/ui-grid.resize-columns.css new file mode 100644 index 0000000000..100d05e43f --- /dev/null +++ b/src/css/ui-grid.resize-columns.css @@ -0,0 +1,38 @@ +.ui-grid-column-resizer { + top: 0; + bottom: 0; + width: 5px; + position: absolute; + cursor: col-resize; +} +.ui-grid-column-resizer.left { + left: 0; +} +.ui-grid-column-resizer.right { + right: 0; +} +.ui-grid-header-cell:last-child .ui-grid-column-resizer.right { + border-right: 1px solid #d4d4d4; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.right { + border-right: 0; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.left { + border-left: 1px solid #d4d4d4; +} +.ui-grid.column-resizing { + cursor: col-resize; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} +.ui-grid.column-resizing .ui-grid-resize-overlay { + position: absolute; + top: 0; + height: 100%; + width: 1px; + background-color: #aeaeae; +} diff --git a/src/css/ui-grid.resize-columns.min.css b/src/css/ui-grid.resize-columns.min.css new file mode 100644 index 0000000000..0915bee160 --- /dev/null +++ b/src/css/ui-grid.resize-columns.min.css @@ -0,0 +1 @@ +.ui-grid-column-resizer{top:0;bottom:0;width:5px;position:absolute;cursor:col-resize}.ui-grid-column-resizer.left{left:0}.ui-grid-column-resizer.right{right:0}.ui-grid-header-cell:last-child .ui-grid-column-resizer.right{border-right:1px solid #d4d4d4}.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.right{border-right:0}.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.left{border-left:1px solid #d4d4d4}.ui-grid.column-resizing{cursor:col-resize;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ui-grid.column-resizing .ui-grid-resize-overlay{position:absolute;top:0;height:100%;width:1px;background-color:#aeaeae} \ No newline at end of file diff --git a/src/css/ui-grid.row-edit.css b/src/css/ui-grid.row-edit.css new file mode 100644 index 0000000000..741c68b301 --- /dev/null +++ b/src/css/ui-grid.row-edit.css @@ -0,0 +1,9 @@ +.ui-grid-row-saving .ui-grid-cell { + color: #848484 !important; +} +.ui-grid-row-dirty .ui-grid-cell { + color: #610B38; +} +.ui-grid-row-error .ui-grid-cell { + color: #FF0000 !important; +} diff --git a/src/css/ui-grid.row-edit.min.css b/src/css/ui-grid.row-edit.min.css new file mode 100644 index 0000000000..362195a02c --- /dev/null +++ b/src/css/ui-grid.row-edit.min.css @@ -0,0 +1 @@ +.ui-grid-row-saving .ui-grid-cell{color:#848484 !important}.ui-grid-row-dirty .ui-grid-cell{color:#610B38}.ui-grid-row-error .ui-grid-cell{color:#FF0000 !important} \ No newline at end of file diff --git a/src/css/ui-grid.selection.css b/src/css/ui-grid.selection.css new file mode 100644 index 0000000000..8267ac9afa --- /dev/null +++ b/src/css/ui-grid.selection.css @@ -0,0 +1,25 @@ +.ui-grid-row.ui-grid-row-selected > [ui-grid-row] > .ui-grid-cell { + background-color: #C9DDE1; +} +.ui-grid-disable-selection { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + cursor: default; +} +.ui-grid-selection-row-header-buttons { + display: flex; + align-items: center; + height: 100%; + cursor: pointer; +} +.ui-grid-selection-row-header-buttons::before { + opacity: 0.1; +} +.ui-grid-selection-row-header-buttons.ui-grid-row-selected::before, +.ui-grid-selection-row-header-buttons.ui-grid-all-selected::before { + opacity: 1; +} diff --git a/src/css/ui-grid.selection.min.css b/src/css/ui-grid.selection.min.css new file mode 100644 index 0000000000..300e60f286 --- /dev/null +++ b/src/css/ui-grid.selection.min.css @@ -0,0 +1 @@ +.ui-grid-row.ui-grid-row-selected>[ui-grid-row]>.ui-grid-cell{background-color:#C9DDE1}.ui-grid-disable-selection{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.ui-grid-selection-row-header-buttons{display:flex;align-items:center;height:100%;cursor:pointer}.ui-grid-selection-row-header-buttons::before{opacity:.1}.ui-grid-selection-row-header-buttons.ui-grid-row-selected::before,.ui-grid-selection-row-header-buttons.ui-grid-all-selected::before{opacity:1} \ No newline at end of file diff --git a/src/css/ui-grid.tree-base.css b/src/css/ui-grid.tree-base.css new file mode 100644 index 0000000000..3431ca5588 --- /dev/null +++ b/src/css/ui-grid.tree-base.css @@ -0,0 +1,4 @@ +.ui-grid-tree-row-header-buttons.ui-grid-tree-header { + cursor: pointer; + opacity: 1; +} diff --git a/src/css/ui-grid.tree-base.min.css b/src/css/ui-grid.tree-base.min.css new file mode 100644 index 0000000000..968a06a917 --- /dev/null +++ b/src/css/ui-grid.tree-base.min.css @@ -0,0 +1 @@ +.ui-grid-tree-row-header-buttons.ui-grid-tree-header{cursor:pointer;opacity:1} \ No newline at end of file diff --git a/src/css/ui-grid.tree-view.css b/src/css/ui-grid.tree-view.css new file mode 100644 index 0000000000..6dfeb52b72 --- /dev/null +++ b/src/css/ui-grid.tree-view.css @@ -0,0 +1,6 @@ +.ui-grid-tree-header-row { + font-weight: bold !important; +} +.ui-grid-tree-header-row .ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell { + pointer-events: all; +} diff --git a/src/css/ui-grid.tree-view.min.css b/src/css/ui-grid.tree-view.min.css new file mode 100644 index 0000000000..c2f4b5de9e --- /dev/null +++ b/src/css/ui-grid.tree-view.min.css @@ -0,0 +1 @@ +.ui-grid-tree-header-row{font-weight:bold !important}.ui-grid-tree-header-row .ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell{pointer-events:all} \ No newline at end of file diff --git a/src/css/ui-grid.validate.css b/src/css/ui-grid.validate.css new file mode 100644 index 0000000000..622b0f6e80 --- /dev/null +++ b/src/css/ui-grid.validate.css @@ -0,0 +1,3 @@ +.ui-grid-cell-contents.invalid { + border: 1px solid #fc8f8f; +} diff --git a/src/css/ui-grid.validate.min.css b/src/css/ui-grid.validate.min.css new file mode 100644 index 0000000000..4030e751d8 --- /dev/null +++ b/src/css/ui-grid.validate.min.css @@ -0,0 +1 @@ +.ui-grid-cell-contents.invalid{border:1px solid #fc8f8f} \ No newline at end of file diff --git a/src/features/auto-resize-grid/js/auto-resize.js b/src/features/auto-resize-grid/js/auto-resize.js deleted file mode 100644 index 164122f18c..0000000000 --- a/src/features/auto-resize-grid/js/auto-resize.js +++ /dev/null @@ -1,69 +0,0 @@ -(function() { - 'use strict'; - /** - * @ngdoc overview - * @name ui.grid.autoResize - * - * @description - * - * #ui.grid.autoResize - * - * - * - * This module provides auto-resizing functionality to UI-Grid. - */ - var module = angular.module('ui.grid.autoResize', ['ui.grid']); - - - module.directive('uiGridAutoResize', ['$timeout', 'gridUtil', function ($timeout, gridUtil) { - return { - require: 'uiGrid', - scope: false, - link: function ($scope, $elm, $attrs, uiGridCtrl) { - var prevGridWidth, prevGridHeight; - - function getDimensions() { - prevGridHeight = gridUtil.elementHeight($elm); - prevGridWidth = gridUtil.elementWidth($elm); - } - - // Initialize the dimensions - getDimensions(); - - var resizeTimeoutId; - function startTimeout() { - clearTimeout(resizeTimeoutId); - - resizeTimeoutId = setTimeout(function () { - var newGridHeight = gridUtil.elementHeight($elm); - var newGridWidth = gridUtil.elementWidth($elm); - - if (newGridHeight !== prevGridHeight || newGridWidth !== prevGridWidth) { - uiGridCtrl.grid.gridHeight = newGridHeight; - uiGridCtrl.grid.gridWidth = newGridWidth; - uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevGridHeight, prevGridWidth, newGridHeight, newGridWidth); - - $scope.$apply(function () { - uiGridCtrl.grid.refresh() - .then(function () { - getDimensions(); - - startTimeout(); - }); - }); - } - else { - startTimeout(); - } - }, 250); - } - - startTimeout(); - - $scope.$on('$destroy', function() { - clearTimeout(resizeTimeoutId); - }); - } - }; - }]); -})(); diff --git a/src/features/auto-resize-grid/test/auto-resize-grid.spec.js b/src/features/auto-resize-grid/test/auto-resize-grid.spec.js deleted file mode 100644 index 39926dae8d..0000000000 --- a/src/features/auto-resize-grid/test/auto-resize-grid.spec.js +++ /dev/null @@ -1,90 +0,0 @@ -describe('ui.grid.autoResizeGrid', function () { - var gridScope, gridElm, viewportElm, $scope, $compile, recompile, uiGridConstants, $timeout; - - var data = [ - { "name": "Ethel Price", "gender": "female", "company": "Enersol" }, - { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" }, - { "name": "Beryl Rice", "gender": "female", "company": "Velity" }, - { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" } - ]; - - beforeEach(module('ui.grid')); - beforeEach(module('ui.grid.autoResize')); - - beforeEach(inject(function (_$compile_, _$timeout_, $rootScope, _uiGridConstants_) { - $scope = $rootScope; - $timeout = _$timeout_; - $compile = _$compile_; - uiGridConstants = _uiGridConstants_; - - $scope.gridOpts = { - data: data - }; - - recompile = function () { - gridElm = angular.element('
'); - document.body.appendChild(gridElm[0]); - $compile(gridElm)($scope); - $scope.$digest(); - gridScope = gridElm.isolateScope(); - - viewportElm = $(gridElm).find('.ui-grid-viewport'); - }; - - recompile(); - })); - - afterEach(function () { - angular.element(gridElm).remove(); - gridElm = null; - }); - - describe('on grid element dimension change', function () { - var w; - beforeEach(function (done) { - w = $(viewportElm).width(); - var h = $(viewportElm).height(); - - $(gridElm).width(600); - $scope.$digest(); - setTimeout(done, 300); - }); - it('adjusts the grid viewport size', function () { - var newW = $(viewportElm).width(); - expect(newW).toBeGreaterThan(w); - }); - }); - - // Rebuild the grid as having 100% width and being in a 400px wide container, then change the container width to 500px and make sure it adjusts - describe('on grid container dimension change', function () { - var gridContainerElm; - var w; - - beforeEach(function (done) { - angular.element(gridElm).remove(); - - gridContainerElm = angular.element('
'); - document.body.appendChild(gridContainerElm[0]); - $compile(gridContainerElm)($scope); - $scope.$digest(); - - gridElm = gridContainerElm.find('[ui-grid]'); - - viewportElm = $(gridElm).find('.ui-grid-viewport'); - - w = $(viewportElm).width(); - var h = $(viewportElm).height(); - - $(gridContainerElm).width(500); - $scope.$digest(); - setTimeout(done, 300); - }); - - it('adjusts the grid viewport size', function() { - var newW = $(viewportElm).width(); - - expect(newW).toBeGreaterThan(w); - }); - }); - -}); diff --git a/src/features/cellnav/less/cellNav.less b/src/features/cellnav/less/cellNav.less deleted file mode 100644 index b24eae2284..0000000000 --- a/src/features/cellnav/less/cellNav.less +++ /dev/null @@ -1,30 +0,0 @@ -@import '../../../less/variables'; -@import (reference) '../../../less/bootstrap/bootstrap'; - -// .ui-grid-cell-contents:focus { -// outline: 0; -// background-color: @focusedCell; -// } - -.ui-grid-cell-focus { - outline: 0; - background-color: @focusedCell; -} - -.ui-grid-focuser { - position: absolute; - left: 0px; - top: 0px; - z-index: -1; - width:100%; - height:100%; - #ui-grid-twbs > .form-control-focus(); -} - -.ui-grid-offscreen{ - display: block; - position: absolute; - left: -10000px; - top: -10000px; - clip:rect(0px,0px,0px,0px); -} diff --git a/src/features/cellnav/test/uiGridCellNavDirective.spec.js b/src/features/cellnav/test/uiGridCellNavDirective.spec.js deleted file mode 100644 index f1bd38cf28..0000000000 --- a/src/features/cellnav/test/uiGridCellNavDirective.spec.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('ui.grid.cellNav directive', function () { - var $scope, $compile, elm, uiGridConstants; - - beforeEach(module('ui.grid')); - beforeEach(module('ui.grid.cellNav')); - - beforeEach(inject(function (_$rootScope_, _$compile_, _uiGridConstants_) { - $scope = _$rootScope_; - $compile = _$compile_; - uiGridConstants = _uiGridConstants_; - - $scope.gridOpts = { - data: [{ name: 'Bob' }, {name: 'Mathias'}, {name: 'Fred'}], - modifierKeysToMultiSelectCells: true, - keyDownOverrides: [{ keyCode: 39 }] - }; - - $scope.gridOpts.onRegisterApi = function (gridApi) { - $scope.gridApi = gridApi; - $scope.grid = gridApi.grid; - }; - - elm = angular.element('
'); - $scope.gridOpts.onRegisterApi = function (gridApi) { - $scope.gridApi = gridApi; - $scope.grid = gridApi.grid; - }; - - elm = angular.element('
'); - - $compile(elm)($scope); - $scope.$digest(); - })); - - it('should not throw exceptions when scrolling when a grid does NOT have the ui-grid-cellNav directive', function () { - expect(function () { - $scope.gridApi.core.raise.scrollBegin({}); - }).not.toThrow(); - }); - - - it('rowColSelectIndex(rowCol) should properly return the index of the provided rowCol representing the order it was' + - ' selected', function () { - var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] }; - // We select an arbitrary cell first to test that holding modifier persists the selection - $scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true); - $scope.grid.cellNav.broadcastCellNav(rowColToTest, true); - // Now our rowColToTest should have the index 1 as it was selected second - expect($scope.gridApi.cellNav.rowColSelectIndex(rowColToTest)).toEqual(1); - }); - - it('getCurrentSelection() should properly return an array representing the values of the current cell selection', function () { - $scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true); - $scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true); - expect($scope.gridApi.cellNav.getCurrentSelection().length).toEqual(2); - }); - - - it('handleKeyDown should clear the focused cells list when clearing focus', function () { - // first ensure that a cell is selected - $scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true); - var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] }; - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.TAB; - $scope.grid.cellNav.lastRowCol = rowColToTest; - - // simulate tabbing out of grid - elm.controller('uiGrid').cellNav.handleKeyDown(evt); - expect($scope.grid.cellNav.focusedCells.length).toEqual(0); - - // simulate restoring focus - $scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true); - expect($scope.grid.cellNav.focusedCells.length).toEqual(1); - }); - - it('should not call handleKeyDown if the key event is overridden', function () { - spyOn(elm.controller('uiGrid').cellNav, 'handleKeyDown'); - var focuser = elm.find('focuser'); - var evt = jQuery.Event("keydown"); - evt.keyCode = 39; - - focuser.trigger(evt); - - expect(elm.controller('uiGrid').cellNav.handleKeyDown).not.toHaveBeenCalled(); - }); - - it('should call handleKeyDown if the key event is not overridden', function () { - spyOn(elm.controller('uiGrid').cellNav, 'handleKeyDown'); - var focuser = elm.find('.ui-grid-focuser'); - var evt = jQuery.Event("keydown"); - evt.keyCode = 37; - - focuser.trigger(evt); - - expect(elm.controller('uiGrid').cellNav.handleKeyDown).toHaveBeenCalled(); - }); - - it('should raise the viewPortKeyDown event if the key is overridden', function () { - spyOn(elm.controller('uiGrid').grid.api.cellNav.raise, 'viewPortKeyDown'); - var focuser = elm.find('.ui-grid-focuser'); - var evt = jQuery.Event("keydown"); - evt.keyCode = 39; - - focuser.trigger(evt); - - expect(elm.controller('uiGrid').grid.api.cellNav.raise.viewPortKeyDown).toHaveBeenCalled(); - }); - - it('should not raise the viewPortKeyDown event if the key is not overridden and is part of the base cell navigation keyboard support', function () { - spyOn(elm.controller('uiGrid').grid.api.cellNav.raise, 'viewPortKeyDown'); - var focuser = elm.find('.ui-grid-focuser'); - var evt = jQuery.Event("keydown"); - evt.keyCode = 37; - - focuser.trigger(evt); - - expect(elm.controller('uiGrid').grid.api.cellNav.raise.viewPortKeyDown).not.toHaveBeenCalled(); - }); -}); diff --git a/src/features/cellnav/test/uiGridCellNavFactory.spec.js b/src/features/cellnav/test/uiGridCellNavFactory.spec.js deleted file mode 100644 index 841b7be182..0000000000 --- a/src/features/cellnav/test/uiGridCellNavFactory.spec.js +++ /dev/null @@ -1,221 +0,0 @@ -describe('ui.grid.edit uiGridCellNavService', function () { - var UiGridCellNav; - var uiGridCellNavService; - var gridClassFactory; - var grid; - var uiGridConstants; - var uiGridCellNavConstants; - var $rootScope; - var $timeout; - var colDef0,colDef1,colDef2; - - beforeEach(module('ui.grid.cellNav')); - - beforeEach(inject(function (_uiGridCellNavFactory_, _uiGridCellNavService_, _gridClassFactory_, $templateCache, _uiGridConstants_, _uiGridCellNavConstants_, _$rootScope_, _$timeout_) { - UiGridCellNav = _uiGridCellNavFactory_; - uiGridCellNavService = _uiGridCellNavService_; - gridClassFactory = _gridClassFactory_; - uiGridConstants = _uiGridConstants_; - uiGridCellNavConstants = _uiGridCellNavConstants_; - $rootScope = _$rootScope_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
'); - - colDef0 = {name: 'col0', allowCellFocus: true}; - colDef1 = {name: 'col1', allowCellFocus: false}; - colDef2 = {name: 'col2'}; - - var options = {columnDefs: [ - colDef0, - colDef1, - colDef2 - ]}; - - options.data = [ - {col0: 'row0col0', col1: 'row0col1', col2: 'row0col2'}, - {col0: 'row1col0', col1: 'row1col1', col2: 'row1col2'}, - {col0: 'row2col0', col1: 'row2col1', col2: 'row2col2'} - ]; - - grid = gridClassFactory.createGrid(options); - - uiGridCellNavService.initializeGrid(grid); - grid.modifyRows(grid.options.data); - $timeout(function () { - grid.buildColumns().then(function () { - grid.setVisibleColumns(grid.columns); - }); - }); - $timeout.flush(); - - })); - - describe('navigate Left', function () { - beforeEach(function () { - }); - - it('should navigate to col left from unfocusable column', function () { - var row = grid.rows[0]; - var col = grid.columns[1]; - - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.LEFT, row, col); - - expect(rowCol.row).toBe(row); - expect(rowCol.col.name).toBe(colDef0.name); - }); - - it('should navigate up one row and far right column', function () { - var col = grid.columns[0]; - var row = grid.rows[1]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.LEFT, row, col); - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.name).toBe(colDef2.name); - }); - - it('should stay on same row and go to far right', function () { - var col = grid.columns[0]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.LEFT, row, col); - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - - it('should skip col that is not focusable', function () { - var col = grid.columns[2]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.LEFT, row, col); - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.colDef.name).toBe(grid.columns[0].colDef.name); - }); - - it('should skip row that is not focusable', function () { - var col = grid.columns[2]; - var row = grid.rows[0]; - grid.rows[1].allowCellFocus = false; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, row, col); - expect(rowCol.row).toBe(grid.rows[2]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - }); - - - describe('navigate right', function () { - beforeEach(function () { - - }); - it('should navigate to col right from unfocusable column', function () { - var col = grid.columns[1]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.RIGHT, row, col); - - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - it('should navigate down one row and far left column', function () { - var col = grid.columns[2]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.RIGHT, row, col); - expect(rowCol.row).toBe(grid.rows[1]); - expect(rowCol.col.colDef.name).toBe(grid.columns[0].colDef.name); - }); - - it('should stay on same row and go to far left', function () { - var col = grid.columns[2]; - var row = grid.rows[2]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.RIGHT, row, col); - - expect(rowCol.row).toBe(grid.rows[2]); - expect(rowCol.col.colDef.name).toBe(grid.columns[0].colDef.name); - }); - - it('should skip col that is not focusable', function () { - var col = grid.columns[0]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.RIGHT, row, col); - - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - }); - - describe('navigate down', function () { - beforeEach(function () { - grid.registerColumnBuilder(uiGridCellNavService.cellNavColumnBuilder); - grid.buildColumns(); - }); - it('should navigate to col 0 from unfocusable column', function () { - var col = grid.columns[1]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, row, col); - expect(rowCol.row).toBe(grid.rows[1]); - expect(rowCol.col.colDef.name).toBe(grid.columns[0].colDef.name); - }); - - it('should navigate down one row and same column', function () { - var col = grid.columns[2]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, row, col); - expect(rowCol.row).toBe(grid.rows[1]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - it('should stay on same row and same column', function () { - var col = grid.columns[2]; - var row = grid.rows[2]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, row, col); - expect(rowCol.row).toBe(grid.rows[2]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - }); - - describe('navigate up', function () { - beforeEach(function () { - grid.registerColumnBuilder(uiGridCellNavService.cellNavColumnBuilder); - grid.buildColumns(); - }); - it('should navigate to first col from unfocusable column', function () { - var col = grid.columns[1]; - var row = grid.rows[2]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.UP, row, col); - expect(rowCol.row).toBe(grid.rows[1]); - expect(rowCol.col.colDef.name).toBe(grid.columns[0].colDef.name); - }); - - it('should navigate up one row and same column', function () { - var col = grid.columns[2]; - var row = grid.rows[2]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.UP, row, col); - expect(rowCol.row).toBe(grid.rows[1]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - it('should stay on same row and same column', function () { - var col = grid.columns[2]; - var row = grid.rows[0]; - var cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, null, null); - var rowCol = cellNav.getNextRowCol(uiGridCellNavConstants.direction.UP, row, col); - expect(rowCol.row).toBe(grid.rows[0]); - expect(rowCol.col.colDef.name).toBe(grid.columns[2].colDef.name); - }); - - }); - -}); diff --git a/src/features/cellnav/test/uiGridCellNavService.spec.js b/src/features/cellnav/test/uiGridCellNavService.spec.js deleted file mode 100644 index d30022c9c6..0000000000 --- a/src/features/cellnav/test/uiGridCellNavService.spec.js +++ /dev/null @@ -1,302 +0,0 @@ -describe('ui.grid.edit uiGridCellNavService', function () { - var uiGridCellNavService; - var gridClassFactory; - var grid; - var uiGridConstants; - var uiGridCellNavConstants; - var $rootScope; - var $timeout; - - beforeEach(module('ui.grid.cellNav')); - - beforeEach(inject(function (_uiGridCellNavService_, _gridClassFactory_, $templateCache, _uiGridConstants_, _uiGridCellNavConstants_, _$rootScope_, _$timeout_) { - uiGridCellNavService = _uiGridCellNavService_; - gridClassFactory = _gridClassFactory_; - uiGridConstants = _uiGridConstants_; - uiGridCellNavConstants = _uiGridCellNavConstants_; - $rootScope = _$rootScope_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
'); - - grid = gridClassFactory.createGrid(); - // Give the grid a meaningful height (large enough for one row to be displayed) - grid.gridHeight = grid.options.rowHeight + grid.headerHeight; - //throttled scrolling isn't working in tests for some reason - grid.options.scrollDebounce = 0; - grid.options.columnDefs = [ - {name: 'col0', allowCellFocus: true}, - {name: 'col1', allowCellFocus: false}, - {name: 'col2'} - ]; - - grid.options.data = [ - {col0: 'row0col0', col1: 'row0col1', col2: 'row0col2'}, - {col0: 'row1col0', col1: 'row1col1', col2: 'row1col2'}, - {col0: 'row2col0', col1: 'row2col1', col2: 'row2col2'} - ]; - - uiGridCellNavService.initializeGrid(grid); - grid.modifyRows(grid.options.data); - })); - - - describe('public Apis function', function () { - beforeEach(function(){ - grid.buildColumns(); - }); - - it('should have getFocusedCell', function () { - expect(grid.api.cellNav.getFocusedCell()).toBeDefined(); - expect(grid.api.cellNav.getFocusedCell()).toBe(null); - grid.cellNav.lastRowCol = 'mockRowCol'; - expect(grid.api.cellNav.getFocusedCell()).toBe('mockRowCol'); - }); - - }); - - - describe('cellNavColumnBuilder function', function () { - beforeEach(function(){ - grid.buildColumns(); - }); - - it('should populate allowCellFocus with defaults', function () { - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - uiGridCellNavService.cellNavColumnBuilder(colDef, col, grid.options); - expect(col.colDef.allowCellFocus).toBe(true); - - colDef = grid.options.columnDefs[1]; - col = grid.columns[1]; - uiGridCellNavService.cellNavColumnBuilder(colDef, col, grid.options); - expect(col.colDef.allowCellFocus).toBe(false); - - colDef = grid.options.columnDefs[2]; - col = grid.columns[2]; - uiGridCellNavService.cellNavColumnBuilder(colDef, col, grid.options); - expect(col.colDef.allowCellFocus).toBe(true); - }); - }); - - describe('getDirection(evt)', function () { - beforeEach(function(){ - grid.registerColumnBuilder(uiGridCellNavService.cellNavColumnBuilder); - grid.buildColumns(); - }); - it('should navigate right on tab', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.TAB; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.RIGHT); - }); - - it('should navigate right on right arrow', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.RIGHT; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.RIGHT); - }); - - it('should navigate left on shift tab', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.TAB; - evt.shiftKey = true; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.LEFT); - }); - - it('should navigate left on left arrow', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.LEFT; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.LEFT); - }); - - it('should navigate down on enter', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.ENTER; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.DOWN); - }); - - it('should navigate down on down arrow', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.DOWN; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.DOWN); - }); - - it('should navigate up on shift enter', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.ENTER; - evt.shiftKey = true; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.UP); - }); - - it('should navigate up on up arrow', function () { - var evt = jQuery.Event("keydown"); - evt.keyCode = uiGridConstants.keymap.UP; - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - var direction = uiGridCellNavService.getDirection(evt); - expect(direction).toBe(uiGridCellNavConstants.direction.UP); - }); - - - }); - - - describe('scrollTo', function () { - /* - * We have 11 rows (10 visible) and 11 columns (10 visible). The column widths are - * 100 for the first 5, and 200 for the second 5. Column 2 and row 2 are invisible. - */ - var evt; - var args; - var $scope; - - beforeEach(function(){ - var i, j, row; - grid.options.columnDefs = []; - for ( i = 0; i < 11; i++ ){ - grid.options.columnDefs.push({name: 'col' + i}); - } - - grid.options.data = []; - for ( i = 0; i < 11; i++ ){ - row = {}; - for ( j = 0; j < 11; j++ ){ - row['col' + j] = 'test data ' + i + '_' + j; - } - grid.options.data.push( row ); - } - - uiGridCellNavService.initializeGrid(grid); - grid.modifyRows(grid.options.data); - - grid.registerColumnBuilder(uiGridCellNavService.cellNavColumnBuilder); - grid.buildColumns(); - - grid.columns[2].visible = false; - grid.rows[2].visible = false; - - grid.setVisibleColumns(grid.columns); - grid.setVisibleRows(grid.rows); - - grid.renderContainers.body.headerHeight = 0; - - for ( i = 0; i < 11; i++ ){ - grid.columns[i].drawnWidth = i < 6 ? 100 : 200; - } - - $scope = $rootScope.$new(); - - args = null; - grid.api.core.on.scrollEnd($scope, function( receivedArgs ){ - args = receivedArgs; - }); - - }); - - - // these have changed to use scrollToIfNecessary, which is better code - // but it means these unit tests are now mostly checking that it is the same it used to - // be, not that it is giving some specified result (i.e. I just updated them to what they were) - // Since we set the grid height, the expected vertical scroll percentages make sense. - // They will be (at least when scrolling down): (seekRowIndex - visibleRows) / (totalRows - visibleRows) - it('should request scroll to row and column', function () { - $timeout(function () { - grid.scrollTo(grid.options.data[4], grid.columns[4].colDef); - }); - $timeout.flush(); - - expect(args.grid).toEqual(grid); - expect(Math.round(args.y.percentage * 10)/10).toBe(0.3); - expect(isNaN(args.x.percentage)).toEqual( true ); - }); - - it('should request scroll to row only - first row', function () { - $timeout(function () { - grid.scrollTo( grid.options.data[0], null); - }); - $timeout.flush(); - - // The first row is already displayed. No scrolling necessary. - expect(args).toBe(null); - }); - - it('should request scroll to row only - last row', function () { - $timeout(function () { - grid.scrollTo( grid.options.data[10], null); - }); - $timeout.flush(); - - expect(args.y.percentage).toBeGreaterThan(0.5); - expect(args.x).toBe(null); - }); - - it('should request scroll to row only - row 5', function () { - $timeout(function () { - grid.scrollTo( grid.options.data[5], null); - }); - $timeout.flush(); - - expect(Math.round(args.y.percentage * 10)/10).toEqual( 0.4); - expect(args.x).toBe(null); - }); - - it('should request scroll to column only - first column', function () { - $timeout(function () { - grid.scrollTo( null, grid.columns[0].colDef); - }); - $timeout.flush(); - - - expect(isNaN(args.x.percentage)).toEqual( true ); - }); - - it('should request scroll to column only - last column', function () { - $timeout(function () { - grid.scrollTo( null, grid.columns[10].colDef); - }); - $timeout.flush(); - - - expect(isNaN(args.x.percentage)).toEqual( true ); - }); - - it('should request scroll to column only - column 8', function () { - $timeout(function () { - grid.scrollTo( null, grid.columns[8].colDef); - }); - $timeout.flush(); - - expect(isNaN(args.x.percentage)).toEqual( true ); - }); - - it('should request no scroll as no row or column', function () { - $timeout(function () { - grid.scrollTo( null, null ); - }); - $timeout.flush(); - - expect(args).toEqual( null ); - }); - }); -}); \ No newline at end of file diff --git a/src/features/edit/templates/cellEditor.html b/src/features/edit/templates/cellEditor.html deleted file mode 100644 index 9f6f3a2b10..0000000000 --- a/src/features/edit/templates/cellEditor.html +++ /dev/null @@ -1,10 +0,0 @@ -
-
- -
-
diff --git a/src/features/edit/templates/dropdownEditor.html b/src/features/edit/templates/dropdownEditor.html deleted file mode 100644 index 7d8f8a5ae2..0000000000 --- a/src/features/edit/templates/dropdownEditor.html +++ /dev/null @@ -1,11 +0,0 @@ -
-
- -
-
diff --git a/src/features/edit/templates/fileChooserEditor.html b/src/features/edit/templates/fileChooserEditor.html deleted file mode 100644 index 30da7b7ad7..0000000000 --- a/src/features/edit/templates/fileChooserEditor.html +++ /dev/null @@ -1,12 +0,0 @@ -
-
- -
-
diff --git a/src/features/edit/test/uiGridCell.spec.js b/src/features/edit/test/uiGridCell.spec.js deleted file mode 100644 index 59329e59e8..0000000000 --- a/src/features/edit/test/uiGridCell.spec.js +++ /dev/null @@ -1,172 +0,0 @@ -describe('ui.grid.edit GridCellDirective', function () { - var gridUtil; - var scope; - var element; - var uiGridConstants; - var recompile; - var $timeout; - - beforeEach(module('ui.grid.edit')); - - beforeEach(inject(function ($rootScope, $compile, $controller, _gridUtil_, $templateCache, gridClassFactory, - uiGridEditService, _uiGridConstants_, _$timeout_) { - gridUtil = _gridUtil_; - uiGridConstants = _uiGridConstants_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
{{COL_FIELD CUSTOM_FILTERS}}
'); - $templateCache.put('ui-grid/cellEditor', '
'); - - scope = $rootScope.$new(); - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {name: 'col1', enableCellEdit: true} - ]; - grid.options.data = [ - {col1: 'val', col2:'col2val'} - ]; - uiGridEditService.initializeGrid(grid); - grid.buildColumns(); - grid.modifyRows(grid.options.data); - - scope.grid = grid; - scope.col = grid.columns[0]; - scope.row = grid.rows[0]; - - scope.getCellValue = function(row,col){return 'val';}; - - $timeout(function(){ - recompile = function () { - $compile(element)(scope); - $rootScope.$digest(); - }; - }); - $timeout.flush(); - - })); - - describe('ui.grid.edit uiGridCell start editing', function () { - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('val'); - }); - - it('startEdit on "a"', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = 65; - element.trigger(event); - expect(element.find('input')).toBeDefined(); - }); - - it('not start edit on tab', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - element.trigger(event); - expect(element.html()).toEqual(displayHtml); - }); - - }); - - describe('ui.grid.edit uiGridCell and uiGridEditor full workflow', function () { - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('val'); - //invoke edit - element.dblclick(); - $timeout(function () { - expect(element.find('input')).toBeDefined(); - expect(element.find('input').val()).toBe('val'); - }); - $timeout.flush(); - }); - - it('should stop editing on enter', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ENTER; - element.find('input').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should stop editing on esc', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ESC; - element.find('input').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should stop editing on tab', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - element.find('input').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should stop when grid scrolls', function () { - //stop edit - scope.grid.api.core.raise.scrollBegin(); - scope.$digest(); - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should fire public event', inject(function ($timeout) { - - var edited = false; - - scope.grid.api.edit.on.afterCellEdit(scope,function(rowEntity, colDef, newValue, oldValue){ - edited = true; - scope.$apply(); - }); - - //stop edit - $timeout(function(){ - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ENTER; - element.find('input').trigger(event); - }); - $timeout.flush(); - - expect(edited).toBe(true); - - })); - - - }); - - - describe('ui.grid.edit should override bound value when using editModelField', function () { - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - //bind the edit to another column. This could be any property on the entity - scope.grid.options.columnDefs[0].editModelField = 'col2'; - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('val'); - //invoke edit - element.dblclick(); - expect(element.find('input')).toBeDefined(); - expect(element.find('input').val()).toBe('col2val'); - }); - }); -}); diff --git a/src/features/edit/test/uiGridCellWithCellNav.spec.js b/src/features/edit/test/uiGridCellWithCellNav.spec.js deleted file mode 100644 index 66116cd8d4..0000000000 --- a/src/features/edit/test/uiGridCellWithCellNav.spec.js +++ /dev/null @@ -1,103 +0,0 @@ -//tests not working. need to refactor either tests or cellNav because the controller isn't wired properly -xdescribe('ui.grid.edit GridCellDirective with CellNav feature', function () { - beforeEach(module('ui.grid.cellNav')); - beforeEach(module('ui.grid.edit')); - - var gridUtil; - var scope; - var element; - var uiGridConstants; - var recompile; - var $timeout; - - - var gridController = null; - - beforeEach(inject(function ($rootScope, $compile, $controller, _gridUtil_, $templateCache, gridClassFactory, - uiGridEditService, uiGridCellNavService, _uiGridConstants_, _$timeout_) { - gridUtil = _gridUtil_; - uiGridConstants = _uiGridConstants_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
{{COL_FIELD CUSTOM_FILTERS}}
'); - $templateCache.put('ui-grid/cellEditor', '
'); - - scope = $rootScope.$new(); - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {name: 'col1', enableCellEdit: true, enableCellEditOnFocus:true} - ]; - grid.options.data = [ - {col1: 'val'} - ]; - uiGridCellNavService.initializeGrid(grid); - uiGridEditService.initializeGrid(grid); - grid.buildColumns(); - grid.modifyRows(grid.options.data); - - scope.grid = grid; - scope.col = grid.columns[0]; - scope.col.cellTemplate = '
{{COL_FIELD}}
'; - scope.row = grid.rows[0]; - - var gridController = { - add: function() { return 123; } - }; - - - $timeout(function(){ - grid.preCompileCellTemplates(); - recompile = function () { - element.data('$uiGridController', gridController); - $compile(element)(scope); - $rootScope.$digest(); - }; - }); - $timeout.flush(); - })); - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('val'); - //invoke edit - element.dblclick(); - expect(element.find('input')).toBeDefined(); - expect(element.find('input').val()).toBe('val'); - }); - - it('should stop editing on arrow', function () { - //stop edit - - $timeout(function () { - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.RIGHT; - element.find('input').trigger(event); - scope.$digest(); - }); - $timeout.flush(); - - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should not stop editing on arrow after click', inject(function ($timeout) { - //click to deep edit (user can use arrows to navigate around editable text) - - - - var event = jQuery.Event("click"); - element.find('input').trigger(event); - - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ARROW_RIGHT; - element.find('input').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - })); - -}); diff --git a/src/features/edit/test/uiGridCellWithDropdown.spec.js b/src/features/edit/test/uiGridCellWithDropdown.spec.js deleted file mode 100644 index 9132dff27b..0000000000 --- a/src/features/edit/test/uiGridCellWithDropdown.spec.js +++ /dev/null @@ -1,191 +0,0 @@ -describe('ui.grid.edit GridCellDirective - with dropdown', function () { - var gridUtil; - var scope; - var element; - var uiGridConstants; - var recompile; - var $timeout; - - beforeEach(module('ui.grid.edit')); - - beforeEach(inject(function ($rootScope, $compile, $controller, _gridUtil_, $templateCache, gridClassFactory, - uiGridEditService, _uiGridConstants_, _$timeout_) { - gridUtil = _gridUtil_; - uiGridConstants = _uiGridConstants_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
{{COL_FIELD CUSTOM_FILTERS}}
'); - $templateCache.put('ui-grid/dropdownEditor', '
'); - - scope = $rootScope.$new(); - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {name: 'col1', enableCellEdit: true, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownOptionsArray: [{id: 1, value: 'fred'}, {id:2, value: 'john'}]} - ]; - grid.options.data = [ - {col1: 1} - ]; - uiGridEditService.initializeGrid(grid); - grid.buildColumns(); - grid.modifyRows(grid.options.data); - - scope.grid = grid; - scope.col = grid.columns[0]; - scope.row = grid.rows[0]; - - scope.getCellValue = function(row,col){return 'val';}; - - $timeout(function(){ - recompile = function () { - $compile(element)(scope); - $rootScope.$digest(); - }; - }); - $timeout.flush(); - - })); - - describe('ui.grid.edit uiGridCell start editing', function () { - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('1'); - }); - - it('startEdit on "a"', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = 65; - element.trigger(event); - expect(element.find('input')).toBeDefined(); - }); - - it('not start edit on tab', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - element.trigger(event); - expect(element.html()).toEqual(displayHtml); - }); - - }); - - describe('ui.grid.edit uiGridCell and uiGridEditor full workflow', function () { - var displayHtml; - beforeEach(function () { - element = angular.element('
'); - recompile(); - - displayHtml = element.html(); - expect(element.text()).toBe('1'); - //invoke edit - element.dblclick(); - expect(element.find('select')).toBeDefined(); - - $timeout(function () { - // val is the selected option, which is option 0 or 'number:1' in angular ^1.4 - /* - * Why the version dependent test? - * See: https://github.com/angular/angular.js/blob/master/CHANGELOG.md#breaking-changes-7 - */ - if ( angular.version.major === 1 && angular.version.minor < 4) { // If below vesrion 1.4 - expect(element.find('select').val()).toBe('0'); - } else { // If above vesrion 1.4 - expect(element.find('select').val()).toBe('number:1'); - } - }); - $timeout.flush(); - }); - - it('should stop editing on enter', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ENTER; - element.find('select').trigger(event); - - //back to beginning - $timeout(function () { - expect(element.html()).toBe(displayHtml); - }); - $timeout.flush(); - - }); - - it('should stop editing on esc', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ESC; - element.find('select').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - //todo: arrow left only stops editing if using cellnav. need to wire up the controllers in test - xit('should stop editing on arrow left', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.LEFT; - element.find('select').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - //todo: arrow left only stops editing if using cellnav. need to wire up the controllers in test - xit('should stop editing on arrow right', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.RIGHT; - element.find('select').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should stop editing on tab', function () { - //stop edit - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - element.find('select').trigger(event); - - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should stop when grid scrolls', function () { - //stop edit - scope.grid.api.core.raise.scrollBegin(scope); - scope.$digest(); - //back to beginning - expect(element.html()).toBe(displayHtml); - }); - - it('should fire public event', inject(function ($timeout) { - - var edited = false; - - scope.grid.api.edit.on.afterCellEdit(scope,function(rowEntity, colDef, newValue, oldValue){ - edited = true; - scope.$apply(); - }); - - //stop edit - $timeout(function(){ - var event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.ENTER; - element.find('select').trigger(event); - }); - $timeout.flush(); - - expect(edited).toBe(true); - - })); - - - }); - -}); diff --git a/src/features/edit/test/uiGridEditDirective.spec.js b/src/features/edit/test/uiGridEditDirective.spec.js deleted file mode 100644 index 812bbeae12..0000000000 --- a/src/features/edit/test/uiGridEditDirective.spec.js +++ /dev/null @@ -1,80 +0,0 @@ -describe('uiGridEditDirective', function () { - var gridUtil; - var scope; - var element; - var cellEditorHtml = '
'; - var colDefEditableCellTemplate = '
'; - var gridOptionsEditableCellTemplate = '
'; - var recompile; - - beforeEach(module('ui.grid.edit')); - - beforeEach(inject(function ($rootScope, $compile, $controller, _gridUtil_, $templateCache, $timeout) { - gridUtil = _gridUtil_; - - $templateCache.put('ui-grid/ui-grid', '
'); - $templateCache.put('ui-grid/uiGridCell', '
'); - $templateCache.put('ui-grid/uiGridHeaderCell', '
'); - $templateCache.put('ui-grid/cellEditor', cellEditorHtml); - - scope = $rootScope.$new(); - scope.options = {}; - scope.options.data = [ - {col1: 'row1'}, - {col1: 'row2'} - ]; - - scope.options.columnDefs = [ - {field: 'col1', enableCellEdit: true}, - {field: 'col2', enableCellEdit: false} - ]; - - recompile = function () { - $compile(element)(scope); - $rootScope.$digest(); - }; - })); - - describe('columnsBuilder function', function () { - - it('should create additional edit properties', function () { - element = angular.element('
'); - recompile(); - - //grid scope is a child of the scope used to compile the element. - // this is the only way I could figure out how to access - var gridScope = element.scope().$$childTail; - - var col = gridScope.grid.getColumn('col1'); - expect(col).not.toBeNull(); - expect(col.colDef.enableCellEdit).toBe(true); - expect(col.editableCellTemplate).toBe(cellEditorHtml); - - col = gridScope.grid.getColumn('col2'); - expect(col).not.toBeNull(); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.colDef.editableCellTemplate).not.toBeDefined(); - expect(col.colDef.editModelField).not.toBeDefined(); - - }); - - it('editableCellTemplate value should get priority over default templates', function () { - - element = angular.element('
'); - scope.options.editableCellTemplate = gridOptionsEditableCellTemplate; - recompile(); - - //A template specified in Grid Options should get priority over defaults - var gridScope = element.scope().$$childTail; - var col = gridScope.grid.getColumn('col1'); - expect(col.editableCellTemplate).toBe(gridOptionsEditableCellTemplate); - - //A template specified in colDef should get priority over defaults - //as well as one specified in grid options - scope.options.columnDefs[0].editableCellTemplate = colDefEditableCellTemplate; - recompile(); - expect(col.editableCellTemplate).toBe(colDefEditableCellTemplate); - }); - }); - -}); diff --git a/src/features/edit/test/uiGridEditService.spec.js b/src/features/edit/test/uiGridEditService.spec.js deleted file mode 100644 index badff0e027..0000000000 --- a/src/features/edit/test/uiGridEditService.spec.js +++ /dev/null @@ -1,190 +0,0 @@ -describe('ui.grid.edit uiGridEditService', function () { - var uiGridEditService; - var gridClassFactory; - - - - beforeEach(module('ui.grid.edit')); - - beforeEach(inject(function (_uiGridEditService_,_gridClassFactory_, $templateCache) { - uiGridEditService = _uiGridEditService_; - gridClassFactory = _gridClassFactory_; - - $templateCache.put('ui-grid/uiGridCell', '
'); - $templateCache.put('ui-grid/cellEditor', '
'); - - - })); - - describe('editColumnBuilder function', function () { - - it('should default gridOptions', inject(function ($timeout) { - - var options = {}; - uiGridEditService.defaultGridOptions(options); - expect(options.enableCellEdit).toBe(undefined); - expect(options.cellEditableCondition).toBe(true); - expect(options.enableCellEditOnFocus).toBe(false); - - options.enableCellEdit = false; - uiGridEditService.defaultGridOptions(options); - expect(options.enableCellEdit).toBe(false); - - function myFunc(){} - options.cellEditableCondition = myFunc; - uiGridEditService.defaultGridOptions(options); - expect(options.cellEditableCondition).toBe(myFunc); - - options.cellEditableCondition = false; - uiGridEditService.defaultGridOptions(options); - expect(options.cellEditableCondition).toBe(false); - - options.enableCellEditOnFocus = true; - uiGridEditService.defaultGridOptions(options); - expect(options.enableCellEditOnFocus).toBe(true); - - })); - - it('should create additional edit properties', inject(function ($timeout) { - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {field: 'col1', enableCellEdit: true} - ]; - $timeout(function(){ - uiGridEditService.defaultGridOptions(grid.options); - grid.buildColumns(); - }); - $timeout.flush(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - $timeout(function(){ - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - }); - $timeout.flush(); - - expect(col.colDef.enableCellEdit).toBe(true); - expect(col.editableCellTemplate).toBeDefined(); - })); - - it('should not create additional edit properties if edit is not enabled for a column', function () { - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {field: 'col1', enableCellEdit: false} - ]; - grid.buildColumns(); - - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.editableCellTemplate).not.toBeDefined(); - }); - - it('should create additional edit properties if global enableCellEdit is true', inject(function ($timeout) { - var grid = gridClassFactory.createGrid(); - grid.options.enableCellEdit = true; - grid.options.columnDefs = [ - {field: 'col1'} - ]; - grid.buildColumns(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - $timeout(function(){ - uiGridEditService.defaultGridOptions(grid.options); - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - }); - $timeout.flush(); - expect(col.colDef.enableCellEdit).toBe(true); - expect(col.colDef.editableCellTemplate).toBeDefined(); - })); - - it('should not create additional edit properties if global enableCellEdit is false', function () { - var grid = gridClassFactory.createGrid(); - grid.options.enableCellEdit = false; - grid.options.columnDefs = [ - {field: 'col1'} - ]; - grid.buildColumns(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.colDef.editableCellTemplate).not.toBeDefined(); - }); - - it('should not create additional edit properties for column of type object', function () { - var grid = gridClassFactory.createGrid(); - grid.options.columnDefs = [ - {field: 'col1', type: 'object'} - ]; - grid.buildColumns(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.colDef.editableCellTemplate).not.toBeDefined(); - }); - - it('should override enableCellEdit for each coldef if global enableCellEdit is false', inject(function ($timeout) { - var grid = gridClassFactory.createGrid(); - grid.options.enableCellEdit = false; - grid.options.columnDefs = [ - {field: 'col1', enableCellEdit:true}, - {field: 'col2', enableCellEdit:false} - ]; - grid.buildColumns(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - $timeout(function(){ - uiGridEditService.defaultGridOptions(grid.options); - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - }); - $timeout.flush(); - expect(col.colDef.enableCellEdit).toBe(true); - expect(col.editableCellTemplate).toBeDefined(); - - colDef = grid.options.columnDefs[1]; - col = grid.columns[1]; - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.editableCellTemplate).not.toBeDefined(); - })); - - it('should override enableCellEdit for each coldef if global enableCellEdit is true', inject(function($timeout) { - var grid = gridClassFactory.createGrid(); - grid.options.enableCellEdit = true; - grid.options.columnDefs = [ - {field: 'col1', enableCellEdit:false}, - {field: 'col2', enableCellEdit:true} - ]; - grid.buildColumns(); - - var colDef = grid.options.columnDefs[0]; - var col = grid.columns[0]; - $timeout(function(){ - uiGridEditService.defaultGridOptions(grid.options); - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - }); - $timeout.flush(); - expect(col.colDef.enableCellEdit).toBe(false); - expect(col.editableCellTemplate).not.toBeDefined(); - - colDef = grid.options.columnDefs[1]; - col = grid.columns[1]; - $timeout(function(){ - uiGridEditService.editColumnBuilder(colDef,col,grid.options); - }); - $timeout.flush(); - expect(col.colDef.enableCellEdit).toBe(true); - expect(col.editableCellTemplate).toBeDefined(); - })); - - }); - -}); diff --git a/src/features/edit/test/uiGridInputDirective.spec.js b/src/features/edit/test/uiGridInputDirective.spec.js deleted file mode 100644 index bf8951b402..0000000000 --- a/src/features/edit/test/uiGridInputDirective.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -describe('inputDirective', function () { - var element; - var recompile; - var scope; - - beforeEach(module('ui.grid.edit')); - - beforeEach(inject(function ($rootScope, $compile) { - element = angular.element('
'); - scope = $rootScope.$new(); - - recompile = function () { - $compile(element)(scope); - $rootScope.$digest(); - }; - })); - - it('value of input date should be same as ng-model', function () { - scope.myDate = new Date(2014, 0, 1); - recompile(); - expect(scope.inputForm.inputDate.$viewValue).toBe('2014-01-01'); - scope.myDate = null; - recompile(); - - // NOTE: in Angular 1.3 setting the scope value to null results in the viewValue being an empty string, NOT null - expect(scope.inputForm.inputDate.$viewValue === '' || scope.inputForm.inputDate.$viewValue === null).toEqual(true); - }); - -/* - it('change in input value should update ng-model', function () { - recompile(); - scope.inputForm.inputDate.$setViewValue('1900-01-01'); - recompile(); - expect(scope.myDate.getFullYear()).toBe(1900); - scope.inputForm.inputDate.$setViewValue(null); - recompile(); - expect(scope.myDate).toBeNull(); - }); -*/ - - it('valid date value in ng-model should set $valid to true', function () { - scope.myDate = new Date(2014, 0, 1); - recompile(); - expect(scope.inputForm.$valid).toBe(true, 'valid date'); - }); - - // NOTE(c0bra): This fails with angular 1.3. No idea why. Do we need it? Turning off for now. - // it('invalid date value in ng-model should set $valid to false', function () { - // scope.myDate = new Date(2014, 0, 1); - // recompile(); - // expect(scope.inputForm.$valid).toBe(true); - // scope.myDate = new Date('00-22-2013'); - // recompile(); - // expect(scope.inputForm.$valid).toBe(false); - // scope.myDate = null; - // recompile(); - // expect(scope.inputForm.$valid).toBe(true); - // }); - -}); diff --git a/src/features/empty-base-layer/templates/emptyBaseLayerContainer.html b/src/features/empty-base-layer/templates/emptyBaseLayerContainer.html deleted file mode 100644 index a5e42546be..0000000000 --- a/src/features/empty-base-layer/templates/emptyBaseLayerContainer.html +++ /dev/null @@ -1,13 +0,0 @@ -
-
-
-
-
-
-
-
-
-
diff --git a/src/features/empty-base-layer/test/emptyBaseLayer.spec.js b/src/features/empty-base-layer/test/emptyBaseLayer.spec.js deleted file mode 100644 index 57fd8089a8..0000000000 --- a/src/features/empty-base-layer/test/emptyBaseLayer.spec.js +++ /dev/null @@ -1,94 +0,0 @@ -describe('ui.grid.emptyBaseLayer', function () { - - var scope, element, viewportHeight, emptyBaseLayerContainer, $compile; - - beforeEach(module('ui.grid.emptyBaseLayer')); - - beforeEach(inject(function (_$compile_, $rootScope, $httpBackend) { - - $compile = _$compile_; - scope = $rootScope; - - viewportHeight = "100"; - scope.gridOptions = {}; - scope.gridOptions.data = [ - { col1: 'col1', col2: 'col2' } - ]; - scope.gridOptions.onRegisterApi = function (gridApi) { - scope.gridApi = gridApi; - scope.grid = gridApi.grid; - var renderBodyContainer = scope.grid.renderContainers.body; - spyOn(renderBodyContainer, 'getViewportHeight').and.callFake(function() { - return viewportHeight; - }); - }; - })); - - describe('enabled', function() { - beforeEach(function() { - element = angular.element('
'); - - $compile(element)(scope); - scope.$digest(); - - emptyBaseLayerContainer = angular.element(element.find('.ui-grid-empty-base-layer-container')[0]); - }); - - it('should add emptyBaseLayerContainer to the viewport html', function () { - expect(element.find('.ui-grid-empty-base-layer-container').length).toBe(1); - }); - - it('should add fake rows to the empty base layer container, on building styles', function() { - expect(emptyBaseLayerContainer.children().length).toBe(4); - }); - - it('should increase in rows if viewport height increased', function() { - viewportHeight = "150"; - scope.grid.buildStyles(); - scope.$digest(); - expect(emptyBaseLayerContainer.children().length).toBe(5); - }); - }); - - describe('disabled', function() { - it('should be disabled if we pass false into the directive in the markup', function() { - element = angular.element('
'); - $compile(element)(scope); - scope.$digest(); - emptyBaseLayerContainer = angular.element(element.find('.ui-grid-empty-base-layer-container')[0]); - expect(emptyBaseLayerContainer.children().length).toBe(0); - }); - - it('should be disabled if we pass false as an value through the scope in markup', function() { - scope.enableEmptyBaseLayer = false; - element = angular.element('
'); - $compile(element)(scope); - scope.$digest(); - emptyBaseLayerContainer = angular.element(element.find('.ui-grid-empty-base-layer-container')[0]); - expect(emptyBaseLayerContainer.children().length).toBe(0); - }); - - it('should be disabled if set enableEmptyGridBaseLayer in gridOptions to false', function() { - scope.gridOptions.enableEmptyGridBaseLayer = false; - element = angular.element('
'); - $compile(element)(scope); - scope.$digest(); - emptyBaseLayerContainer = angular.element(element.find('.ui-grid-empty-base-layer-container')[0]); - expect(emptyBaseLayerContainer.children().length).toBe(0); - }); - - it('should not reset the number of rows incase it is disabled', function() { - scope.gridOptions.enableEmptyGridBaseLayer = false; - element = angular.element('
'); - $compile(element)(scope); - scope.$digest(); - emptyBaseLayerContainer = angular.element(element.find('.ui-grid-empty-base-layer-container')[0]); - expect(emptyBaseLayerContainer.children().length).toBe(0); - - viewportHeight = "150"; - scope.grid.buildStyles(); - scope.$digest(); - expect(emptyBaseLayerContainer.children().length).toBe(0); - }); - }); -}); diff --git a/src/features/expandable/templates/expandableRow.html b/src/features/expandable/templates/expandableRow.html deleted file mode 100644 index 91d3d218aa..0000000000 --- a/src/features/expandable/templates/expandableRow.html +++ /dev/null @@ -1,7 +0,0 @@ -
-
diff --git a/src/features/expandable/templates/expandableRowHeader.html b/src/features/expandable/templates/expandableRowHeader.html deleted file mode 100644 index 9429d086a0..0000000000 --- a/src/features/expandable/templates/expandableRowHeader.html +++ /dev/null @@ -1,10 +0,0 @@ -
-
- - -
-
diff --git a/src/features/expandable/templates/expandableScrollFiller.html b/src/features/expandable/templates/expandableScrollFiller.html deleted file mode 100644 index 31088fd1f3..0000000000 --- a/src/features/expandable/templates/expandableScrollFiller.html +++ /dev/null @@ -1,9 +0,0 @@ -
- - -
diff --git a/src/features/expandable/templates/expandableTopRowHeader.html b/src/features/expandable/templates/expandableTopRowHeader.html deleted file mode 100644 index ec63fe78db..0000000000 --- a/src/features/expandable/templates/expandableTopRowHeader.html +++ /dev/null @@ -1,10 +0,0 @@ -
-
- - -
-
diff --git a/src/features/expandable/test/expandable.spec.js b/src/features/expandable/test/expandable.spec.js deleted file mode 100644 index 3d638ca7f3..0000000000 --- a/src/features/expandable/test/expandable.spec.js +++ /dev/null @@ -1,84 +0,0 @@ -describe('ui.grid.expandable', function () { - - var scope, element, timeout; - - beforeEach(module('ui.grid.expandable')); - - beforeEach(inject(function (_$compile_, $rootScope, $timeout, $httpBackend) { - - var $compile = _$compile_; - scope = $rootScope; - timeout = $timeout; - - scope.gridOptions = { - expandableRowTemplate: 'expandableRowTemplate.html', - expandableRowHeight: 150, - expandableRowHeaderWidth: 40 - }; - scope.gridOptions.data = [ - { col1: 'col1', col2: 'col2' } - ]; - scope.gridOptions.onRegisterApi = function (gridApi) { - scope.gridApi = gridApi; - scope.grid = gridApi.grid; - }; - - $httpBackend.when('GET', 'expandableRowTemplate.html').respond("
"); - element = angular.element('
'); - - $timeout(function () { - $compile(element)(scope); - }); - $timeout.flush(); - })); - - it('public api expandable should be well defined', function () { - expect(scope.gridApi.expandable).toBeDefined(); - expect(scope.gridApi.expandable.on.rowExpandedStateChanged).toBeDefined(); - expect(scope.gridApi.expandable.raise.rowExpandedStateChanged).toBeDefined(); - expect(scope.gridApi.expandable.toggleRowExpansion).toBeDefined(); - expect(scope.gridApi.expandable.expandAllRows).toBeDefined(); - expect(scope.gridApi.expandable.collapseAllRows).toBeDefined(); - expect(scope.gridApi.expandable.toggleAllRows).toBeDefined(); - }); - - it('expandAll and collapseAll should set and unset row.isExpanded', function () { - scope.gridApi.expandable.expandAllRows(); - scope.grid.rows.forEach(function(row) { - expect(row.isExpanded).toBe(true); - }); - scope.gridApi.expandable.collapseAllRows(); - scope.grid.rows.forEach(function(row) { - expect(row.isExpanded).toBe(false); - }); - }); - - it('toggleAllRows should set and unset row.isExpanded', function(){ - scope.gridApi.expandable.toggleAllRows(); - scope.grid.rows.forEach(function(row){ - expect(row.isExpanded).toBe(true); - }); - scope.gridApi.expandable.toggleAllRows(); - scope.grid.rows.forEach(function(row){ - expect(row.isExpanded).toBe(false); - }); - }); - - it('event rowExpandedStateChanged should be fired whenever row expands', function () { - var functionCalled = false; - scope.gridApi.expandable.on.rowExpandedStateChanged(scope,function(row){ - functionCalled = true; - }); - scope.gridApi.expandable.toggleRowExpansion(scope.grid.rows[0].entity); - expect(functionCalled).toBe(true); - }); - - it('subgrid should be addeed to the dom when we expand row', function () { - expect(element.find('.test').length).toBe(0); - scope.gridApi.expandable.toggleRowExpansion(scope.grid.rows[0].entity); - scope.$digest(); - timeout(function () { - expect(element.find('.test').length).toBe(1); - }); - }); -}); diff --git a/src/features/exporter/less/exporter.less b/src/features/exporter/less/exporter.less deleted file mode 100644 index d55954b2fa..0000000000 --- a/src/features/exporter/less/exporter.less +++ /dev/null @@ -1,4 +0,0 @@ -@import '../../../less/variables'; - -.ui-grid-exporter-header { -} diff --git a/src/features/exporter/templates/csvLink.html b/src/features/exporter/templates/csvLink.html deleted file mode 100644 index 86c91346e0..0000000000 --- a/src/features/exporter/templates/csvLink.html +++ /dev/null @@ -1,8 +0,0 @@ - - - LINK_LABEL - - diff --git a/src/features/exporter/test/exporter.spec.js b/src/features/exporter/test/exporter.spec.js deleted file mode 100644 index d13fb3d8a1..0000000000 --- a/src/features/exporter/test/exporter.spec.js +++ /dev/null @@ -1,520 +0,0 @@ -describe('ui.grid.exporter uiGridExporterService', function () { - var uiGridExporterService; - var uiGridSelectionService; - var uiGridExporterConstants; - var uiGridSelectionConstants; - var gridClassFactory; - var grid; - var $compile; - var $scope; - var $document; - - beforeEach(module('ui.grid.exporter', 'ui.grid.selection', 'ui.grid.pinning')); - - - beforeEach(inject(function (_uiGridExporterService_, _uiGridSelectionService_, _uiGridPinningService_, _gridClassFactory_, _uiGridExporterConstants_, - _uiGridPinningConstants_, - _$compile_, _$rootScope_, _$document_, _uiGridSelectionConstants_) { - uiGridExporterService = _uiGridExporterService_; - uiGridSelectionService = _uiGridSelectionService_; - uiGridExporterConstants = _uiGridExporterConstants_; - gridClassFactory = _gridClassFactory_; - $compile = _$compile_; - $scope = _$rootScope_.$new(); - $document = _$document_; - uiGridSelectionConstants = _uiGridSelectionConstants_; - - grid = gridClassFactory.createGrid({}); - grid.options.columnDefs = [ - {field: 'col1', name: 'col1', displayName: 'Col1', width: 50, pinnedLeft: true}, - {field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number', cellFilter: 'uppercase'}, - {field: 'col3', name: 'col3', displayName: 'Col3', width: 100}, - {field: 'col4', name: 'col4', displayName: 'Col4', width: 200} - ]; - - _uiGridExporterService_.initializeGrid(grid); - _uiGridSelectionService_.initializeGrid(grid); - _uiGridPinningService_.initializeGrid(grid); - var data = []; - for (var i = 0; i < 3; i++) { - data.push({col1:'a_'+i, col2:'b_'+i, col3:'c_'+i, col4:'d_'+i}); - } - grid.options.data = data; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - grid.rows[1].visible = false; - grid.columns[2].visible = false; - grid.setVisibleRows(grid.rows); - grid.setVisibleColumns(grid.columns); - - grid.api.selection.clearSelectedRows(); - grid.api.selection.selectRow(grid.rows[0].entity); - - grid.gridWidth = 500; - grid.columns[0].drawnWidth = 50; - grid.columns[1].drawnWidth = '*'; - grid.columns[2].drawnWidth = 100; - grid.columns[3].drawnWidth = 200; - - })); - - - describe('defaultGridOptions', function() { - var options; - beforeEach(function() { - options = {}; - }); - - it('set all options to default', function() { - uiGridExporterService.defaultGridOptions(options); - expect( options ).toEqual({ - exporterSuppressMenu: false, - exporterMenuLabel: 'Export', - exporterCsvColumnSeparator: ',', - exporterCsvFilename: 'download.csv', - exporterPdfFilename: 'download.pdf', - exporterOlderExcelCompatibility: false, - exporterIsExcelCompatible: false, - exporterPdfDefaultStyle : { fontSize : 11 }, - exporterPdfTableStyle : { margin : [ 0, 5, 0, 15 ] }, - exporterPdfTableHeaderStyle : { bold : true, fontSize : 12, color : 'black' }, - exporterPdfHeader: null, - exporterPdfFooter: null, - exporterPdfOrientation : 'landscape', - exporterPdfPageSize : 'A4', - exporterPdfMaxGridWidth : 720, - exporterPdfCustomFormatter: jasmine.any(Function), - exporterHeaderFilterUseName: false, - exporterMenuAllData: true, - exporterMenuVisibleData: true, - exporterMenuSelectedData: true, - exporterMenuCsv: true, - exporterMenuPdf: true, - exporterFieldCallback: jasmine.any(Function), - exporterAllDataFn: null, - exporterSuppressColumns: [], - exporterMenuItemOrder: 200 - }); - }); - - it('set all options to non-default, including using deprecated exporterAllDataPromise', function() { - var callback = function() {}; - options = { - exporterSuppressMenu: true, - exporterMenuLabel: 'custom export button', - exporterCsvColumnSeparator: ';', - exporterCsvFilename: 'myfile.csv', - exporterPdfFilename: 'myfile.pdf', - exporterOlderExcelCompatibility: true, - exporterIsExcelCompatible: true, - exporterPdfDefaultStyle : { fontSize : 12 }, - exporterPdfTableStyle : { margin : [ 15, 5, 15, 15 ] }, - exporterPdfTableHeaderStyle : { bold : false, fontSize : 12, color : 'green' }, - exporterPdfHeader: "My Header", - exporterPdfFooter: "My Footer", - exporterPdfOrientation : 'portrait', - exporterPdfPageSize : 'LETTER', - exporterPdfMaxGridWidth : 670, - exporterPdfCustomFormatter: callback, - exporterHeaderFilterUseName: true, - exporterMenuAllData: false, - exporterMenuVisibleData: false, - exporterMenuSelectedData: false, - exporterMenuCsv: false, - exporterMenuPdf: false, - exporterFieldCallback: callback, - exporterAllDataPromise: callback, - exporterSuppressColumns: [ 'buttons' ], - exporterMenuItemOrder: 75 - }; - uiGridExporterService.defaultGridOptions(options); - expect( options ).toEqual({ - exporterSuppressMenu: true, - exporterMenuLabel: 'custom export button', - exporterCsvColumnSeparator: ';', - exporterCsvFilename: 'myfile.csv', - exporterPdfFilename: 'myfile.pdf', - exporterOlderExcelCompatibility: true, - exporterIsExcelCompatible: true, - exporterPdfDefaultStyle : { fontSize : 12 }, - exporterPdfTableStyle : { margin : [ 15, 5, 15, 15 ] }, - exporterPdfTableHeaderStyle : { bold : false, fontSize : 12, color : 'green' }, - exporterPdfHeader: "My Header", - exporterPdfFooter: "My Footer", - exporterPdfOrientation : 'portrait', - exporterPdfPageSize : 'LETTER', - exporterPdfMaxGridWidth : 670, - exporterPdfCustomFormatter: callback, - exporterHeaderFilterUseName: true, - exporterMenuAllData: false, - exporterMenuVisibleData: false, - exporterMenuSelectedData: false, - exporterMenuCsv: false, - exporterMenuPdf: false, - exporterFieldCallback: callback, - exporterAllDataFn: callback, - exporterAllDataPromise: callback, - exporterSuppressColumns: [ 'buttons' ], - exporterMenuItemOrder: 75 - }); - }); - }); - - - describe('getColumnHeaders', function() { - it('gets visible headers', function() { - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.VISIBLE)).toEqual([ - {name: 'col1', displayName: 'Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'Col2', width: '*', align: 'right'}, - {name: 'col4', displayName: 'Col4', width: 200, align: 'left'} - ]); - }); - - it('gets all headers', function() { - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.ALL)).toEqual([ - {name: 'col1', displayName: 'Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'Col2', width: '*', align: 'right'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'col4', displayName: 'Col4', width: 200, align: 'left'} - ]); - }); - - it('ignores suppressed columns', function() { - grid.columns[0].colDef.exporterSuppressExport = true; - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.ALL)).toEqual([ - {name: 'col2', displayName: 'Col2', width: '*', align: 'right'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'col4', displayName: 'Col4', width: 200, align: 'left'} - ]); - }); - - it('ignores suppressed header', function() { - grid.options.exporterSuppressColumns = [ 'col1']; - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.ALL)).toEqual([ - {name: 'col2', displayName: 'Col2', width: '*', align: 'right'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'col4', displayName: 'Col4', width: 200, align: 'left'} - ]); - }); - - it('gets all headers using headerFilter', function() { - grid.options.exporterHeaderFilter = function( displayName ){ return "mapped_" + displayName; }; - - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.ALL)).toEqual([ - {name: 'col1', displayName: 'mapped_Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'mapped_Col2', width: '*', align: 'right'}, - {name: 'col3', displayName: 'mapped_Col3', width: 100, align: 'left'}, - {name: 'col4', displayName: 'mapped_Col4', width: 200, align: 'left'} - ]); - }); - - it('gets all headers using headerFilter, passing name not displayName', function() { - grid.options.exporterHeaderFilterUseName = true; - grid.options.exporterHeaderFilter = function( name ){ return "mapped_" + name; }; - - expect(uiGridExporterService.getColumnHeaders(grid, uiGridExporterConstants.ALL)).toEqual([ - {name: 'col1', displayName: 'mapped_col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'mapped_col2', width: '*', align: 'right'}, - {name: 'col3', displayName: 'mapped_col3', width: 100, align: 'left'}, - {name: 'col4', displayName: 'mapped_col4', width: 200, align: 'left'} - ]); - }); - }); - - - describe('getData', function() { - it('gets all rows and columns', function() { - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL)).toEqual([ - [ {value: 'a_0'}, {value: 'b_0'}, {value: 'c_0'}, {value: 'd_0'} ], - [ {value: 'a_1'}, {value: 'b_1'}, {value: 'c_1'}, {value: 'd_1'} ], - [ {value: 'a_2'}, {value: 'b_2'}, {value: 'c_2'}, {value: 'd_2'} ] - ]); - }); - - it('ignores selection row header column', function() { - grid.columns[0].colDef.exporterSuppressExport = true; - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL)).toEqual([ - [ {value: 'b_0'}, {value: 'c_0'}, {value: 'd_0'} ], - [ {value: 'b_1'}, {value: 'c_1'}, {value: 'd_1'} ], - [ {value: 'b_2'}, {value: 'c_2'}, {value: 'd_2'} ] - ]); - }); - - it('ignores suppressed column', function() { - grid.options.exporterSuppressColumns = [ 'col1' ]; - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL)).toEqual([ - [ {value: 'b_0'}, {value: 'c_0'}, {value: 'd_0'} ], - [ {value: 'b_1'}, {value: 'c_1'}, {value: 'd_1'} ], - [ {value: 'b_2'}, {value: 'c_2'}, {value: 'd_2'} ] - ]); - }); - - it('ignores disabled row', function() { - grid.rows[1].exporterEnableExporting = false; - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL)).toEqual([ - [ {value: 'a_0'}, {value: 'b_0'}, {value: 'c_0'}, {value: 'd_0'} ], - [ {value: 'a_2'}, {value: 'b_2'}, {value: 'c_2'}, {value: 'd_2'} ] - ]); - }); - - it('gets visible rows and columns', function() { - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE)).toEqual([ - [ {value: 'a_0'}, {value: 'b_0'}, {value: 'd_0'} ], - [ {value: 'a_2'}, {value: 'b_2'}, {value: 'd_2'} ] - ]); - }); - - it('gets selected rows and visible columns', function() { - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE)).toEqual([ - [ {value: 'a_0'}, {value: 'b_0'}, {value: 'd_0'} ] - ]); - }); - - it('gets the rows display values', function() { - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL, true)).toEqual([ - [ {value: 'a_0'}, {value: 'B_0'}, {value: 'c_0'}, {value: 'd_0'} ], - [ {value: 'a_1'}, {value: 'B_1'}, {value: 'c_1'}, {value: 'd_1'} ], - [ {value: 'a_2'}, {value: 'B_2'}, {value: 'c_2'}, {value: 'd_2'} ] - ]); - }); - - it('maps data using objectCallback', function() { - grid.options.exporterFieldCallback = function( grid, row, col, value ){ - if ( col.name === 'col2' ){ - return 'translated'; - } else { - return value; - } - }; - - expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL)).toEqual([ - [ { value: 'a_0' }, { value: 'translated' }, { value: 'c_0' }, { value: 'd_0' } ], - [ { value: 'a_1' }, { value: 'translated' }, { value: 'c_1' }, { value: 'd_1' } ], - [ { value: 'a_2' }, { value: 'translated' }, { value: 'c_2' }, { value: 'd_2' } ] - ]); - }); - }); - - - describe('formatAsCsv', function() { - it('formats empty data as a csv', function() { - var columnHeaders = []; - var data = []; - var separator = ','; - - expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual( - "" - ); - }); - - it('formats a mix of data as a csv', function() { - var columnHeaders = [ - {name: 'col1', displayName: 'Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'Col2', width: '*', align: 'left'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'x', displayName: '12345234', width: 200, align: 'left'} - ]; - - var date = new Date(2014, 11, 12, 0, 0, 0, 0); - - var data = [ - [ {value: 'a string'}, {value: 'a string'}, {value: 'A string'}, {value: 'a string'} ], - [ {value: ''}, {value: '45'}, {value: 'A string'}, {value: false} ], - [ {value: date}, {value: 45}, {value: 'A string'}, {value: true} ] - ]; - - var separator = ','; - - expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual( - '"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"' + date.toISOString() + '",45,"A string",TRUE' - ); - }); - - it('formats a mix of data as a csv with custom separator', function() { - var columnHeaders = [ - {name: 'col1', displayName: 'Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'Col2', width: '*', align: 'left'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'x', displayName: '12345234', width: 200, align: 'left'} - ]; - - var date = new Date(2014, 11, 12, 0, 0, 0, 0); - - var data = [ - [ {value: 'a string'}, {value: 'a string'}, {value: 'A string'}, {value: 'a string'} ], - [ {value: ''}, {value: '45'}, {value: 'A string'}, {value: false} ], - [ {value: date}, {value: 45}, {value: 'A string'}, {value: true} ] - ]; - - var separator = ';'; - - expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual( - '"Col1";"Col2";"Col3";"12345234"\n"a string";"a string";"A string";"a string"\n"";"45";"A string";FALSE\n"' + date.toISOString() + '";45;"A string";TRUE' - ); - }); - }); - - describe( 'prepareAsPdf', function() { - it( 'prepares standard grid using defaults', function() { - /* - * Note that you can test the results from prepareAsPdf using - * http://pdfmake.org/playground.html#, which verifies - * that it creates a genuine pdf - */ - var columnHeaders = [ - {name: 'col1', displayName: 'Col1', width: 50, align: 'left'}, - {name: 'col2', displayName: 'Col2', width: '*', align: 'left'}, - {name: 'col3', displayName: 'Col3', width: 100, align: 'left'}, - {name: 'x', displayName: '12345234', width: 200, align: 'left'} - ]; - - var date = new Date(2014, 11, 12, 0, 0, 0, 0); - - var data = [ - [ {value: 'a string'}, {value: 'a string'}, {value: 'A string'}, {value: 'a string'} ], - [ {value: ''}, {value: '45'}, {value: 'A string'}, {value: false} ], - [ {value: date}, {value: 45}, {value: 'A string'}, {value: true} ] - ]; - - var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data); - expect(result).toEqual({ - pageOrientation : 'landscape', - pageSize: 'A4', - content : [{ - style : 'tableStyle', - table : { - headerRows : 1, - widths: [50 * 720/450, '*', 100 * 720/450, 200 * 720/450], - body : [ - [ - { text : 'Col1', style : 'tableHeader' }, - { text : 'Col2', style : 'tableHeader' }, - { text : 'Col3', style : 'tableHeader' }, - { text : '12345234', style : 'tableHeader' } - ], - [ 'a string', 'a string', 'A string', 'a string' ], - [ '', '45', 'A string', 'FALSE' ], - [ date.toISOString(), '45', 'A string', 'TRUE' ] - ] - } - }], - styles : { - tableStyle : { - margin : [ 0, 5, 0, 15 ] - }, - tableHeader : { - bold : true, fontSize : 12, color : 'black' - } - }, - defaultStyle : { - fontSize : 11 - } - }); - - }); - - it( 'prepares standard grid using overrides', function() { - /* - * Note that you can test the results from prepareAsPdf using - * http://pdfmake.org/playground.html#, which verifies - * that it creates a genuine pdf - */ - - grid.options.exporterPdfDefaultStyle = {fontSize: 10}; - grid.options.exporterPdfTableStyle = {margin: [30, 30, 30, 30]}; - grid.options.exporterPdfTableHeaderStyle = {fontSize: 11, bold: true, italic: true}; - grid.options.exporterPdfHeader = "My Header"; - grid.options.exporterPdfFooter = "My Footer"; - grid.options.exporterPdfCustomFormatter = function ( docDefinition ) { - docDefinition.styles.headerStyle = { fontSize: 10 }; - return docDefinition; - }; - grid.options.exporterPdfOrientation = 'portrait'; - grid.options.exporterPdfPageSize = 'LETTER'; - grid.options.exporterPdfMaxGridWidth = 500; - - var columnHeaders = [ - {name: 'col1', displayName: 'Col1', width: 100, exporterPdfAlign: 'right'}, - {name: 'col2', displayName: 'Col2', width: '*', exporterPdfAlign: 'left'}, - {name: 'col3', displayName: 'Col3', width: 100, exporterPdfAlign: 'center'}, - {name: 'x', displayName: '12345234', width: 200, align: 'left'} - ]; - - var date = new Date(2014, 12, 12, 0, 0, 0, 0); - - var data = [ - [ {value: 'a string', alignment: 'right'}, {value: 'a string', alignment: 'center'}, {value: 'A string', alignment: 'left'}, {value: 'a string'} ], - [ {value: '', alignment: 'right'}, {value: '45', alignment: 'center'}, {value: 'A string', alignment: 'left'}, {value: false} ], - [ {value: date, alignment: 'right'}, {value: 45, alignment: 'center'}, {value: 'A string', alignment: 'left'}, {value: true} ] - ]; - - var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data); - expect(result).toEqual({ - pageOrientation : 'portrait', - pageSize: 'LETTER', - content : [ - { - style : 'tableStyle', - table : { - headerRows : 1, - widths : [ 100, '*', 100, 200 ], - body : [ - [ - { text : 'Col1', style : 'tableHeader' }, - { text : 'Col2', style : 'tableHeader' }, - { text : 'Col3', style : 'tableHeader' }, - { text : '12345234', style : 'tableHeader' } - ], - [ {text: 'a string', alignment: 'right'}, { text: 'a string', alignment: 'center'}, { text: 'A string', alignment: 'left'}, 'a string' ], - [ {text: '', alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'FALSE' ], - [ {text: date.toISOString(), alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'TRUE' ] - ] - } - } - ], - header : "My Header", - footer : "My Footer", - styles : { - tableStyle : { - margin : [ 30, 30, 30, 30 ] - }, - tableHeader : { - fontSize : 11, bold : true, italic : true - }, - headerStyle: { fontSize: 10 } - }, - defaultStyle : { - fontSize : 10 - } - }); - - }); - }); - - describe( 'calculatePdfHeaderWidths', function() { - it( 'calculates mix of widths', function() { - var headers = [ - { width: '20%' }, - { width: '*' }, - { width: 150 }, - { width: 200 }, - { width: 150 }, - { width: 100 } - ]; - - grid.options.exporterPdfMaxGridWidth = 410; - - // baseGridWidth = 600 - // extra 120 for 20% - // extra 100 for '*' - // total gridWidth 820 - - - expect(uiGridExporterService.calculatePdfHeaderWidths( grid, headers)).toEqual( - [60, '*', 75, 100, 75, 50] - ); - }); - }); - -}); diff --git a/src/features/grouping/test/grouping.spec.js b/src/features/grouping/test/grouping.spec.js deleted file mode 100644 index 3cc0b4701a..0000000000 --- a/src/features/grouping/test/grouping.spec.js +++ /dev/null @@ -1,685 +0,0 @@ -describe('ui.grid.grouping uiGridGroupingService', function () { - var uiGridGroupingService; - var uiGridGroupingConstants; - var uiGridTreeBaseService; - var gridClassFactory; - var grid; - var $rootScope; - var $scope; - var GridRow; - var $timeout; - - beforeEach(module('ui.grid.grouping')); - - beforeEach(inject(function (_uiGridGroupingService_,_gridClassFactory_, $templateCache, _uiGridGroupingConstants_, - _$rootScope_, _GridRow_, _uiGridTreeBaseService_,_$timeout_) { - uiGridGroupingService = _uiGridGroupingService_; - uiGridGroupingConstants = _uiGridGroupingConstants_; - gridClassFactory = _gridClassFactory_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - GridRow = _GridRow_; - uiGridTreeBaseService = _uiGridTreeBaseService_; - $timeout = _$timeout_; - - $templateCache.put('ui-grid/uiGridCell', '
'); - $templateCache.put('ui-grid/editableCell', '
'); - - grid = gridClassFactory.createGrid({}); - grid.options.columnDefs = [ - {field: 'col0', enableGrouping: true}, - {field: 'col1', enableGrouping: true}, - {field: 'col2', enableGrouping: true}, - {field: 'col3', enableGrouping: true}, - {field: 'col4', enableGrouping: true, type: 'date'} - ]; - - uiGridGroupingService.initializeGrid(grid, $scope); - var data = []; - for (var i = 0; i < 10; i++) { - - data.push({ - col0: 'a_' + Math.floor(i/4), - col1: 'b_' + Math.floor(i/2), - col2: 'c_' + i, - col3: 'd_' + i, - col4: i > 5 ? new Date(2015, 6, 1) : null - }); - } - grid.options.data = data; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - })); - - - describe( 'tidySortPriority', function() { - it( 'no group columns, no sort columns, no errors', function() { - uiGridGroupingService.tidyPriorities( grid ); - }); - - it( 'some group columns, some sort columns, tidies correctly', function() { - grid.columns[0].sort = { priority: 1}; - grid.columns[0].grouping = { groupPriority: 3}; - grid.columns[1].sort = {priority: 9}; - grid.columns[2].sort = {priority: 1}; - grid.columns[2].grouping = { groupPriority: 2 }; - grid.columns[3].sort = {priority: 0}; - - uiGridGroupingService.tidyPriorities( grid ); - expect(grid.columns[2].grouping.groupPriority).toEqual(0, 'column 2 groupPriority'); - expect(grid.columns[2].sort.priority).toEqual(0, 'column 2 sort priority'); - expect(grid.columns[0].grouping.groupPriority).toEqual(1, 'column 0 groupPriority'); - expect(grid.columns[0].sort.priority).toEqual(1, 'column 0 sort priority'); - expect(grid.columns[3].sort.priority).toEqual(2, 'column 3 sort priority'); - expect(grid.columns[1].sort.priority).toEqual(3, 'column 1 sort priority'); - }); - }); - - - describe( 'moveGroupColumns', function() { - it( 'move some columns left, and some columns right', function() { - // TODO - }); - - it( 'will not move header columns', function() { - - $timeout(function () { - grid.addRowHeaderColumn({name:'aRowHeader'}, -200); - }); - $timeout.flush(); - - - grid.columns[2].renderContainer = 'left'; - grid.columns[2].sort = { priority: 1}; - grid.columns[2].grouping = { groupPriority: 1}; - uiGridGroupingService.moveGroupColumns(grid,grid.columns,grid.rows); - expect(grid.columns[0].colDef.name).toBe('aRowHeader'); - - - }); - }); - - - describe('groupColumn', function() { - it('saves previous sort state', function() { - grid.columns[1].sort = { priority: 42, direction: 'foo'}; - uiGridGroupingService.groupColumn(grid, grid.columns[1]); - expect(grid.columns[1].previousSort.priority).toBe(42); - expect(grid.columns[1].previousSort.direction).toBe('foo'); - }); - }); - - describe('ungroupColumn', function() { - it('restores previuosly restored state if there is one', function() { - grid.columns[1].previousSort = { direction: 'bar'}; - uiGridGroupingService.ungroupColumn(grid, grid.columns[1]); - expect(grid.columns[1].sort.direction).toBe('bar'); - }); - - it('should remove previous sort prop from column object after column sort is restored', function() { - grid.columns[1].previousSort = {direction: 'bar'}; - uiGridGroupingService.ungroupColumn(grid, grid.columns[1]); - expect(grid.columns[1].previousSort).toBeUndefined(); - }); - }); - - - describe( 'groupRows', function() { - beforeEach(function() { - spyOn(gridClassFactory, 'rowTemplateAssigner').and.callFake( function() {}); - }); - - it( 'group by col0 then col1', function() { - - grid.columns[0].grouping = { groupPriority: 1 }; - grid.columns[1].grouping = { groupPriority: 2 }; - - var groupedRows = uiGridGroupingService.groupRows.call( grid, grid.rows.slice(0) ); - expect( groupedRows.length ).toEqual( 18, 'all rows are present, including the added group headers' ); - }); - - it( 'group by col4 (type date with nulls)', function() { - grid.columns[4].grouping = { groupPriority: 1 }; - - uiGridGroupingService.tidyPriorities(grid); - var groupedRows = uiGridGroupingService.groupRows.call( grid, grid.rows.slice(0) ); - expect( groupedRows.length ).toEqual( 12, 'all rows are present, including two group header rows' ); - }); - }); - - describe('initialiseProcessingState', function() { - it('no grouping', function() { - grid.columns[1].grouping = {}; - grid.columns[3].grouping = {}; - - expect(uiGridGroupingService.initialiseProcessingState(grid)).toEqual([ - ]); - }); - - it('groupingShowCounts', function() { - grid.columns[1].grouping = {groupPriority: 3}; - grid.columns[3].grouping = {groupPriority: 2}; - grid.options.groupingShowCounts = true; - - var result = uiGridGroupingService.initialiseProcessingState(grid); - expect(result[0].col).toEqual(grid.columns[3]); - delete result[0].col; - expect(result[1].col).toEqual(grid.columns[1]); - delete result[1].col; - - expect(result).toEqual([ - { fieldName: 'col3', initialised: false, currentValue: null, currentRow: null }, - { fieldName: 'col1', initialised: false, currentValue: null, currentRow: null } - ]); - }); - - it('without groupingShowCounts', function() { - grid.columns[1].grouping = {groupPriority: 3}; - grid.columns[3].grouping = {groupPriority: 2}; - grid.options.groupingShowCounts = false; - - var result = uiGridGroupingService.initialiseProcessingState(grid); - expect(result[0].col).toEqual(grid.columns[3]); - delete result[0].col; - expect(result[1].col).toEqual(grid.columns[1]); - delete result[1].col; - - expect(result).toEqual([ - { fieldName: 'col3', initialised: false, currentValue: null, currentRow: null }, - { fieldName: 'col1', initialised: false, currentValue: null, currentRow: null } - ]); - }); - - it('mixture of settings', function() { - grid.columns[0].grouping = {}; - grid.columns[1].grouping = {groupPriority: 3}; - grid.columns[2].grouping = {}; - grid.columns[3].grouping = {groupPriority: 2}; - grid.options.groupingShowCounts = true; - - // when expected results go wrong the messages suck if columns are in the results...so check them individually then delete them out - var result = uiGridGroupingService.initialiseProcessingState(grid); - expect(result[0].col).toEqual(grid.columns[3]); - delete result[0].col; - expect(result[1].col).toEqual(grid.columns[1]); - delete result[1].col; - expect(result).toEqual([ - { fieldName: 'col3', initialised: false, currentValue: null, currentRow: null }, - { fieldName: 'col1', initialised: false, currentValue: null, currentRow: null } - ]); - }); - }); - - - describe('getGrouping', function() { - it('should find no grouping', function() { - expect(uiGridGroupingService.getGrouping(grid)).toEqual({ - grouping: [], - aggregations: [] - }); - }); - - it('finds one grouping', function() { - grid.columns[1].grouping = {groupPriority: 0}; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.grouping[0].col.name).toEqual('col1'); - delete grouping.grouping[0].col; - - expect(grouping).toEqual({ - grouping: [{ field: 'col1', groupPriority: 0 }], - aggregations: [] - }); - }); - - it('finds one aggregation, has no priority', function() { - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.aggregations[0].col.name ).toEqual('col1'); - delete grouping.aggregations[0].col; - - expect( grouping ).toEqual({ - grouping: [], - aggregations: [ { field: 'col1', aggregation: { type: 'count' } } ] - }); - }); - - it('finds one aggregation, has a priority', function() { - grid.columns[1].grouping = {groupPriority: 0}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.grouping[0].col.name).toEqual('col1'); - delete grouping.grouping[0].col; - expect( grouping.aggregations[0].col.name).toEqual('col1'); - delete grouping.aggregations[0].col; - - expect(grouping).toEqual({ - grouping: [{ field: 'col1', groupPriority: 0 }], - aggregations: [ { field: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } } ] - }); - }); - - it('finds one aggregation, has no priority, aggregation is stored', function() { - grid.columns[1].grouping = {groupPriority: -1}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.aggregations[0].col.name).toEqual('col1'); - delete grouping.aggregations[0].col; - - expect(grouping).toEqual({ - grouping: [], - aggregations: [ { field: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } } ] - }); - }); - - it('multiple finds, sorts correctly', function() { - grid.columns[1].grouping = {}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - grid.columns[2].grouping = {groupPriority: 1}; - grid.columns[3].grouping = {groupPriority: 0}; - grid.columns[3].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.grouping[0].col.name).toEqual('col3'); - delete grouping.grouping[0].col; - expect( grouping.grouping[1].col.name).toEqual('col2'); - delete grouping.grouping[1].col; - expect( grouping.aggregations[0].col.name).toEqual('col1'); - delete grouping.aggregations[0].col; - expect( grouping.aggregations[1].col.name).toEqual('col3'); - delete grouping.aggregations[1].col; - - expect(grouping).toEqual({ - grouping: [ - { field: 'col3', groupPriority: 0 }, - { field: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT} }, - { field: 'col3', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT} } - ] - }); - }); - - it('different multiple finds, sorts correctly', function() { - grid.columns[1].grouping = {groupPriority: 0}; - grid.columns[2].grouping = {groupPriority: 2}; - grid.columns[3].grouping = {groupPriority: 1}; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.grouping[0].col.name).toEqual('col1'); - delete grouping.grouping[0].col; - expect( grouping.grouping[1].col.name).toEqual('col3'); - delete grouping.grouping[1].col; - expect( grouping.grouping[2].col.name).toEqual('col2'); - delete grouping.grouping[2].col; - - expect(grouping).toEqual({ - grouping: [ - { field: 'col1', groupPriority: 0 }, - { field: 'col3', groupPriority: 1 }, - { field: 'col2', groupPriority: 2 } - ], - aggregations: [] - }); - }); - - it('renumbers non-contiguous grouping', function() { - grid.columns[1].grouping = {groupPriority: 2}; - grid.columns[2].grouping = {groupPriority: 6}; - grid.columns[3].grouping = {groupPriority: 4}; - - var grouping = uiGridGroupingService.getGrouping(grid); - - expect( grouping.grouping[0].col.name).toEqual('col1'); - delete grouping.grouping[0].col; - expect( grouping.grouping[1].col.name).toEqual('col3'); - delete grouping.grouping[1].col; - expect( grouping.grouping[2].col.name).toEqual('col2'); - delete grouping.grouping[2].col; - - expect(grouping).toEqual({ - grouping: [ - { field: 'col1', groupPriority: 0 }, - { field: 'col3', groupPriority: 1 }, - { field: 'col2', groupPriority: 2 } - ], - aggregations: [] - }); - }); - }); - - - describe('getGrouping via api (returns colName)', function() { - it('should find no grouping', function() { - expect(grid.api.grouping.getGrouping( true )).toEqual({ - grouping: [], - aggregations: [], - rowExpandedStates: {} - }); - }); - - it('should find no grouping', function() { - expect(grid.api.grouping.getGrouping( false )).toEqual({ - grouping: [], - aggregations: [] - }); - }); - - it('should find no grouping, expanded states present', function() { - grid.grouping.groupingHeaderCache = { male: { row: { treeNode: { state: 'expanded' } } } }; - - expect(grid.api.grouping.getGrouping( true )).toEqual({ - grouping: [], - aggregations: [], - rowExpandedStates: { male: { state: 'expanded', children: {} } } - }); - }); - - it('finds one grouping', function() { - grid.columns[1].grouping = {groupPriority: 0}; - expect(grid.api.grouping.getGrouping(true)).toEqual({ - grouping: [{ field: 'col1', colName: 'col1', groupPriority: 0 }], - aggregations: [], - rowExpandedStates: {} - }); - }); - - it('finds one aggregation, has no priority', function() { - grid.columns[1].grouping = {}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - expect(grid.api.grouping.getGrouping(false)).toEqual({ - grouping: [], - aggregations: [{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT} } ] - }); - }); - - it('finds one aggregation, has a priority, aggregation is not ignored', function() { - grid.columns[1].grouping = {groupPriority: 0}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - expect(grid.api.grouping.getGrouping(false)).toEqual({ - grouping: [{ field: 'col1', colName: 'col1', groupPriority: 0 }], - aggregations: [{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT} } ] - }); - }); - - it('finds one aggregation, has no priority, aggregation is stored', function() { - grid.columns[1].grouping = {groupPriority: -1}; - grid.columns[1].treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT }; - expect(grid.api.grouping.getGrouping(false)).toEqual({ - grouping: [], - aggregations: [{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT} } ] - }); - }); - - it('multiple finds, sorts correctly', function() { - grid.columns[1].treeAggregation = {type: uiGridGroupingConstants.aggregation.COUNT}; - grid.columns[2].grouping = {groupPriority: 1}; - grid.columns[3].grouping = {groupPriority: 0}; - grid.columns[3].treeAggregation = {type: uiGridGroupingConstants.aggregation.COUNT}; - expect(grid.api.grouping.getGrouping(false)).toEqual({ - grouping: [ - { field: 'col3', colName: 'col3', groupPriority: 0 }, - { field: 'col2', colName: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }, - { field: 'col3', colName: 'col3', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } } - ] - }); - }); - }); - - - describe('setGrouping', function() { - it('no grouping', function() { - grid.api.grouping.setGrouping( - {} - ); - expect(grid.api.grouping.getGrouping( true )).toEqual( - { grouping: [], aggregations: [], rowExpandedStates: {} } - ); - }); - - it('grouping, aggregations and rowExpandedStates', function() { - grid.grouping.groupingHeaderCache = { - male: { - row: { treeNode: { state: 'collapsed' } }, - children: { - 22: { row: { treeNode: { state: 'expanded' } }, children: {} }, - 39: { row: { treeNode: { state: 'collapsed' } }, children: {} } - } - }, - female: { - row: { treeNode: { state: 'expanded' } }, - children: { - 23: { row: { treeNode: { state: 'collapsed' } }, children: {} }, - 38: { row: { treeNode: { state: 'expanded' } }, children: {} } - } - } - }; - - grid.api.grouping.setGrouping({ - grouping: [ - { field: 'col3', colName: 'col3', groupPriority: 0 }, - { field: 'col2', colName: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } } - ], - rowExpandedStates: { - male: { state: 'expanded', children: { - 22: { state: 'collapsed' }, - 38: { state: 'expanded' } - } }, - female: { state: 'expanded', children: { - 23: { state: 'expanded' }, - 39: { state: 'collapsed' } - } } - } - }); - expect(grid.api.grouping.getGrouping(true)).toEqual({ - grouping: [ - { field: 'col3', colName: 'col3', groupPriority: 0 }, - { field: 'col2', colName: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT, label: uiGridTreeBaseService.nativeAggregations().count.label } } - ], - rowExpandedStates: { - male: { state: 'expanded', children: { - 22: { state: 'collapsed', children: {} }, - 39: { state: 'collapsed', children: {} } - } }, - female: { state: 'expanded', children: { - 23: { state: 'expanded', children: {} }, - 38: { state: 'expanded', children: {} } - } } - } - }); - }); - - - describe('sorts', function(){ - beforeEach(function() { - spyOn(grid.api.core.raise, 'sortChanged').and.callThrough(); - }); - - it('', function() { - grid.grouping.groupingHeaderCache = { - male: { - row: { treeNode: { state: 'collapsed' } }, - children: { - 22: { row: { treeNode: { state: 'expanded' } }, children: {} }, - 39: { row: { treeNode: { state: 'collapsed' } }, children: {} } - } - }, - female: { - row: { treeNode: { state: 'expanded' } }, - children: { - 23: { row: { treeNode: { state: 'collapsed' } }, children: {} }, - 38: { row: { treeNode: { state: 'expanded' } }, children: {} } - } - } - }; - - - grid.api.grouping.setGrouping({ - grouping: [ - { field: 'col3', colName: 'col3', groupPriority: 0 }, - { field: 'col2', colName: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } } - ], - rowExpandedStates: { - male: { state: 'expanded', children: { - 22: { state: 'collapsed' }, - 38: { state: 'expanded' } - } }, - female: { state: 'expanded', children: { - 23: { state: 'expanded' }, - 39: { state: 'collapsed' } - } } - } - }); - - // Should call sort change twice because we are grouping by two columns - expect(grid.api.core.raise.sortChanged.calls.count()).toEqual(2); - }); - - }); - - }); - - - describe('clearGrouping', function() { - it('no grouping', function() { - grid.api.grouping.setGrouping( - {} - ); - - // really just checking there are no errors, it should do nothing - grid.api.grouping.clearGrouping(); - - expect(grid.api.grouping.getGrouping( true )).toEqual( - { grouping: [], aggregations: [], rowExpandedStates: {} } - ); - }); - - it('clear grouping, aggregations and rowExpandedStates', function() { - grid.grouping.groupingHeaderCache = { - male: { row: { treeNode: { state: 'collapsed' } } } - }; - - grid.api.grouping.setGrouping({ - grouping: [ - { field: 'col3', colName: 'col3', groupPriority: 0 }, - { field: 'col2', colName: 'col2', groupPriority: 1 } - ], - aggregations: [ - { field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT }} - ], - rowExpandedStates: { male: { state: 'expanded' } } - }); - - grid.api.grouping.clearGrouping(); - - expect(grid.api.grouping.getGrouping( true )).toEqual( - { grouping: [], aggregations: [], rowExpandedStates: { male : { state : 'expanded', children: {} } } } - ); - }); - - }); - - - describe('insertGroupHeader', function() { - it('inserts a header in the middle', function() { - var rowTemplateSpy = jasmine.createSpy('rowTemplateSpy'); - rowTemplateSpy.and.callFake( function() {}); - rowTemplateSpy(gridClassFactory, 'rowTemplateAssigner'); - var headerRow1 = new GridRow( {}, null, grid ); - var headerRow2 = new GridRow( {}, null, grid ); - var headerRow3 = new GridRow( {}, null, grid ); - - headerRow1.expandedState = { state: uiGridGroupingConstants.EXPANDED }; - headerRow2.expandedState = { state: uiGridGroupingConstants.COLLAPSED }; - grid.grouping.groupingHeaderCache = { - test: { - row: {}, - children: {} - } - }; - - var processingStates = [ - { - fieldName: 'col1', - col: grid.columns[1], - initialised: true, - currentValue: 'test', - currentRow: headerRow1 - }, - { - fieldName: 'col2', - col: grid.columns[2], - initialised: true, - currentValue: 'blah', - currentRow: headerRow2 - }, - { - fieldName: 'col3', - col: grid.columns[3], - initialised: true, - currentValue: 'fred', - currentRow: headerRow3 - } - ]; - - uiGridGroupingService.insertGroupHeader(grid, grid.rows, 3, processingStates, 1); - - expect( grid.rows.length ).toEqual(11, 'extra row created'); - - expect( processingStates[0].currentRow.uid ).toEqual(headerRow1.uid); - delete processingStates[0].currentRow; - expect( processingStates[1].currentRow.uid ).toBe(grid.rows[3].uid); - delete processingStates[1].currentRow; - expect( processingStates[2].currentRow ).toEqual(null, 'should be cleared as parent initialised it'); - - expect( processingStates[0].col.name ).toEqual( grid.columns[1].name, 'processing state 0 should have col1' ); - delete processingStates[0].col; - expect( processingStates[1].col.name ).toEqual( grid.columns[2].name, 'processing state 1 should have col2' ); - delete processingStates[1].col; - expect( processingStates[2].col.name ).toEqual( grid.columns[3].name, 'processing state 2 should have col3' ); - delete processingStates[2].col; - - expect(processingStates).toEqual([ - { - fieldName: 'col1', - initialised: true, - currentValue: 'test' - }, - { - fieldName: 'col2', - initialised: true, - currentValue: 'c_3' - }, - { - fieldName: 'col3', - initialised: false, - currentValue: null, - currentRow: null - } - ]); - }); - }); - }); diff --git a/src/features/importer/less/importer.less b/src/features/importer/less/importer.less deleted file mode 100644 index b4f058f5d9..0000000000 --- a/src/features/importer/less/importer.less +++ /dev/null @@ -1,4 +0,0 @@ -@import '../../../less/variables'; - -.ui-grid-importer-header { -} diff --git a/src/features/importer/templates/importerMenuItem.html b/src/features/importer/templates/importerMenuItem.html deleted file mode 100644 index 19509a7872..0000000000 --- a/src/features/importer/templates/importerMenuItem.html +++ /dev/null @@ -1,10 +0,0 @@ -
  • -
    - -
    -
  • diff --git a/src/features/importer/templates/importerMenuItemContainer.html b/src/features/importer/templates/importerMenuItemContainer.html deleted file mode 100644 index 8613edf9ac..0000000000 --- a/src/features/importer/templates/importerMenuItemContainer.html +++ /dev/null @@ -1 +0,0 @@ -
    \ No newline at end of file diff --git a/src/features/importer/test/importer.spec.js b/src/features/importer/test/importer.spec.js deleted file mode 100644 index a44d67610e..0000000000 --- a/src/features/importer/test/importer.spec.js +++ /dev/null @@ -1,534 +0,0 @@ -describe('ui.grid.importer uiGridImporterService', function () { - var uiGridImporterService; - var uiGridRowEditService; - var uiGridEditService; - var uiGridSelectionService; - var uiGridImporterConstants; - var gridClassFactory; - var grid; - var $scope; - var $window; - var $interval; - var $compile; - var gridOptions; - var gridUtil; - - beforeEach(module('ui.grid.importer', 'ui.grid.rowEdit')); - - - beforeEach(inject(function (_uiGridImporterService_, _gridClassFactory_, _uiGridImporterConstants_, - _uiGridRowEditService_, _uiGridEditService_, _$interval_, - _$rootScope_, _$window_, _$compile_, _gridUtil_ ) { - uiGridImporterService = _uiGridImporterService_; - uiGridRowEditService = _uiGridRowEditService_; - uiGridEditService = _uiGridEditService_; - uiGridImporterConstants = _uiGridImporterConstants_; - gridClassFactory = _gridClassFactory_; - $scope = _$rootScope_.$new(); - $window = _$window_; - $interval = _$interval_; - $compile = _$compile_; - gridUtil = _gridUtil_; - - spyOn($window, 'alert').and.callFake(angular.noop); - $scope.data = []; - for (var i = 0; i < 3; i++) { - $scope.data.push({col1:'a_'+i, col2:'b_'+i, col3:'c_'+i, col4:'d_'+i}); - } - - gridOptions = { - columnDefs: [ - {field: 'col1', name: 'col1', displayName: 'Col1', width: 50}, - {field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number'}, - {field: 'col3', name: 'col3', displayName: 'Col3', width: 100}, - {field: 'col4', name: 'col4', displayName: 'Col4', width: 200} - ], - data: $scope.data, - importerDataAddCallback: function( grid, newObjects ){ - $scope.data = $scope.data.concat( newObjects ); - gridOptions.data = $scope.data; - } - }; - - grid = gridClassFactory.createGrid(gridOptions); - - _uiGridImporterService_.initializeGrid($scope, grid); - grid.buildColumns(); - grid.modifyRows(grid.options.data); - grid.rows[1].visible = false; - grid.columns[2].visible = false; - grid.setVisibleRows(grid.rows); - })); - - - describe('defaultGridOptions', function() { - var options; - - beforeEach(function() { - options = {}; - }); - - // If the browser supports the File API, expect the grid options to be the default - it(', depending on browser support, should set all options to default, or "disabled" defaults', function() { - uiGridImporterService.defaultGridOptions(options); - - if ($window.hasOwnProperty('File') && $window.hasOwnProperty('FileReader') && $window.hasOwnProperty('FileList') && $window.hasOwnProperty('Blob')) { - expect( options ).toEqual({ - enableImporter: false, - importerProcessHeaders: uiGridImporterService.processHeaders, - //importerNewObject: undefined, - importerShowMenu: true, - importerObjectCallback: jasmine.any(Function), - importerHeaderFilter: jasmine.any(Function) - }); - } - else { - expect( options ).toEqual({ - enableImporter: false, - importerProcessHeaders: uiGridImporterService.processHeaders, - //importerNewObject: undefined, - importerShowMenu: true, - importerObjectCallback: jasmine.any(Function), - importerHeaderFilter: jasmine.any(Function) - }); - } - }); - - // Only run the rest of the tests if the browser supports the File API - if (window.hasOwnProperty('File') && window.hasOwnProperty('FileReader') && window.hasOwnProperty('FileList') && window.hasOwnProperty('Blob')) { - it('disable importer', function() { - var testFunction = function() {}; - var testObject = {}; - - options = { - enableImporter: false, - importerProcessHeaders: testFunction, - importerNewObject: testObject, - importerShowMenu: true, - importerErrorCallback: 'test' - }; - - uiGridImporterService.defaultGridOptions(options); - - expect( options ).toEqual({ - enableImporter: false, - importerProcessHeaders: testFunction, - importerNewObject: testObject, - importerShowMenu: true, - importerObjectCallback: jasmine.any(Function), - importerHeaderFilter: jasmine.any(Function) - }); - }); - - it('enable importer', function() { - var testFunction = function() {}; - var testObject = {}; - - options = { - enableImporter: true, - importerProcessHeaders: testFunction, - importerNewObject: testObject, - importerShowMenu: true, - importerErrorCallback: testFunction, - importerDataAddCallback: testFunction, - importerObjectCallback: testFunction, - importerHeaderFilter: testFunction - }; - - uiGridImporterService.defaultGridOptions(options); - - expect( options ).toEqual({ - enableImporter: true, - importerProcessHeaders: testFunction, - importerNewObject: testObject, - importerShowMenu: true, - importerErrorCallback: testFunction, - importerDataAddCallback: testFunction, - importerObjectCallback: testFunction, - importerHeaderFilter: testFunction - }); - }); - } - }); - - // Only run the rest of the tests if the browser supports the File API - if (window.hasOwnProperty('File') && window.hasOwnProperty('FileReader') && window.hasOwnProperty('FileList') && window.hasOwnProperty('Blob')) { - describe( 'importThisFile', function() { - // not tested as yet, mocking files is annoying - }); - - - describe( 'importJsonClosure', function() { - it( 'imports a valid file', function() { - var testFile = {target: {result: '[{"field":"some data","field2":"some more data"}]'}}; - - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.importJsonClosure( grid )( testFile ); - - grid.modifyRows($scope.data); - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(4, 'data should now have 4 rows'); - expect( $scope.data[3].field ).toEqual( 'some data' ); - - expect( grid.rows.length ).toEqual(4, 'grid should now have 4 rows'); - }); - - it( 'with importerObjectCallback updates', function() { - var testFile = {target: {result: '[{"field":"some data","field2":"some more data","status":"Active"}]'}}; - grid.options.importerObjectCallback = function( grid, newObject ){ - if ( newObject.status === "Active" ){ - newObject.status = 1; - } - return newObject; - }; - - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.importJsonClosure( grid )( testFile ); - - grid.modifyRows($scope.data); - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(4, 'data should now have 4 rows'); - expect( $scope.data[3].status ).toEqual( 1 ); - - expect( grid.rows.length ).toEqual(4, 'grid should now have 4 rows'); - }); - - it( 'with rowEdit, sets rows dirty', function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - - var testFile = {target: {result: '[{"field":"some data","field2":"some more data"},{"field":"2some data","field2":"2some more data"}]'}}; - - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.importJsonClosure( grid )( testFile ); - - grid.modifyRows($scope.data); - - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(5, 'data should now have 5 rows'); - expect( $scope.data[3].field ).toEqual( 'some data' ); - - expect( grid.rows.length ).toEqual(5, 'grid should now have 5 rows'); - expect( grid.rows[3].isDirty ).toEqual( true ); - expect( grid.rows[4].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length).toEqual(2); - }); - }); - - - describe( 'parseJson', function() { - it( 'imports a valid file', function() { - var testFile = {target: {result: '[{"field":"some data","field2":"some more data"}]'}}; - expect( uiGridImporterService.parseJson(grid, testFile) ).toEqual( [ { field: 'some data', field2: 'some more data'} ]); - }); - - it( 'errors on an invalid file', function() { - var testFile = {target: {result: '[{"field""some data","field2":"some more data"}]'}}; - var alertErrorSpy = jasmine.createSpy('alertErrorSpy'); - alertErrorSpy.and.callFake( function() {}); - alertErrorSpy( uiGridImporterService, 'alertError' ); - uiGridImporterService.parseJson(grid, testFile); - expect(alertErrorSpy).toHaveBeenCalled(); - }); - - it( 'errors on valid json that isn\'t an array', function() { - var testFile = {target: {result: '{"field""some data","field2":"some more data"}'}}; - var alertErrorSpy = jasmine.createSpy('alertErrorSpy'); - alertErrorSpy.and.callFake( function() {}); - alertErrorSpy( uiGridImporterService, 'alertError' ); - uiGridImporterService.parseJson(grid, testFile); - expect( alertErrorSpy).toHaveBeenCalled(); - }); - }); - - - describe( 'importCsvClosure', function() { - it( 'imports a valid file', function() { - var testFile = {target: {result: '"col1", "col2"\n"some data","some more data"\n"2some data", "2some more data"'}}; - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.importCsvClosure( grid )( testFile ); - - grid.modifyRows($scope.data); - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(5, 'data should now have 5 rows'); - expect( $scope.data[3].col1 ).toEqual( 'some data' ); - - expect( grid.rows.length ).toEqual(5, 'grid should now have 5 rows'); - }); - - it( 'with rowEdit, sets rows dirty', function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - - var testFile = {target: {result: '"col1", "col2"\n"some data","some more data"\n"2some data", "2some more data"'}}; - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.importCsvClosure( grid )( testFile ); - - grid.modifyRows($scope.data); - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(5, 'data should now have 5 rows'); - expect( $scope.data[3].col1 ).toEqual( 'some data' ); - - expect( grid.rows.length ).toEqual(5, 'grid should now have 5 rows'); - expect( grid.rows[3].isDirty ).toEqual( true ); - expect( grid.rows[4].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length).toEqual(2); - }); - }); - - - describe( 'createCsvObjects', function() { - it( 'header not provided', function() { - var fakeArray = [ [], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - var alertErrorSpy = jasmine.createSpy('alertErrorSpy'); - alertErrorSpy.and.callFake( function() {}); - alertErrorSpy( uiGridImporterService, 'alertError' ); - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([]); - expect( alertErrorSpy).toHaveBeenCalled(); - }); - - it( 'standard headers processed, objects created with new column defs', function() { - // this messes up the grid - OK for this test, but don't chain onto it - grid.options.columnDefs = []; - var fakeArray = [ ["col1", "col2", "col 3"], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([ - { col1: "data 1", col2: "data 2", col_3: "data 3"}, - { col1: "data 4", col2: "data 5", col_3: "data 6"} - ]); - }); - - it( 'standard headers processed, objects matched to column defs', function() { - var fakeArray = [ ["col1", "col2", "col 3"], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([ - { col1: "data 1", col2: "data 2"}, - { col1: "data 4", col2: "data 5"} - ]); - }); - - it( 'standard headers processed, objects matched to lower case column defs', function() { - var fakeArray = [ ["col1", "COL2", "col 3"], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([ - { col1: "data 1", col2: "data 2"}, - { col1: "data 4", col2: "data 5"} - ]); - }); - - - it( 'custom processHeader function, maps "col 3" to "col4"', function() { - var fakeArray = [ ["col1", "col2", "col 3"], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - grid.options.importerProcessHeaders = function( theGrid, headerRow ) { - return ["col1", "col2", "col4"]; - }; - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([ - { col1: "data 1", col2: "data 2", col4: "data 3"}, - { col1: "data 4", col2: "data 5", col4: "data 6"} - ]); - }); - - it( 'custom importerObjectCallback function, maps col4: "data 3" to col4: "mapped 3"', function() { - var fakeArray = [ ["col1", "col2", "col 3"], ["data 1", "data 2", "data 3"], ["data 4", "data 5", "data 6"]]; - grid.options.importerProcessHeaders = function( theGrid, headerRow ) { - return ["col1", "col2", "col4"]; - }; - grid.options.importerObjectCallback = function( grid, newObject ){ - if ( newObject.col4 === "data 3" ){ - newObject.col4 = "mapped 3"; - } - return newObject; - }; - - expect( uiGridImporterService.createCsvObjects( grid, fakeArray )).toEqual([ - { col1: "data 1", col2: "data 2", col4: "mapped 3"}, - { col1: "data 4", col2: "data 5", col4: "data 6"} - ]); - }); - }); - - - describe( 'parseCsv', function() { - it( 'imports a valid file', function() { - var testFile = {target: {result: '"field","field2"\n"some data","some more data"'}}; - expect( uiGridImporterService.parseCsv(testFile) ).toEqual( [ ["field", "field2"], ["some data", "some more data"] ]); - }); - - it( 'imports a valid file with commas in the text', function() { - var testFile = {target: {result: '"field","field2"\n"some, data","some more data"'}}; - expect( uiGridImporterService.parseCsv(testFile) ).toEqual( [ ["field", "field2"], ["some, data", "some more data"] ]); - }); - }); - - - describe( 'processHeaders', function() { - it( 'no columnDefs, create columns', function() { - var fakeGrid = {options: {}}; - var fakeHeaders = ["Field one","Field@#$%two","Field12 ^&* 34"]; - - expect( uiGridImporterService.processHeaders( fakeGrid, fakeHeaders )).toEqual( - [ "Field_one", "Field____two", "Field12______34" ] - ); - }); - - it( 'columnDefs empty, create columns', function() { - var fakeGrid = {options: {columnDefs: []}}; - var fakeHeaders = ["Field one","Field@#$%two","Field12 ^&* 34"]; - - expect( uiGridImporterService.processHeaders( fakeGrid, fakeHeaders )).toEqual( - [ "Field_one", "Field____two", "Field12______34" ] - ); - }); - - it( 'columnDefs empty, create columns, different values', function() { - var fakeGrid = {options: {columnDefs: []}}; - var fakeHeaders = ["col1","col2","col 3"]; - - expect( uiGridImporterService.processHeaders( fakeGrid, fakeHeaders )).toEqual( - [ "col1", "col2", "col_3" ] - ); - }); - - it( 'columnDefs, match columns', function() { - var fakeGrid = {options: {columnDefs: [ - {name: 'gender'}, - {field: 'company'}, - {displayName: 'First Name', field: 'firstName'} - ]}}; - - var fakeHeaders = ["gender","company","Field12", "First Name"]; - - expect( uiGridImporterService.processHeaders( fakeGrid, fakeHeaders )).toEqual( - [ "gender", "company", null, "firstName" ] - ); - }); - - it( 'empty array, no column defs, returns empty array', function() { - var fakeGrid = {options: {}}; - - var fakeHeaders = []; - - expect( uiGridImporterService.processHeaders( fakeGrid, fakeHeaders )).toEqual( - [] - ); - }); - }); - - - describe( 'flattenColumnDefs', function() { - it( 'creates the hash as expected for differing columnDefs', function() { - var fakeColumnDefs = [ - { name: 'test1' }, - { field: 'test2', name: 'should_use_field' }, - { displayName: 'Test 3', field: 'test3'} - ]; - - grid.options.importerHeaderFilter = function( displayName ){ if ( displayName === 'Test 3' ) { return 'Translated 3'; } }; - - expect( uiGridImporterService.flattenColumnDefs( grid, fakeColumnDefs ) ).toEqual({ - test1: "test1", - test2: "test2", - should_use_field: "test2", - "Test 3": "test3", - "test 3": "test3", - test3: "test3", - "Translated 3": "test3", - "translated 3": "test3" - }); - }); - }); - - - describe( 'addObjects', function() { - it( 'adds objects without rowEdit', function() { - var objects = [ { name: 'Fred', gender: 'male'}, { name: 'Jane', gender: 'female' } ]; - uiGridImporterService.addObjects( grid, objects ); - - expect( $scope.data.length ).toEqual(5); - expect( $scope.data[3].name ).toEqual( 'Fred' ); - }); - - it( 'with rowEdit, sets rows dirty', function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - - var objects = [ { name: 'Fred', gender: 'male'}, { name: 'Jane', gender: 'female' } ]; - - expect( grid.rows.length ).toEqual(3, 'should start with 3 gridRows'); - expect( $scope.data.length ).toEqual(3, 'should start with 3 rows in data'); - - uiGridImporterService.addObjects( grid, objects ); - - grid.modifyRows($scope.data); - angular.forEach( grid.dataChangeCallbacks, function( callback, uid ) { - callback.callback( grid ); - }); - - expect( $scope.data.length ).toEqual(5, 'data should now have 5 rows'); - expect( $scope.data[3].name ).toEqual( 'Fred' ); - - expect( grid.rows.length ).toEqual(5, 'grid should now have 5 rows'); - expect( grid.rows[3].isDirty ).toEqual( true ); - expect( grid.rows[4].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length).toEqual(2); - }); - }); - - - describe( 'alertError', function() { - describe('', function() { - beforeEach(function() { - spyOn( gridUtil, 'logError').and.callFake(function () {}); - }); - - it('raises an alert and writes a console log', function() { - uiGridImporterService.alertError( grid, 'importer.noHeaders', 'A message', ["test", "test2"]); - - // this will need adjusting whenever the En translation for this element changes, but is needed to - // check i18n is working - expect($window.alert.calls.mostRecent().args).toEqual(['Column names were unable to be derived, does the file have a header?']); - expect(gridUtil.logError.calls.mostRecent().args).toEqual(['A message' + ["test", "test2"]]); - }); - }); - - describe( 'calls custom error logging function if available', function() { - beforeEach(function() { - grid.options.importerErrorCallback = function (){}; - spyOn(grid.options, 'importerErrorCallback').and.callFake(function() {}); - }); - - it('', function() { - uiGridImporterService.alertError( grid, 'importer.noHeaders', 'A message', ["test", "test2"]); - expect( grid.options.importerErrorCallback.calls.mostRecent().args ).toEqual([grid, 'importer.noHeaders', 'A message', ["test", "test2"]]); - }); - }); - }); - } -}); diff --git a/src/features/infinite-scroll/test/infiniteScroll.spec.js b/src/features/infinite-scroll/test/infiniteScroll.spec.js deleted file mode 100644 index d0f71c70d4..0000000000 --- a/src/features/infinite-scroll/test/infiniteScroll.spec.js +++ /dev/null @@ -1,130 +0,0 @@ -/* global _ */ -(function () { - 'use strict'; - describe('ui.grid.infiniteScroll uiGridInfiniteScrollService', function () { - - var uiGridInfiniteScrollService; - var grid; - var gridClassFactory; - var uiGridConstants; - var $rootScope; - var $scope; - - beforeEach(module('ui.grid.infiniteScroll')); - - beforeEach(inject(function (_uiGridInfiniteScrollService_, _gridClassFactory_, _uiGridConstants_, _$rootScope_) { - uiGridInfiniteScrollService = _uiGridInfiniteScrollService_; - gridClassFactory = _gridClassFactory_; - uiGridConstants = _uiGridConstants_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - - grid = gridClassFactory.createGrid({}); - - grid.options.columnDefs = [ - {field: 'col1'} - ]; - grid.options.infiniteScrollRowsFromEnd = 20; - - uiGridInfiniteScrollService.initializeGrid(grid, $scope); - spyOn(grid.api.infiniteScroll.raise, 'needLoadMoreData'); - spyOn(grid.api.infiniteScroll.raise, 'needLoadMoreDataTop'); - - grid.options.data = [{col1:'a'},{col1:'b'}]; - - grid.buildColumns(); - - })); - - describe('event handling', function () { - beforeEach(function() { - spyOn(uiGridInfiniteScrollService, 'loadData').and.callFake(function() {}); - var arrayOf100 = []; - for ( var i = 0; i < 100; i++ ){ - arrayOf100.push(i); - } - grid.renderContainers = { body: { visibleRowCache: arrayOf100}}; - }); - - it('should not request more data if scroll up to 21%', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.UP; - uiGridInfiniteScrollService.handleScroll( { grid: grid, y: { percentage: 0.21 }}); - expect(uiGridInfiniteScrollService.loadData).not.toHaveBeenCalled(); - }); - - it('should request more data if scroll up to 20%', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.UP; - uiGridInfiniteScrollService.handleScroll( { grid: grid, y: { percentage: 0.20 }}); - expect(uiGridInfiniteScrollService.loadData).toHaveBeenCalled(); - }); - - it('should not request more data if scroll down to 79%', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; - uiGridInfiniteScrollService.handleScroll( {grid: grid, y: { percentage: 0.79 }}); - expect(uiGridInfiniteScrollService.loadData).not.toHaveBeenCalled(); - }); - - it('should request more data if scroll down to 80%', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; - uiGridInfiniteScrollService.handleScroll( { grid: grid, y: { percentage: 0.80 }}); - expect(uiGridInfiniteScrollService.loadData).toHaveBeenCalled(); - }); - }); - - describe('loadData', function() { - it('scroll up and there is data up', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.UP; - grid.infiniteScroll.scrollUp = true; - - uiGridInfiniteScrollService.loadData(grid); - - expect(grid.api.infiniteScroll.raise.needLoadMoreDataTop).toHaveBeenCalled(); - expect(grid.infiniteScroll.previousVisibleRows).toEqual(0); - expect(grid.infiniteScroll.direction).toEqual(uiGridConstants.scrollDirection.UP); - }); - - it('scroll up and there isn\'t data up', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.UP; - grid.infiniteScroll.scrollUp = false; - - uiGridInfiniteScrollService.loadData(grid); - - expect(grid.api.infiniteScroll.raise.needLoadMoreDataTop).not.toHaveBeenCalled(); - }); - - it('scroll down and there is data down', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; - grid.infiniteScroll.scrollDown = true; - - uiGridInfiniteScrollService.loadData(grid); - - expect(grid.api.infiniteScroll.raise.needLoadMoreData).toHaveBeenCalled(); - expect(grid.infiniteScroll.previousVisibleRows).toEqual(0); - expect(grid.infiniteScroll.direction).toEqual(uiGridConstants.scrollDirection.DOWN); - }); - - it('scroll down and there isn\'t data down', function() { - grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; - grid.infiniteScroll.scrollDown = false; - - uiGridInfiniteScrollService.loadData(grid); - - expect(grid.api.infiniteScroll.raise.needLoadMoreData).not.toHaveBeenCalled(); - }); - }); - - - describe( 'dataRemovedTop', function() { - it( 'adjusts scroll as expected', function() { - - }); - }); - - - describe( 'dataRemovedBottom', function() { - it( 'adjusts scroll as expected', function() { - - }); - }); - }); -})(); diff --git a/src/features/move-columns/js/column-movable.js b/src/features/move-columns/js/column-movable.js deleted file mode 100644 index cee35efa55..0000000000 --- a/src/features/move-columns/js/column-movable.js +++ /dev/null @@ -1,658 +0,0 @@ -(function () { - 'use strict'; - - /** - * @ngdoc overview - * @name ui.grid.moveColumns - * @description - * - * # ui.grid.moveColumns - * - * - * - * This module provides column moving capability to ui.grid. It enables to change the position of columns. - *
    - */ - var module = angular.module('ui.grid.moveColumns', ['ui.grid']); - - /** - * @ngdoc service - * @name ui.grid.moveColumns.service:uiGridMoveColumnService - * @description Service for column moving feature. - */ - module.service('uiGridMoveColumnService', ['$q', '$timeout', '$log', 'ScrollEvent', 'uiGridConstants', 'gridUtil', function ($q, $timeout, $log, ScrollEvent, uiGridConstants, gridUtil) { - - var service = { - initializeGrid: function (grid) { - var self = this; - this.registerPublicApi(grid); - this.defaultGridOptions(grid.options); - grid.moveColumns = {orderCache: []}; // Used to cache the order before columns are rebuilt - grid.registerColumnBuilder(self.movableColumnBuilder); - grid.registerDataChangeCallback(self.verifyColumnOrder, [uiGridConstants.dataChange.COLUMN]); - }, - registerPublicApi: function (grid) { - var self = this; - /** - * @ngdoc object - * @name ui.grid.moveColumns.api:PublicApi - * @description Public Api for column moving feature. - */ - var publicApi = { - events: { - /** - * @ngdoc event - * @name columnPositionChanged - * @eventOf ui.grid.moveColumns.api:PublicApi - * @description raised when column is moved - *
    -             *      gridApi.colMovable.on.columnPositionChanged(scope,function(colDef, originalPosition, newPosition){})
    -             * 
    - * @param {object} colDef the column that was moved - * @param {integer} originalPosition of the column - * @param {integer} finalPosition of the column - */ - colMovable: { - columnPositionChanged: function (colDef, originalPosition, newPosition) { - } - } - }, - methods: { - /** - * @ngdoc method - * @name moveColumn - * @methodOf ui.grid.moveColumns.api:PublicApi - * @description Method can be used to change column position. - *
    -             *      gridApi.colMovable.moveColumn(oldPosition, newPosition)
    -             * 
    - * @param {integer} originalPosition of the column - * @param {integer} finalPosition of the column - */ - colMovable: { - moveColumn: function (originalPosition, finalPosition) { - var columns = grid.columns; - if (!angular.isNumber(originalPosition) || !angular.isNumber(finalPosition)) { - gridUtil.logError('MoveColumn: Please provide valid values for originalPosition and finalPosition'); - return; - } - var nonMovableColumns = 0; - for (var i = 0; i < columns.length; i++) { - if ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true) { - nonMovableColumns++; - } - } - if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) { - gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition'); - return; - } - var findPositionForRenderIndex = function (index) { - var position = index; - for (var i = 0; i <= position; i++) { - if (angular.isDefined(columns[i]) && ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true)) { - position++; - } - } - return position; - }; - self.redrawColumnAtPosition(grid, findPositionForRenderIndex(originalPosition), findPositionForRenderIndex(finalPosition)); - } - } - } - }; - grid.api.registerEventsFromObject(publicApi.events); - grid.api.registerMethodsFromObject(publicApi.methods); - }, - defaultGridOptions: function (gridOptions) { - /** - * @ngdoc object - * @name ui.grid.moveColumns.api:GridOptions - * - * @description Options for configuring the move column feature, these are available to be - * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} - */ - /** - * @ngdoc object - * @name enableColumnMoving - * @propertyOf ui.grid.moveColumns.api:GridOptions - * @description If defined, sets the default value for the colMovable flag on each individual colDefs - * if their individual enableColumnMoving configuration is not defined. Defaults to true. - */ - gridOptions.enableColumnMoving = gridOptions.enableColumnMoving !== false; - }, - movableColumnBuilder: function (colDef, col, gridOptions) { - var promises = []; - /** - * @ngdoc object - * @name ui.grid.moveColumns.api:ColumnDef - * - * @description Column Definition for move column feature, these are available to be - * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} - */ - /** - * @ngdoc object - * @name enableColumnMoving - * @propertyOf ui.grid.moveColumns.api:ColumnDef - * @description Enable column moving for the column. - */ - colDef.enableColumnMoving = colDef.enableColumnMoving === undefined ? gridOptions.enableColumnMoving - : colDef.enableColumnMoving; - return $q.all(promises); - }, - /** - * @ngdoc method - * @name updateColumnCache - * @methodOf ui.grid.moveColumns - * @description Cache the current order of columns, so we can restore them after new columnDefs are defined - */ - updateColumnCache: function(grid){ - grid.moveColumns.orderCache = grid.getOnlyDataColumns(); - }, - /** - * @ngdoc method - * @name verifyColumnOrder - * @methodOf ui.grid.moveColumns - * @description dataChangeCallback which uses the cached column order to restore the column order - * when it is reset by altering the columnDefs array. - */ - verifyColumnOrder: function(grid){ - var headerRowOffset = grid.rowHeaderColumns.length; - var newIndex; - - angular.forEach(grid.moveColumns.orderCache, function(cacheCol, cacheIndex){ - newIndex = grid.columns.indexOf(cacheCol); - if ( newIndex !== -1 && newIndex - headerRowOffset !== cacheIndex ){ - var column = grid.columns.splice(newIndex, 1)[0]; - grid.columns.splice(cacheIndex + headerRowOffset, 0, column); - } - }); - }, - redrawColumnAtPosition: function (grid, originalPosition, newPosition) { - var columns = grid.columns; - - if (originalPosition === newPosition) { - return; - } - - //check columns in between move-range to make sure they are visible columns - var pos = (originalPosition < newPosition) ? originalPosition + 1 : originalPosition - 1; - var i0 = Math.min(pos, newPosition); - for (i0; i0 <= Math.max(pos, newPosition); i0++) { - if (columns[i0].visible) { - break; - } - } - if (i0 > Math.max(pos, newPosition)) { - //no visible column found, column did not visibly move - return; - } - - var originalColumn = columns[originalPosition]; - if (!grid.options.enableColumnMoving || !originalColumn.colDef.enableColumnMoving) { - return; - } - - if (originalPosition > newPosition) { - if (!columns[newPosition].colDef.enableColumnMoving) { - this.redrawColumnAtPosition(grid, originalPosition, newPosition+1); - } - for (var i1 = originalPosition; i1 > newPosition; i1--) { - columns[i1] = columns[i1 - 1]; - } - } - else if (newPosition > originalPosition) { - if (!columns[newPosition].colDef.enableColumnMoving) { - this.redrawColumnAtPosition(grid, originalPosition, newPosition-1); - return; - } - for (var i2 = originalPosition; i2 < newPosition; i2++) { - columns[i2] = columns[i2 + 1]; - } - } - columns[newPosition] = originalColumn; - service.updateColumnCache(grid); - grid.queueGridRefresh(); - $timeout(function () { - grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); - grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition); - var selector = '.ui-grid-header-cell.ui-grid-col' + originalColumn.uid + ' .ui-grid-cell-contents' - angular.element(selector).focus(); - }); - } - }; - return service; - }]); - - /** - * @ngdoc directive - * @name ui.grid.moveColumns.directive:uiGridMoveColumns - * @element div - * @restrict A - * @description Adds column moving features to the ui-grid directive. - * @example - - - var app = angular.module('app', ['ui.grid', 'ui.grid.moveColumns']); - app.controller('MainCtrl', ['$scope', function ($scope) { - $scope.data = [ - { name: 'Bob', title: 'CEO', age: 45 }, - { name: 'Frank', title: 'Lowly Developer', age: 25 }, - { name: 'Jenny', title: 'Highly Developer', age: 35 } - ]; - $scope.columnDefs = [ - {name: 'name'}, - {name: 'title'}, - {name: 'age'} - ]; - }]); - - - .grid { - width: 100%; - height: 150px; - } - - -
    -
    -
    -
    -
    - */ - module.directive('uiGridMoveColumns', ['uiGridMoveColumnService', function (uiGridMoveColumnService) { - return { - replace: true, - priority: 0, - require: '^uiGrid', - scope: false, - compile: function () { - return { - pre: function ($scope, $elm, $attrs, uiGridCtrl) { - uiGridMoveColumnService.initializeGrid(uiGridCtrl.grid); - }, - post: function ($scope, $elm, $attrs, uiGridCtrl) { - } - }; - } - }; - }]); - - /** - * @ngdoc directive - * @name ui.grid.moveColumns.directive:uiGridHeaderCell - * @element div - * @restrict A - * - * @description Stacks on top of ui.grid.uiGridHeaderCell to provide capability to be able to move it to reposition column. - * - * On receiving mouseDown event headerCell is cloned, now as the mouse moves the cloned header cell also moved in the grid. - * In case the moving cloned header cell reaches the left or right extreme of grid, grid scrolling is triggered (if horizontal scroll exists). - * On mouseUp event column is repositioned at position where mouse is released and cloned header cell is removed. - * - * Events that invoke cloning of header cell: - * - mousedown - * - * Events that invoke movement of cloned header cell: - * - mousemove - * - * Events that invoke repositioning of column: - * - mouseup - */ - module.directive('uiGridHeaderCell', ['$q', 'gridUtil', 'uiGridMoveColumnService', '$document', '$log', 'uiGridConstants', 'ScrollEvent', - function ($q, gridUtil, uiGridMoveColumnService, $document, $log, uiGridConstants, ScrollEvent) { - return { - priority: -10, - require: '^uiGrid', - compile: function () { - return { - post: function ($scope, $elm, $attrs, uiGridCtrl) { - function enableColumnMove(){ - offAllEvents(); - - if ($scope.grid.options.enableColumnMoving && $scope.col.colDef.enableColumnMoving) { - onDownEvents(); - } - } - $scope.$watch('grid.options.enableColumnMoving', enableColumnMove); - - $scope.$watch('col.colDef.enableColumnMoving', enableColumnMove); - - /* - * Our general approach to column move is that we listen to a touchstart or mousedown - * event over the column header. When we hear one, then we wait for a move of the same type - * - if we are a touchstart then we listen for a touchmove, if we are a mousedown we listen for - * a mousemove (i.e. a drag) before we decide that there's a move underway. If there's never a move, - * and we instead get a mouseup or a touchend, then we just drop out again and do nothing. - * - */ - var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); - - var gridLeft; - var previousMouseX; - var totalMouseMovement; - var rightMoveLimit; - var elmCloned = false; - var movingElm; - var reducedWidth; - var moveOccurred = false; - - var downFn = function( event ){ - //Setting some variables required for calculations. - gridLeft = $scope.grid.element[0].getBoundingClientRect().left; - if ( $scope.grid.hasLeftContainer() ){ - gridLeft += $scope.grid.renderContainers.left.header[0].getBoundingClientRect().width; - } - - previousMouseX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); - totalMouseMovement = 0; - rightMoveLimit = gridLeft + $scope.grid.getViewportWidth(); - - if ( event.type === 'mousedown' ){ - $document.on('mousemove', moveFn); - $document.on('mouseup', upFn); - } else if ( event.type === 'touchstart' ){ - $document.on('touchmove', moveFn); - $document.on('touchend', upFn); - } - }; - - var moveFn = function( event ) { - var pageX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); - var changeValue = pageX - previousMouseX; - if ( changeValue === 0 ){ return; } - //Disable text selection in Chrome during column move - document.onselectstart = function() { return false; }; - - moveOccurred = true; - - if (!elmCloned) { - cloneElement(); - } - else if (elmCloned) { - moveElement(changeValue); - previousMouseX = pageX; - } - }; - - var upFn = function( event ){ - //Re-enable text selection after column move - document.onselectstart = null; - - //Remove the cloned element on mouse up. - if (movingElm) { - movingElm.remove(); - elmCloned = false; - } - - offAllEvents(); - onDownEvents(); - - if (!moveOccurred){ - return; - } - - var columns = $scope.grid.columns; - var columnIndex = 0; - for (var i = 0; i < columns.length; i++) { - if (columns[i].colDef.name !== $scope.col.colDef.name) { - columnIndex++; - } - else { - break; - } - } - moveColumnPosition(true); - $elm.parent().removeClass('columnsMoving'); - angular.element('.ui-grid-header-canvas').removeClass('headerColumnsAreMoving'); - }; - - var onDownEvents = function(){ - $contentsElm.on('touchstart', downFn); - $contentsElm.on('mousedown', downFn); - }; - - var offAllEvents = function() { - $contentsElm.off('touchstart', downFn); - $contentsElm.off('mousedown', downFn); - - $document.off('mousemove', moveFn); - $document.off('touchmove', moveFn); - - $document.off('mouseup', upFn); - $document.off('touchend', upFn); - }; - - var cloneElement = function () { - elmCloned = true; - - //Cloning header cell and appending to current header cell. - movingElm = $elm.clone(); - $elm.parent().append(movingElm); - - //Left of cloned element should be aligned to original header cell. - angular.element('.ui-grid-header-canvas').addClass('headerColumnsAreMoving'); - $elm.parent().addClass('columnsMoving'); - movingElm.addClass('movingColumn'); - var movingElementStyles = {}; - movingElementStyles.left = $elm[0].offsetLeft + 'px'; - var gridRight = $scope.grid.element[0].getBoundingClientRect().right; - var elmRight = $elm[0].getBoundingClientRect().right; - if (elmRight > gridRight) { - reducedWidth = $scope.col.drawnWidth + (gridRight - elmRight); - movingElementStyles.width = reducedWidth + 'px'; - } - movingElm.css(movingElementStyles); - }; - - var moveElement = function (changeValue) { - //Calculate total column width - var columns = $scope.grid.columns; - var gridRight = $scope.grid.element[0].getBoundingClientRect().right; - var totalColumnWidth = 0; - for (var i = 0; i < columns.length; i++) { - if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) { - totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width; - } - } - - //Calculate new position of left of column - var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1; - var currentElmRight = movingElm[0].getBoundingClientRect().right; - - var newElementLeft = currentElmLeft - gridLeft + changeValue; - newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit; - - // move the column if it's in view. Else scroll if we need to - var delta; - if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) { - delta = (newElementLeft < rightMoveLimit) ? changeValue : 0; - movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft + delta) + 'px'}); - } else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) { - changeValue *= 8; - var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement'); - scrollEvent.x = {pixels: changeValue}; - scrollEvent.grid.scrollContainers('',scrollEvent); - delta = (newElementLeft < rightMoveLimit) ? changeValue : 0; - var newLeft = movingElm[0].offsetLeft + delta; - // Have to recaluculate the bounds of the moving element since the scrolling will have changed it. - if (movingElm[0].getBoundingClientRect().left - 1 >= gridLeft && (movingElm[0].getBoundingClientRect().right <= rightMoveLimit)) { - movingElm.css({visibility: 'visible', 'left': newLeft + 'px'}); - } - } - - //Calculate total width of columns on the left of the moving column and the mouse movement - var totalColumnsLeftWidth = 0; - for (var il = 0; il < columns.length; il++) { - if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { - if (columns[il].colDef.name !== $scope.col.colDef.name) { - totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; - } - else { - break; - } - } - } - if ($scope.newScrollLeft === undefined) { - totalMouseMovement += changeValue; - } - else { - totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth; - } - - //Increase width of moving column, in case the rightmost column was moved and its width was - //decreased because of overflow - if (reducedWidth < $scope.col.drawnWidth) { - reducedWidth += Math.abs(changeValue); - movingElm.css({'width': reducedWidth + 'px'}); - } - - moveColumnPosition(false); - }; - - // This function either re-positions the columns or adds classes to the ui-grid-header-cells that would be re-positioned - var moveColumnPosition = function (isColumnDropped) { - var columns = $scope.grid.columns; - var columnIndex = 0; - var visibleMovableColumnIndex = 0; - - // Returns a boolean indicating whether the column is visible or not. - function isVisible(col) { - return angular.isUndefined(col.colDef.visible) || !!col.colDef.visible; - } - - // Returns a boolean indicating wether the column is pinned or not. - function isPinned(col) { - return !!col.colDef.pinnedLeft || !!col.colDef.pinnedRight; - } - - // Applies `klass` to `col`, if it hasn't already been applied and if `col` is not the column we are moving. - function addNewPositionClass(col, klass) { - var colClass = col.getColClass(true); - - var gridElm = uiGridCtrl.grid.element || $elm.parent(); - // Only do something if the column in question doesn't already have the class applied. - if ($elm.parent().find('div.' + klass + colClass).length === 0) { - // When adding the position class to a new column, clear out any old position classes - gridElm.find('div.new_position_left').removeClass('new_position_left'); - gridElm.find('div.new_position_right').removeClass('new_position_right'); - - // Only add the class if this is not the column that is moving - if ($elm.parent().find('div.' + 'old_position' + colClass).length === 0) { - gridElm.find('div' + colClass).addClass(klass); - } - } - } - - // Returns the width of the column - function getColWidth(col) { - return col.drawnWidth || col.width || col.colDef.width; - } - - // Moves or updates the current column's position to that of `visMovCol` where `visMovCol` - // is a visible, movable column whose position represents the current column's new position. - // `dir` is a string indicating the direction of movement and is used for updating the CSS class. - function updateColumnPosition(visMovCol, dir) { - if (isColumnDropped) { - uiGridMoveColumnService.redrawColumnAtPosition($scope.grid, columnIndex, columns.indexOf(visMovCol)); - } else { - addNewPositionClass(visMovCol, 'new_position_' + dir); - } - } - - // Get the index (in grid.columns) of the column we want to move. - for (var i = 0; i < columns.length; i++) { - if (columns[i].colDef.name !== $scope.col.colDef.name) { - columnIndex++; - } else { - break; - } - } - - if (isColumnDropped) { - // If we are dropping the column, clear out the position classes. - var gridElm = uiGridCtrl.grid.element || $elm.parent(); - gridElm.find('div.new_position_left').removeClass('new_position_left'); - gridElm.find('div.new_position_right').removeClass('new_position_right'); - gridElm.find('div.old_position').removeClass('old_position'); - } else { - // Add the 'old_position' class to the column we are moving to mark its original location. - $elm.parent().find('div.ui-grid-header-cell' + columns[columnIndex].getColClass(true)).addClass('old_position'); - } - - // Build a list of columns that are eligible for moving - var visibleMovableColumns = columns.filter(function(c) { return isVisible(c) && !isPinned(c); }); - - // Get the index (in the _visible_ and _movable_ list) of the column we are moving. - visibleMovableColumnIndex = visibleMovableColumns.indexOf(columns[columnIndex]); - - var il, ir; - // Case where column should be moved to a position on its left - if (totalMouseMovement < 0) { - var totalColumnsLeftWidth = 0; - var visibleMovableColumnsLeftCount = 0; - if ($scope.grid.isRTL()) { - // In RTL, moving left means traversing towards the end of the array - for (il = visibleMovableColumnIndex + 1; il < visibleMovableColumns.length; il++) { - totalColumnsLeftWidth += getColWidth(visibleMovableColumns[il]); - if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { - updateColumnPosition(visibleMovableColumns[il - 1], 'left'); - break; - } - } - } else { - for (il = visibleMovableColumnIndex - 1; il >= 0; il--) { - totalColumnsLeftWidth += getColWidth(visibleMovableColumns[il]); - if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { - updateColumnPosition(visibleMovableColumns[il + 1], 'left'); - break; - } - } - } - // Case where column should be moved to beginning (or end for RTL) of the grid. - if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) { - if ($scope.grid.isRTL()) { - updateColumnPosition(visibleMovableColumns[visibleMovableColumns.length - 1], 'left'); - } else { - updateColumnPosition(visibleMovableColumns[0], 'left'); - } - } - } - // Case where column should be moved to a position on its right - else if (totalMouseMovement > 0) { - var totalColumnsRightWidth = 0; - var visibleMovableColumnsRightCount = 0; - if ($scope.grid.isRTL()) { - // In RTL, moving right means traversing towards the beginning of the array. - for (ir = visibleMovableColumnIndex - 1; ir >= 0; ir--) { - totalColumnsRightWidth += getColWidth(visibleMovableColumns[ir]); - if (totalColumnsRightWidth > totalMouseMovement) { - updateColumnPosition(visibleMovableColumns[ir + 1], 'right'); - break; - } - } - } else { - for (ir = visibleMovableColumnIndex + 1; ir < visibleMovableColumns.length; ir++) { - totalColumnsRightWidth += getColWidth(visibleMovableColumns[ir]); - if (totalColumnsRightWidth > totalMouseMovement) { - updateColumnPosition(visibleMovableColumns[ir - 1], 'right'); - break; - } - } - } - // Case where column should be moved to end (or beginning for RTL) of the grid. - if (totalColumnsRightWidth < totalMouseMovement) { - if ($scope.grid.isRTL()) { - updateColumnPosition(visibleMovableColumns[0], 'right'); - } else { - updateColumnPosition(visibleMovableColumns[visibleMovableColumns.length - 1], 'right'); - } - } - } - }; - $scope.$on('$destroy', offAllEvents); - } - }; - } - }; - }]); -})(); diff --git a/src/features/move-columns/test/column-movable.spec.js b/src/features/move-columns/test/column-movable.spec.js deleted file mode 100644 index 85eff02fe4..0000000000 --- a/src/features/move-columns/test/column-movable.spec.js +++ /dev/null @@ -1,314 +0,0 @@ -describe('ui.grid.moveColumns', function () { - - var scope, element, timeout, gridUtil, document, uiGridConstants; - - var data = [ - { "name": "Ethel Price", "gender": "female", "age": 25, "company": "Enersol", phone: '111'}, - { "name": "Claudine Neal", "gender": "female", "age": 30, "company": "Sealoud", phone: '111'}, - { "name": "Beryl Rice", "gender": "female", "age": 35, "company": "Velity", phone: '111'}, - { "name": "Wilder Gonzales", "gender": "male", "age": 40, "company": "Geekko", phone: '111'} - ]; - - beforeEach(module('ui.grid.moveColumns')); - - beforeEach(inject(function (_$compile_, $rootScope, $timeout, _gridUtil_, $document, _uiGridConstants_) { - - var $compile = _$compile_; - scope = $rootScope; - timeout = $timeout; - gridUtil = _gridUtil_; - document = $document; - uiGridConstants = _uiGridConstants_; - scope.gridOptions = {}; - scope.gridOptions.data = data; - scope.gridOptions.columnDefs = [ - { field: 'name', width: 200 }, - { field: 'gender', width: 200 }, - { field: 'age', width: 200, visible: false}, - { field: 'company', enableColumnMoving: false, width: 200 }, - { field: 'phone', width: 200 } - ]; - - scope.gridOptions.onRegisterApi = function (gridApi) { - scope.gridApi = gridApi; - scope.grid = gridApi.grid; - }; - - element = angular.element('
    '); - - $timeout(function () { - $compile(element)(scope); - }); - $timeout.flush(); - })); - - it('grid api for columnMovable should be defined', function () { - expect(scope.gridApi.colMovable).toBeDefined(); - expect(scope.gridApi.colMovable.on.columnPositionChanged).toBeDefined(); - expect(scope.gridApi.colMovable.raise.columnPositionChanged).toBeDefined(); - expect(scope.gridApi.colMovable.moveColumn).toBeDefined(); - }); - - it('expect enableColumnMoving to be true by default', function () { - expect(scope.grid.options.enableColumnMoving).toBe(true); - expect(scope.grid.columns[0].colDef.enableColumnMoving).toBe(true); - expect(scope.grid.columns[1].colDef.enableColumnMoving).toBe(true); - expect(scope.grid.columns[2].colDef.enableColumnMoving).toBe(true); - expect(scope.grid.columns[3].colDef.enableColumnMoving).toBe(false); - expect(scope.grid.columns[4].colDef.enableColumnMoving).toBe(true); - }); - - it('expect moveColumn() to change position of columns', function () { - scope.gridApi.colMovable.moveColumn(0, 1); - expect(scope.grid.columns[0].name).toBe('gender'); - expect(scope.grid.columns[1].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - scope.gridApi.colMovable.moveColumn(0, 3); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('age'); - expect(scope.grid.columns[2].name).toBe('company'); - expect(scope.grid.columns[3].name).toBe('phone'); - expect(scope.grid.columns[4].name).toBe('gender'); - }); - - it('expect moveColumn() to persist after adding additional column', function () { - scope.gridApi.colMovable.moveColumn(0, 1); - scope.gridOptions.columnDefs.push({ field: 'name', displayName: 'name2', width: 200 }); - scope.gridApi.core.notifyDataChange( uiGridConstants.COLUMN ); - timeout.flush(); - scope.$digest(); - - expect(scope.grid.columns[0].name).toBe('gender'); - expect(scope.grid.columns[1].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - expect(scope.grid.columns[5].displayName).toBe('name2'); - }); - - it('expect moveColumn() to not change position of columns if enableColumnMoving is false', function () { - scope.gridApi.colMovable.moveColumn(2, 1); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - describe("expect moveColumn() to not change position of columns if column position given is wrong", function () { - beforeEach(function() { - spyOn(gridUtil, 'logError').and.callFake(function() {}); - scope.gridApi.colMovable.moveColumn(4, 5); - }); - it('', function() { - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - expect(gridUtil.logError.calls.mostRecent().args).toEqual(['MoveColumn: Invalid values for originalPosition, finalPosition']); - }); - - }); - - it('expect event columnPositionChanged to be called when column position is changed', function () { - var functionCalled = false; - scope.gridApi.colMovable.on.columnPositionChanged(scope, function (colDef, newPos, oldPos) { - functionCalled = true; - }); - scope.gridApi.colMovable.moveColumn(0, 1); - timeout.flush(); - expect(functionCalled).toBe(true); - }); - - // NOTE (nsartor) this test fails since scrolling is fixed. I believe it's caused by the - // viewport size = 0, the elements want to scroll immediately. - //it('expect column to move right when dragged right', function () { - //var event = jQuery.Event("mousedown", { - //pageX: 0 - //}); - //var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[0]); - //columnHeader.trigger(event); - //event = jQuery.Event("mousemove", { - //pageX: 200 - //}); - //document.trigger(event); - //document.trigger(event); - //event = jQuery.Event("mouseup"); - //document.trigger(event); - //expect(scope.grid.columns[0].name).toBe('gender'); - //expect(scope.grid.columns[1].name).toBe('age'); - //expect(scope.grid.columns[2].name).toBe('name'); - //expect(scope.grid.columns[3].name).toBe('company'); - //expect(scope.grid.columns[4].name).toBe('phone'); - //}); - - it('expect column to move left when dragged left', function () { - var event = jQuery.Event("mousedown", { - pageX: 0 - }); - var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[1]); - columnHeader.trigger(event); - event = jQuery.Event("mousemove", { - pageX: -200 - }); - document.trigger(event); - document.trigger(event); - event = jQuery.Event("mouseup"); - document.trigger(event); - expect(scope.grid.columns[0].name).toBe('gender'); - expect(scope.grid.columns[1].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - it('expect column movement to not happen if enableColumnMoving is false', function () { - var event = jQuery.Event("mousedown", { - pageX: 0 - }); - var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[3]); - columnHeader.trigger(event); - event = jQuery.Event("mousemove", { - pageX: 200 - }); - document.trigger(event); - document.trigger(event); - event = jQuery.Event("mouseup"); - document.trigger(event); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - it('expect column movement to not happen if enableColumnMoving is changed to false', function() { - scope.grid.options.enableColumnMoving = false; - scope.gridApi.colMovable.moveColumn(0, 1); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - it('expect column movement to happen if enableColumnMoving is changed to true', function() { - scope.grid.options.enableColumnMoving = false; - scope.grid.options.enableColumnMoving = true; - scope.gridApi.colMovable.moveColumn(0, 1); - expect(scope.grid.columns[0].name).toBe('gender'); - expect(scope.grid.columns[1].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - it('expect column movement not to happen if column definition enableColumnMoving is changed to false', function(){ - scope.grid.options.enableColumnMoving = true; - scope.grid.columns[2].colDef.enableColumnMoving = false; - scope.gridApi.colMovable.moveColumn(2, 0); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - }); - - it('expect column movement not to happen for column definition enableColumnMoving is false by default', function(){ - scope.gridApi.colMovable.moveColumn(2, 0); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[3].name).toBe('company'); - }); - - it('expect column movement to be happen for changing the column definition enableColumnMoving property to true which is false by default', function(){ - scope.grid.columns[3].colDef.enableColumnMoving = true; - scope.gridApi.colMovable.moveColumn(2, 0); - expect(scope.grid.columns[0].name).toBe('company'); - expect(scope.grid.columns[3].name).toBe('age'); - }); - - it('expect column move not to happen if moving across hidden columns', function() { - scope.gridOptions.columnDefs[1].visible = false; - scope.gridApi.colMovable.moveColumn(0, 3); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - describe('when jQuery is enabled on touch devices', function() { - // NOTE (priceld) this is excluded for the same reason nsartor mentioned above - // it('expect column to move right when dragged right', function () { - // var event = jQuery.Event("touchstart", { - // originalEvent: { - // pageX: 0 - // } - // }); - // var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[0]); - // columnHeader.trigger(event); - // event = jQuery.Event("touchmove", { - // originalEvent: { - // pageX: 200 - // } - // }); - // document.trigger(event); - // document.trigger(event); - // event = jQuery.Event("touchend"); - // document.trigger(event); - // expect(scope.grid.columns[0].name).toBe('gender'); - // expect(scope.grid.columns[1].name).toBe('age'); - // expect(scope.grid.columns[2].name).toBe('name'); - // expect(scope.grid.columns[3].name).toBe('company'); - // expect(scope.grid.columns[4].name).toBe('phone'); - // }); - - it('expect column to move left when dragged left', function () { - var event = jQuery.Event("touchstart", { - originalEvent: { - pageX: 0 - } - }); - var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[1]); - columnHeader.trigger(event); - event = jQuery.Event("touchmove", { - originalEvent: { - pageX: -200 - } - }); - document.trigger(event); - document.trigger(event); - event = jQuery.Event("touchend"); - document.trigger(event); - expect(scope.grid.columns[0].name).toBe('gender'); - expect(scope.grid.columns[1].name).toBe('name'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - - it('expect column movement to not happen if enableColumnMoving is false', function () { - var event = jQuery.Event("touchstart", { - originalEvent: { - pageX: 0 - } - }); - var columnHeader = angular.element(element.find('.ui-grid-cell-contents')[3]); - columnHeader.trigger(event); - event = jQuery.Event("touchmove", { - originalEvent: { - pageX: 200 - } - }); - document.trigger(event); - document.trigger(event); - event = jQuery.Event("touchend"); - document.trigger(event); - expect(scope.grid.columns[0].name).toBe('name'); - expect(scope.grid.columns[1].name).toBe('gender'); - expect(scope.grid.columns[2].name).toBe('age'); - expect(scope.grid.columns[3].name).toBe('company'); - expect(scope.grid.columns[4].name).toBe('phone'); - }); - }); -}); diff --git a/src/features/pagination/less/pagination.less b/src/features/pagination/less/pagination.less deleted file mode 100644 index 0b0acc2f6c..0000000000 --- a/src/features/pagination/less/pagination.less +++ /dev/null @@ -1,135 +0,0 @@ -@import "../../../less/variables"; -@import "../../../less/elements"; -@import (reference) "../../../less/bootstrap/bootstrap"; - -.ui-grid-pager-panel { - position: absolute; - left: 0; - bottom: 0; - width: 100%; - padding-top: 3px; - padding-bottom: 3px; - box-sizing: content-box; -} - -.ui-grid-pager-container { - float: left; -} - -.ui-grid-pager-control { - margin-right: 10px; - margin-left: 10px; - min-width: 135px; - float: left; - - button { - height: 25px; - min-width: 26px; - #ui-grid-twbs > .btn; - #ui-grid-twbs > .button-variant(@paginationButtonColor, @paginationButtonBackgroundColor, @paginationButtonBorderColor); - } - - input { - #ui-grid-twbs > .form-control(); - #ui-grid-twbs > .input-sm (); - display: inline; - height: 26px; - width: 50px; - vertical-align: top; - } - - .ui-grid-pager-max-pages-number{ - vertical-align: bottom; - > * { - vertical-align: middle; - } - } - - .first-bar { - width: 10px; - border-left: 2px solid #4d4d4d; - margin-top: -6px; - height: 12px; - margin-left: -3px; - } - - .first-bar-rtl { - width: 10px; - border-left: 2px solid #4d4d4d; - margin-top: -6px; - height: 12px; - margin-right: -7px; - } - - .first-triangle { - width: 0; - height: 0; - border-style: solid; - border-width: 5px 8.7px 5px 0; - border-color: transparent #4d4d4d transparent transparent; - margin-left: 2px; - } - - .next-triangle { - margin-left: 1px; - } - - .prev-triangle { - margin-left: 0; - } - - .last-triangle { - width: 0; - height: 0; - border-style: solid; - border-width: 5px 0 5px 8.7px; - border-color: transparent transparent transparent #4d4d4d; - margin-left: -1px; - } - - .last-bar { - width: 10px; - border-left: 2px solid #4d4d4d; - margin-top: -6px; - height: 12px; - margin-left: 1px; - } - - .last-bar-rtl { - width: 10px; - border-left: 2px solid #4d4d4d; - margin-top: -6px; - height: 12px; - margin-right: -11px; - } - - -} - -.ui-grid-pager-row-count-picker { - float: left; - - select { - #ui-grid-twbs > .form-control; - #ui-grid-twbs > .input-sm (); - height: 26px; - width: 67px; - display: inline; - } - - .ui-grid-pager-row-count-label { - margin-top: 3px; - } -} - -.ui-grid-pager-count-container { - float: right; - margin-top: 4px; - min-width: 50px; - - .ui-grid-pager-count { - margin-right: 10px; - margin-left: 10px; - float: right; - } -} diff --git a/src/features/pagination/templates/pagination.html b/src/features/pagination/templates/pagination.html deleted file mode 100644 index 630e1f86a9..0000000000 --- a/src/features/pagination/templates/pagination.html +++ /dev/null @@ -1,113 +0,0 @@ - diff --git a/src/features/pagination/test/pagination.spec.js b/src/features/pagination/test/pagination.spec.js deleted file mode 100644 index 53890ccf7c..0000000000 --- a/src/features/pagination/test/pagination.spec.js +++ /dev/null @@ -1,286 +0,0 @@ -describe('ui.grid.pagination uiGridPaginationService', function () { - 'use strict'; - - var gridApi; - var gridElement; - var $rootScope; - var $timeout; - - beforeEach(module('ui.grid')); - beforeEach(module('ui.grid.pagination')); - - beforeEach(inject(function (_$rootScope_, _$timeout_, $compile) { - $rootScope = _$rootScope_; - $timeout = _$timeout_; - - $rootScope.gridOptions = { - columnDefs: [ - {name: 'col1'}, - {name: 'col2'}, - {name: 'col3'}, - {name: 'col4'} - ], - data: [ - {col1: '1_1', col2: 'G', col3: '1_3', col4: '1_4'}, - {col1: '2_1', col2: 'B', col3: '2_3', col4: '2_4'}, - {col1: '3_1', col2: 'K', col3: '3_3', col4: '3_4'}, - {col1: '4_1', col2: 'J', col3: '4_3', col4: '4_4'}, - {col1: '5_1', col2: 'A', col3: '5_3', col4: '5_4'}, - {col1: '6_1', col2: 'C', col3: '6_3', col4: '6_4'}, - {col1: '7_1', col2: 'D', col3: '7_3', col4: '7_4'}, - {col1: '8_1', col2: 'P', col3: '8_3', col4: '8_4'}, - {col1: '9_1', col2: 'Q', col3: '9_3', col4: '9_4'}, - {col1: '10_1', col2: 'X', col3: '10_3', col4: '10_4'}, - {col1: '11_1', col2: 'H', col3: '11_3', col4: '11_4'}, - {col1: '12_1', col2: 'Y', col3: '12_3', col4: '12_4'}, - {col1: '13_1', col2: 'I', col3: '13_3', col4: '13_4'}, - {col1: '14_1', col2: 'L', col3: '14_3', col4: '14_4'}, - {col1: '15_1', col2: 'T', col3: '15_3', col4: '15_4'}, - {col1: '16_1', col2: 'W', col3: '16_3', col4: '16_4'}, - {col1: '17_1', col2: 'E', col3: '17_3', col4: '17_4'}, - {col1: '18_1', col2: 'N', col3: '18_3', col4: '18_4'}, - {col1: '19_1', col2: 'F', col3: '19_3', col4: '19_4'}, - {col1: '20_1', col2: 'Z', col3: '20_3', col4: '20_4'}, - {col1: '21_1', col2: 'V', col3: '21_3', col4: '21_4'}, - {col1: '22_1', col2: 'O', col3: '22_3', col4: '22_4'}, - {col1: '23_1', col2: 'M', col3: '23_3', col4: '23_4'}, - {col1: '24_1', col2: 'U', col3: '24_3', col4: '24_4'}, - {col1: '25_1', col2: 'S', col3: '25_3', col4: '25_4'}, - {col1: '26_1', col2: 'R', col3: '26_3', col4: '26_4'} - ], - onRegisterApi: function (api) { - gridApi = api; - }, - enablePagination: true, - paginationPageSize: 10 - }; - - var element = angular.element('
    '); - document.body.appendChild(element[0]); - gridElement = $compile(element)($rootScope); - $rootScope.$digest(); - })); - - describe('initialisation', function () { - it('registers the API and methods', function () { - expect(gridApi.pagination.getPage).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.getFirstRowIndex).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.getLastRowIndex).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.getTotalPages).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.nextPage).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.previousPage).toEqual(jasmine.any(Function)); - expect(gridApi.pagination.seek).toEqual(jasmine.any(Function)); - }); - }); - - describe('pagination', function () { - it('starts at page 1 with 10 records', function () { - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(1); - expect(gridRows.length).toBe(10); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('1_1'); - - var lastCell = gridRows.eq(9).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('10_4'); - }); - - it('calculates the total number of pages correctly', function () { - expect(gridApi.pagination.getTotalPages()).toBe(3); - }); - - it('displays page 2 if I call nextPage()', function () { - gridApi.pagination.nextPage(); - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(2); - expect(gridRows.length).toBe(10); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('11_1'); - - var lastCell = gridRows.eq(9).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('20_4'); - }); - - it('displays only 6 rows on page 3', function () { - gridApi.pagination.seek(3); - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(3); - expect(gridRows.length).toBe(6); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('21_1'); - - var lastCell = gridRows.eq(5).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('26_4'); - }); - - it('displays page 1 if I move to page 2 and back again', function () { - gridApi.pagination.nextPage(); - gridApi.pagination.previousPage(); - $rootScope.$digest(); - - expect(gridApi.pagination.getPage()).toBe(1); - }); - - it('does not allow to move before page 1', function () { - gridApi.pagination.previousPage(); - $rootScope.$digest(); - - expect(gridApi.pagination.getPage()).toBe(1); - }); - - it('does not allow to move past page 3', function () { - gridApi.pagination.nextPage(); - gridApi.pagination.nextPage(); - gridApi.pagination.nextPage(); - $rootScope.$digest(); - - expect(gridApi.pagination.getPage()).toBe(3); - }); - - it('paginates correctly on a sorted grid', function() { - gridApi.grid.sortColumn(gridApi.grid.columns[1]).then(function () { - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - expect(gridApi.pagination.getPage()).toBe(1); - expect(gridRows.eq(0).find('div.ui-grid-cell').eq(1).text()).toBe('A'); - expect(gridRows.eq(1).find('div.ui-grid-cell').eq(1).text()).toBe('B'); - expect(gridRows.eq(2).find('div.ui-grid-cell').eq(1).text()).toBe('C'); - expect(gridRows.eq(3).find('div.ui-grid-cell').eq(1).text()).toBe('D'); - expect(gridRows.eq(4).find('div.ui-grid-cell').eq(1).text()).toBe('E'); - expect(gridRows.eq(5).find('div.ui-grid-cell').eq(1).text()).toBe('F'); - expect(gridRows.eq(6).find('div.ui-grid-cell').eq(1).text()).toBe('G'); - expect(gridRows.eq(7).find('div.ui-grid-cell').eq(1).text()).toBe('H'); - expect(gridRows.eq(8).find('div.ui-grid-cell').eq(1).text()).toBe('I'); - expect(gridRows.eq(9).find('div.ui-grid-cell').eq(1).text()).toBe('J'); - - gridApi.pagination.nextPage(); - $rootScope.$digest(); - - gridRows = gridElement.find('div.ui-grid-row'); - expect(gridApi.pagination.getPage()).toBe(2); - expect(gridRows.eq(0).find('div.ui-grid-cell').eq(1).text()).toBe('K'); - }); - }); - }); - - describe('custom pagination', function () { - - var pages = ['COSU', 'DJLPQTVX', 'ABFGHIKNRY', 'EMWZ']; - - function getPage(data, pageNumber) { - return data.filter(function(datum) { - return pages[pageNumber-1].indexOf(datum.col2) >= 0; - }); - } - - beforeEach(inject(function (_$rootScope_, _$timeout_, $compile) { - $rootScope = _$rootScope_; - $timeout = _$timeout_; - - $rootScope.gridOptions.useCustomPagination = true; - $rootScope.gridOptions.useExternalPagination = true; - $rootScope.gridOptions.paginationPageSizes = [4,8,10,4]; - - var data = $rootScope.gridOptions.data; - $rootScope.gridOptions.data = getPage(data, 1); - gridApi.pagination.on.paginationChanged($rootScope, function (pageNumber) { - $rootScope.gridOptions.data = getPage(data, pageNumber); - }); - - $rootScope.$digest(); - })); - - it('starts at page 1 with 4 records', function () { - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(1); - expect(gridRows.length).toBe(4); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('6_1'); - - var lastCell = gridRows.eq(3).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('25_4'); - }); - - it('calculates the total number of pages correctly', function () { - expect(gridApi.pagination.getTotalPages()).toBe(4); - }); - - it('displays page 2 if I call nextPage()', function () { - gridApi.pagination.nextPage(); - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(2); - expect(gridRows.length).toBe(8); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('4_1'); - - var lastCell = gridRows.eq(7).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('21_4'); - }); - - it('displays 10 rows on page 3', function () { - gridApi.pagination.seek(3); - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - - expect(gridApi.pagination.getPage()).toBe(3); - expect(gridRows.length).toBe(10); - - var firstCell = gridRows.eq(0).find('div.ui-grid-cell:first-child'); - expect(firstCell.text()).toBe('1_1'); - - var lastCell = gridRows.eq(9).find('div.ui-grid-cell:last-child'); - expect(lastCell.text()).toBe('26_4'); - }); - - it('paginates correctly on a sorted grid', function() { - gridApi.grid.sortColumn(gridApi.grid.columns[1]).then(function () { - gridApi.pagination.seek(3); - $rootScope.$digest(); - $timeout.flush(); - - var gridRows = gridElement.find('div.ui-grid-row'); - expect(gridApi.pagination.getPage()).toBe(1); - expect(gridRows.eq(0).find('div.ui-grid-cell').eq(1).text()).toBe('A'); - expect(gridRows.eq(1).find('div.ui-grid-cell').eq(1).text()).toBe('B'); - expect(gridRows.eq(2).find('div.ui-grid-cell').eq(1).text()).toBe('F'); - expect(gridRows.eq(3).find('div.ui-grid-cell').eq(1).text()).toBe('G'); - expect(gridRows.eq(4).find('div.ui-grid-cell').eq(1).text()).toBe('H'); - expect(gridRows.eq(5).find('div.ui-grid-cell').eq(1).text()).toBe('I'); - expect(gridRows.eq(6).find('div.ui-grid-cell').eq(1).text()).toBe('K'); - expect(gridRows.eq(7).find('div.ui-grid-cell').eq(1).text()).toBe('N'); - expect(gridRows.eq(8).find('div.ui-grid-cell').eq(1).text()).toBe('R'); - expect(gridRows.eq(9).find('div.ui-grid-cell').eq(1).text()).toBe('Y'); - - gridApi.pagination.nextPage(); - $rootScope.$digest(); - - gridRows = gridElement.find('div.ui-grid-row'); - expect(gridApi.pagination.getPage()).toBe(2); - expect(gridRows.eq(0).find('div.ui-grid-cell').eq(1).text()).toBe('E'); - }); - }); - }); -}); diff --git a/src/features/pinning/test/pinning.spec.js b/src/features/pinning/test/pinning.spec.js deleted file mode 100644 index a3d09649e0..0000000000 --- a/src/features/pinning/test/pinning.spec.js +++ /dev/null @@ -1,204 +0,0 @@ -/* global _ */ -(function() { - "use strict"; - xdescribe('ui.grid.pinning', function () { - var grid, $scope, $compile, recompile, controller, timeout, GridRenderContainerClass; - - var data = [ - { "name": "Ethel Price", "gender": "female", "company": "Enersol" }, - { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" }, - { "name": "Beryl Rice", "gender": "female", "company": "Velity" }, - { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" } - ]; - - beforeEach(function () { - angular.module('ui.grid.pinning.test', ['ui.grid']) - .controller('uiGridController', function ($scope, $q, $timeout) { - controller = this; - $scope = { - grid: { - id: 512, - registerColumnBuilder: jasmine.createSpy('registerColumnBuilder'), - enablePinning: jasmine.createSpy('enablePinning'), - registerStyleComputation: jasmine.createSpy('registerStyleComputation'), - registerViewportAdjusters: jasmine.createSpy('registerViewportAdjusters'), - renderingComplete: jasmine.createSpy('renderingComplete'), - refreshCanvas: jasmine.createSpy('refreshCanvas'), - getViewportHeight: jasmine.createSpy('getViewportHeight').andReturn('333'), - renderContainers: { - body: { - registerViewportAdjuster: jasmine.createSpy('registerViewportAdjusters for body container') - } - }, - options: {} - } - }; - this.grid = $scope.grid; - this.scope = $scope; - this.refresh = jasmine.createSpy().andCallFake(function () { - var deferred = $q.defer(); - $timeout(function () { - deferred.resolve(); - }); - return deferred.promise; - }); - timeout = $timeout; - }); - }); - beforeEach(module('ui.grid')); - beforeEach(module('ui.grid.pinning')); - beforeEach(module('ui.grid.pinning.test')); - - beforeEach(inject(function (_$compile_, $rootScope, GridRenderContainer) { - GridRenderContainerClass = GridRenderContainer; - - $scope = $rootScope; - $compile = _$compile_; - - $scope.gridOpts = { - enablePinning: true, - data: data - }; - - $scope.gridOpts.columnDefs = [ - { name: 'name', width: 100 }, - { name: 'gender', width: 100 }, - { name: 'company', width: 150 } - ]; - - recompile = function () { - grid = angular.element('
    '); - document.body.appendChild(grid[0]); - $compile(grid)($scope); - $scope.$digest(); - }; - recompile(); - })); - - afterEach(function () { - angular.element(grid).remove(); - grid = null; - }); - - describe('enables pinning when gridOptions.enablePinning is true', function () { - it('should add pinned containers to the DOM', function () { - var leftContainer = $(grid).find('[ui-grid-pinned-container*=left]'); - expect(leftContainer.size()).toEqual(1); - - var rightContainer = $(grid).find('[ui-grid-pinned-container*=right]'); - expect(rightContainer.size()).toEqual(1); - }); - - it('should add pinned containers to the grid object', function () { - expect(controller.grid.renderContainers.left).toEqual(jasmine.any(GridRenderContainerClass)); - expect(controller.grid.renderContainers.right).toEqual(jasmine.any(GridRenderContainerClass)); - }); - - it('should register column builders', function () { - expect(controller.grid.registerColumnBuilder).toHaveBeenCalledWith(jasmine.any(Function)); - }); - - - describe('registered menu actions', function () { - var columnBuilder, colDef, col, gridOpts; - - beforeEach(function () { - columnBuilder = controller.grid.registerColumnBuilder.mostRecentCall.args[0]; - - colDef = $scope.gridOpts.columnDefs[0]; - - col = { - menuItems: [] - }; - - gridOpts = $scope.gridOpts; - - columnBuilder(colDef, col, gridOpts); - }); - - it('should set the enablePinning flag on the column', function () { - expect(col.enablePinning).toBeTruthy(); - }); - - it('should register menu actions for pinnable columns', function () { - expect(col.menuItems.length).toEqual(2); - expect(col.menuItems[0].title).toEqual('Pin Left'); - expect(col.menuItems[0].action).toEqual(jasmine.any(Function)); - expect(col.menuItems[1].title).toEqual('Pin Right'); - expect(col.menuItems[1].action).toEqual(jasmine.any(Function)); - }); - - it('should pin a column to the left container and refresh the grid twice when pin left action is activated', function () { - var actionFunction = col.menuItems[0].action; - - var jsScope = { - context: { - col: {} - } - }; - - expect(controller.refresh.calls.length).toEqual(0); - - actionFunction.apply(jsScope); - - expect(jsScope.context.col.renderContainer).toEqual('left'); - - expect(controller.refresh.calls.length).toEqual(1); - timeout.flush(); - expect(controller.refresh.calls.length).toEqual(2); - }); - - it('should pin a column to the right container when pin right action is activated', function () { - var actionFunction = col.menuItems[1].action; - - var jsScope = { - context: { - col: {} - } - }; - - expect(controller.refresh.calls.length).toEqual(0); - - actionFunction.apply(jsScope); - - expect(jsScope.context.col.renderContainer).toEqual('right'); - }); - }); - - it('should move column to the left column when moved to the left', function () { - - }); - - }); - - describe('uiGridPinnedContainer directive', function() { - it('should register a viewport adjuster for the body container that adjusts the body\'s width', function () { - expect(controller.grid.renderContainers.body.registerViewportAdjuster) - .toHaveBeenCalledWith(jasmine.any(Function)); - - var viewPortAdjusterFunction = controller.grid.renderContainers.body.registerViewportAdjuster.mostRecentCall.args[0]; - var adjustment = viewPortAdjusterFunction({width: 500}); - - // TODO Test that the adjuster adjusts - }); - - it('should register a style computation function', function() { - expect(controller.grid.registerStyleComputation) - .toHaveBeenCalledWith({ - priority: 15, - func: jasmine.any(Function) - }); - - var updateContainerDimensionsFunction = _(controller.grid.registerStyleComputation.calls) - .pluck('args') - .flatten() - .pluck('func') - .filter(function(it) { - return it.toString().indexOf('updateContainerDimensions()') === 9; - }) - .first(); - - }); - }); - }); -})(); \ No newline at end of file diff --git a/src/features/pinning/test/uiGridPinningService.spec.js b/src/features/pinning/test/uiGridPinningService.spec.js deleted file mode 100644 index be5bc09afa..0000000000 --- a/src/features/pinning/test/uiGridPinningService.spec.js +++ /dev/null @@ -1,206 +0,0 @@ -/* global _ */ -describe('ui.grid.pinning uiGridPinningService', function () { - var uiGridPinningService; - var uiGridPinningConstants; - var gridClassFactory; - var grid; - var GridRenderContainer; - - beforeEach(module('ui.grid.pinning')); - - beforeEach(inject(function (_uiGridPinningService_,_gridClassFactory_, $templateCache, _GridRenderContainer_, _uiGridPinningConstants_) { - uiGridPinningService = _uiGridPinningService_; - uiGridPinningConstants = _uiGridPinningConstants_; - gridClassFactory = _gridClassFactory_; - GridRenderContainer = _GridRenderContainer_; - })); - beforeEach(function() { - grid = gridClassFactory.createGrid({}); - spyOn(grid, 'registerColumnBuilder'); - - grid.options.columnDefs = [ - {field: 'col1'} - ]; - - uiGridPinningService.initializeGrid(grid); - grid.options.data = [{col1:'a'},{col1:'b'}]; - - grid.buildColumns(); - }); - - describe('initialize', function() { - - it('should have pinning enabled', function() { - expect(grid.options.enablePinning).toBe(true); - }); - - it('should register a column builder to the grid', function() { - expect(grid.registerColumnBuilder).toHaveBeenCalledWith(uiGridPinningService.pinningColumnBuilder); - }); - }); - - describe('defaultGridOptions', function () { - it('should default to true', function () { - var options = {}; - uiGridPinningService.defaultGridOptions(options); - expect(options.enablePinning).toBe(true); - }); - it('should allow false', function () { - var options = {enablePinning:false}; - uiGridPinningService.defaultGridOptions(options); - expect(options.enablePinning).toBe(false); - }); - }); - - describe('pinningColumnBuilder', function() { - var mockCol, colOptions, gridOptions; - - beforeEach(function() { - mockCol = {menuItems: [], grid: grid}; - colOptions = {}; - gridOptions = {enablePinning:true}; - }); - - it('should enable column pinning when pinning allowed for the grid', function() { - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - - expect(colOptions.enablePinning).toBe(true); - }); - - it('should disable column pinning when pinning disabled for the column', function() { - colOptions = {enablePinning: false}; - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - - expect(colOptions.enablePinning).toBe(false); - }); - - it('should enable column pinning when pinning enabled for the column', function() { - colOptions = {enablePinning: true}; - gridOptions = {enablePinning: false}; - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - - expect(colOptions.enablePinning).toBe(true); - }); - - it('should pin left when pinnedLeft=true', function() { - colOptions = {pinnedLeft: true}; - gridOptions = {enablePinning: false}; - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - expect(grid.renderContainers.left).toEqual(jasmine.any(GridRenderContainer)); - expect(grid.renderContainers.right).not.toBeDefined(); - - expect(mockCol.renderContainer).toBe('left'); - }); - - it('should pin left if both PinnedLeft and PinnedRight', function() { - colOptions = {pinnedLeft: true, pinnedRight:true}; - gridOptions = {enablePinning: false}; - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - - expect(mockCol.renderContainer).toBe('left'); - }); - - it('should pin right when pinnedRight=true', function() { - colOptions = {pinnedRight: true}; - gridOptions = {enablePinning: false}; - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - expect(grid.renderContainers.right).toEqual(jasmine.any(GridRenderContainer)); - expect(grid.renderContainers.left).not.toBeDefined(); - - expect(mockCol.renderContainer).toBe('right'); - }); - - it('should register menu actions for pinnable columns', function () { - function testMenuItem(obj) { - expect(obj.title).toEqual(jasmine.any(String)); - expect(obj.icon.indexOf('ui-grid-icon-')).toEqual(0); - expect(obj.shown).toEqual(jasmine.any(Function)); - expect(obj.action).toEqual(jasmine.any(Function)); - } - - uiGridPinningService.pinningColumnBuilder(colOptions, mockCol, gridOptions); - - expect(mockCol.menuItems.length).toEqual(3); - _(mockCol.menuItems).each(function(it) { - testMenuItem(it); - }); - }); - - - }); - - describe('pinColumn', function() { - - var previousWidth; - - beforeEach(function() { - spyOn(grid, 'createLeftContainer').and.callThrough(); - spyOn(grid, 'createRightContainer').and.callThrough(); - previousWidth = grid.columns[0].drawnWidth; - }); - - describe('left', function() { - - beforeEach(function() { - grid.api.pinning.pinColumn(grid.columns[0], uiGridPinningConstants.container.LEFT); - }); - - it('should set renderContainer to be left', function(){ - expect(grid.columns[0].renderContainer).toEqual('left'); - }); - - it('should call createLeftContainer', function() { - expect(grid.createLeftContainer).toHaveBeenCalled(); - }); - - it('should set width based on previous setting', function() { - expect(grid.width).toEqual(previousWidth); - }); - - }); - - describe('right', function() { - - beforeEach(function() { - grid.api.pinning.pinColumn(grid.columns[0], uiGridPinningConstants.container.RIGHT); - }); - - it('should set renderContainer to be right', function(){ - expect(grid.columns[0].renderContainer).toEqual('right'); - }); - - it('should call createLeftContainer', function() { - expect(grid.createRightContainer).toHaveBeenCalled(); - }); - - it('should set width based on previous setting', function() { - expect(grid.width).toEqual(previousWidth); - }); - - }); - - describe('none', function() { - - beforeEach(function() { - grid.api.pinning.pinColumn(grid.columns[0], uiGridPinningConstants.container.NONE); - }); - - it('should set renderContainer to be null', function(){ - expect(grid.columns[0].renderContainer).toBeNull(); - }); - - it('should NOT call either container creation methods', function() { - expect(grid.createLeftContainer).not.toHaveBeenCalled(); - expect(grid.createRightContainer).not.toHaveBeenCalled(); - }); - - }); - - }); - -}); diff --git a/src/features/resize-columns/templates/columnResizer.html b/src/features/resize-columns/templates/columnResizer.html deleted file mode 100644 index 597648d597..0000000000 --- a/src/features/resize-columns/templates/columnResizer.html +++ /dev/null @@ -1,9 +0,0 @@ -
    -
    \ No newline at end of file diff --git a/src/features/resize-columns/test/resizeColumns.spec.js b/src/features/resize-columns/test/resizeColumns.spec.js deleted file mode 100644 index bbd452c694..0000000000 --- a/src/features/resize-columns/test/resizeColumns.spec.js +++ /dev/null @@ -1,347 +0,0 @@ -describe('ui.grid.resizeColumns', function () { - var grid, gridUtil, gridScope, $scope, $compile, recompile, uiGridConstants; - - var downEvent, upEvent, moveEvent; - - var data = [ - { "name": "Ethel Price", "gender": "female", "company": "Enersol" }, - { "name": "Claudine Neal", "gender": "female", "company": "Sealoud" }, - { "name": "Beryl Rice", "gender": "female", "company": "Velity" }, - { "name": "Wilder Gonzales", "gender": "male", "company": "Geekko" } - ]; - - beforeEach(module('ui.grid')); - beforeEach(module('ui.grid.resizeColumns')); - - beforeEach(inject(function (_$compile_, $rootScope, _uiGridConstants_, _gridUtil_) { - $scope = $rootScope; - $compile = _$compile_; - uiGridConstants = _uiGridConstants_; - gridUtil = _gridUtil_; - - if (gridUtil.isTouchEnabled()) { - downEvent = 'touchstart'; - upEvent = 'touchend'; - moveEvent = 'touchmove'; - } - else { - downEvent = 'mousedown'; - upEvent = 'mouseup'; - moveEvent = 'mousemove'; - } - - $scope.gridOpts = { - enableColumnResizing: true, - data: data - }; - - $scope.gridOpts.onRegisterApi = function (gridApi) { - $scope.gridApi = gridApi; - }; - - recompile = function () { - gridUtil.resetUids(); - - grid = angular.element('
    '); - document.body.appendChild(grid[0]); - $compile(grid)($scope); - $scope.$digest(); - gridScope = $(grid).isolateScope(); - }; - - recompile(); - })); - - afterEach(function () { - angular.element(grid).remove(); - grid = null; - }); - - describe('checking grid api for colResizable', function() { - it('columnSizeChanged should be defined', function () { - expect($scope.gridApi.colResizable.on.columnSizeChanged).toBeDefined(); - }); - }); - - describe('setting enableColumnResizing', function () { - it('should by default cause resizer to be attached to the header elements', function () { - var resizers = $(grid).find('[ui-grid-column-resizer]'); - - expect(resizers.size()).toEqual(5); - }); - - it('should only attach a right resizer to the first column', function () { - var firstColumn = $(grid).find('[ui-grid-header-cell]').first(); - - var resizers = $(firstColumn).find('[ui-grid-column-resizer]'); - - expect(resizers.size()).toEqual(1); - - expect(resizers.first().attr('position')).toEqual('right'); - expect(resizers.first().hasClass('right')).toBe(true); - }); - - it('should attach left and right resizers to the last column', function () { - var firstColumn = $(grid).find('[ui-grid-header-cell]').last(); - - var resizers = $(firstColumn).find('[ui-grid-column-resizer]'); - - expect(resizers.size()).toEqual(2); - - expect(resizers.first().attr('position')).toEqual('left'); - expect(resizers.first().hasClass('left')).toBe(true); - }); - }); - - describe('setting enableColumnResizing to false', function () { - it('should result in no resizer elements being attached to the column', function () { - $scope.gridOpts.enableColumnResizing = false; - recompile(); - - var resizers = $(grid).find('[ui-grid-column-resizer]'); - - expect(resizers.size()).toEqual(0); - }); - }); - - describe('setting flag on colDef to false', function () { - it('should result in only one resizer elements being attached to the column and the column to it\'s right', function () { - $scope.gridOpts.columnDefs = [ - { field: 'name' }, - { field: 'gender', enableColumnResizing: false }, - { field: 'company' } - ]; - - recompile(); - - var middleCol = $(grid).find('[ui-grid-header-cell]:nth-child(2)'); - var resizer = middleCol.find('[ui-grid-column-resizer]'); - - expect(resizer.size()).toEqual(1); - - var lastCol = $(grid).find('[ui-grid-header-cell]:nth-child(3)'); - resizer = lastCol.find('[ui-grid-column-resizer]'); - - expect(resizer.size()).toEqual(1); - }); - }); - - describe('setting flag on grid options to false', function () { - it('should not have any resizers', function () { - $scope.gridOpts.enableColumnResizing = false; - recompile(); - - var resizers = $(grid).find('[ui-grid-column-resizer]'); - - expect(resizers.size()).toEqual(0); - }); - }); - - // NOTE: these pixel sizes might fail in other browsers, due to font differences! - describe('double-clicking a resizer', function () { - // TODO(c0bra): We account for menu button and sort icon size now, so this test is failing. - xit('should resize the column to the maximum width of the rendered columns', function (done) { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - - var colWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + '0').first().width(); - - expect(colWidth === 166 || colWidth === 167).toBe(true); // allow for column widths that don't equally divide - - firstResizer.trigger('dblclick'); - - $scope.$digest(); - - var newColWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + '0').first().width(); - - // Can't really tell how big the columns SHOULD be, we'll just expect them to be different in width now - expect(newColWidth).not.toEqual(colWidth); - }); - }); - - describe('clicking on a resizer', function () { - it('should cause the column separator overlay to be added', function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - - firstResizer.trigger(downEvent); - $scope.$digest(); - - var overlay = $(grid).find('.ui-grid-resize-overlay'); - - expect(overlay.size()).toEqual(1); - - // The grid shouldn't have the resizing class - expect(grid.hasClass('column-resizing')).toEqual(false); - }); - - describe('and moving the mouse', function () { - var xDiff, initialWidth, initialX, overlay, initialOverlayX; - - beforeEach(function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - - // Get the initial width of the column - var firstColumnUid = gridScope.grid.columns[0].uid; - initialWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - - initialX = firstResizer.position().left; - - $(firstResizer).simulate(downEvent, { clientX: initialX }); - $scope.$digest(); - - // Get the overlay - overlay = $(grid).find('.ui-grid-resize-overlay'); - initialOverlayX = $(overlay).position().left; - - xDiff = 100; - $(document).simulate(moveEvent, { clientX: initialX + xDiff }); - $scope.$digest(); - }); - - it('should add the column-resizing class to the grid', function () { - // The grid should have the resizing class - expect(grid.hasClass('column-resizing')).toEqual(true); - }); - - it('should cause the overlay to appear', function () { - expect(overlay.is(':visible')).toEqual(true); - }); - - // TODO(c0bra): This test is failing on Travis (PhantomJS on Linux). - xit('should cause the overlay to move', function () { - // TODO(c0bra): This tests fails on IE9 and Opera on linx. It gets 253 instead if 262 (9 pixels off) - //expect($(overlay).position().left).toEqual( (initialX + xDiff + 1) ); // Extra one pixel here for grid border - expect($(overlay).position().left).not.toEqual(initialX); // Extra one pixel here for grid border - }); - - describe('then releasing the mouse', function () { - beforeEach(function () { - $(document).simulate(upEvent, { clientX: initialX + xDiff }); - $scope.$digest(); - }); - - it('should cause the column to resize by the amount change in the X axis', function () { - var firstColumnUid = gridScope.grid.columns[0].uid; - var newWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - expect(newWidth - initialWidth).toEqual(xDiff); - }); - - it('should remove the overlay', function () { - var overlay = $(grid).find('.ui-grid-resize-overlay'); - - expect(overlay.size()).toEqual(0); - }); - }); - }); - }); - - describe('when a column has a minWidth', function () { - var minWidth; - - beforeEach(function () { - minWidth = 200; - - $scope.gridOpts.columnDefs = [ - { field: 'name', minWidth: minWidth }, - { field: 'gender' }, - { field: 'company' } - ]; - - recompile(); - }); - - describe('and you double-click its resizer, the column width', function () { - it('should not go below the minWidth less border', function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - - $(firstResizer).simulate('dblclick'); - $scope.$digest(); - - var firstColumnUid = gridScope.grid.columns[0].uid; - - var newWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - - expect(newWidth >= (minWidth - 1)).toEqual(true); - }); - }); - - describe('and you move its resizer left further than the minWidth, the column width', function () { - var initialX; - - beforeEach(function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - initialX = firstResizer.position().left; - - $(firstResizer).simulate(downEvent, { clientX: initialX }); - $scope.$digest(); - - $(document).simulate(upEvent, { clientX: initialX - minWidth }); - $scope.$digest(); - }); - - it('should not go below the minWidth less border', function () { - var firstColumnUid = gridScope.grid.columns[0].uid; - - var newWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - - expect(newWidth >= (minWidth - 1)).toEqual(true); - }); - }); - }); - - // Don't run this on IE9. The behavior looks correct when testing interactively but these tests fail - if (!navigator.userAgent.match(/MSIE\s+9\.0/)) { - describe('when a column has a maxWidth', function () { - var maxWidth; - - beforeEach(function () { - maxWidth = 60; - - $scope.gridOpts.columnDefs = [ - { field: 'name', maxWidth: maxWidth }, - { field: 'gender' }, - { field: 'company' } - ]; - - recompile(); - }); - - describe('and you double-click its resizer', function () { - it('the column width should not go above the maxWidth', function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - - $(firstResizer).simulate('dblclick'); - $scope.$digest(); - - var firstColumnUid = gridScope.grid.columns[0].uid; - - var newWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - - expect(newWidth <= maxWidth).toEqual(true); - }); - }); - - describe('and you move its resizer right further than the maxWidth, the column width', function () { - var initialX; - - beforeEach(function () { - var firstResizer = $(grid).find('[ui-grid-column-resizer]').first(); - initialX = firstResizer.position().left; - - $(firstResizer).simulate(downEvent, { clientX: initialX }); - $scope.$digest(); - - $(document).simulate(upEvent, { clientX: initialX + maxWidth }); - $scope.$digest(); - }); - - it('should not go above the maxWidth', function () { - var firstColumnUid = gridScope.grid.columns[0].uid; - - var newWidth = $(grid).find('.' + uiGridConstants.COL_CLASS_PREFIX + firstColumnUid).first().width(); - - expect(newWidth <= maxWidth).toEqual(true); - }); - }); - }); - } -}); diff --git a/src/features/resize-columns/test/resizeColumnsService.spec.js b/src/features/resize-columns/test/resizeColumnsService.spec.js deleted file mode 100644 index 88f35c2931..0000000000 --- a/src/features/resize-columns/test/resizeColumnsService.spec.js +++ /dev/null @@ -1,72 +0,0 @@ -describe('uiGridResizeColumnsService', function () { - var uiGridResizeColumnsService; - - beforeEach(module('ui.grid.resizeColumns')); - - beforeEach(inject(function (_uiGridResizeColumnsService_) { - uiGridResizeColumnsService = _uiGridResizeColumnsService_; - })); - - describe('defaultGridOptions', function () { - it('should default enableColumnResizing to true', function () { - var gridOptions = {}; - uiGridResizeColumnsService.defaultGridOptions(gridOptions); - expect(gridOptions.enableColumnResizing).toBe(true); - }); - - it('should not override false gridOptions.enableColumnResizing', function () { - var gridOptions = {enableColumnResizing:false}; - uiGridResizeColumnsService.defaultGridOptions(gridOptions); - expect(gridOptions.enableColumnResizing).toBe(false); - }); - - it('should not override false gridOptions.enableColumnResize (legacy support)', function () { - var gridOptions = {enableColumnResize:false}; - uiGridResizeColumnsService.defaultGridOptions(gridOptions); - expect(gridOptions.enableColumnResizing).toBe(false); - }); - }); - - describe('colResizerColumnBuilder', function () { - it('should default enableColumnResizing to true', inject(function ($timeout) { - var colDef = {name:'col1'}; - var gridOptions = {enableColumnResizing:true, colDefs:[colDef]}; - $timeout(function(){ - uiGridResizeColumnsService.colResizerColumnBuilder(colDef,null, gridOptions); - }); - $timeout.flush(); - expect(gridOptions.colDefs[0].enableColumnResizing).toBe(true); - })); - - it('should not override a colDef setting enableColumnResizing', inject(function ($timeout) { - var colDef = {name:'col1', enableColumnResizing:false}; - var gridOptions = {enableColumnResizing:true, colDefs:[colDef]}; - $timeout(function(){ - uiGridResizeColumnsService.colResizerColumnBuilder(colDef,null, gridOptions); - }); - $timeout.flush(); - expect(gridOptions.colDefs[0].enableColumnResizing).toBe(false); - })); - - it('should override gridOptions enableColumnResizing', inject(function ($timeout) { - var colDef = {name:'col1', enableColumnResizing:true}; - var gridOptions = {enableColumnResizing:false, colDefs:[colDef]}; - $timeout(function(){ - uiGridResizeColumnsService.colResizerColumnBuilder(colDef,null, gridOptions); - }); - $timeout.flush(); - expect(gridOptions.colDefs[0].enableColumnResizing).toBe(true); - })); - - it('should default enableColumnResizing to false if gridOptions is false', inject(function ($timeout) { - var colDef = {name:'col1'}; - var gridOptions = {enableColumnResizing:false, colDefs:[colDef]}; - $timeout(function(){ - uiGridResizeColumnsService.colResizerColumnBuilder(colDef,null, gridOptions); - }); - $timeout.flush(); - expect(gridOptions.colDefs[0].enableColumnResizing).toBe(false); - })); - - }); -}); diff --git a/src/features/row-edit/test/uiGridRowEditService.spec.js b/src/features/row-edit/test/uiGridRowEditService.spec.js deleted file mode 100644 index 8ad02283c6..0000000000 --- a/src/features/row-edit/test/uiGridRowEditService.spec.js +++ /dev/null @@ -1,573 +0,0 @@ -describe('ui.grid.edit uiGridRowEditService', function () { - var uiGridRowEditService; - var uiGridEditService; - var uiGridCellNavService; - var gridClassFactory; - var grid; - var $rootScope; - var $scope; - var $interval; - var $q; - - beforeEach(module('ui.grid.rowEdit')); - - beforeEach(inject(function (_uiGridRowEditService_, _uiGridEditService_, _uiGridCellNavService_, - _gridClassFactory_, $templateCache, - _$rootScope_, _$interval_, _$q_) { - uiGridRowEditService = _uiGridRowEditService_; - uiGridEditService = _uiGridEditService_; - uiGridCellNavService = _uiGridCellNavService_; - gridClassFactory = _gridClassFactory_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - $interval = _$interval_; - $q = _$q_; - - grid = gridClassFactory.createGrid( { id: 1234 }); - grid.options.columnDefs = [ - {name: 'col1'}, - {name: 'col2'}, - {name: 'col3'}, - {name: 'col4'} - ]; - grid.options.data = [ - {col1: '1_1', col2: '1_2', col3: '1_3', col4: '1_4'}, - {col1: '2_1', col2: '2_2', col3: '2_3', col4: '2_4'}, - {col1: '3_1', col2: '3_2', col3: '3_3', col4: '3_4'}, - {col1: '4_1', col2: '4_2', col3: '4_3', col4: '4_4'} - ]; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - -// $templateCache.put('ui-grid/uiGridCell', '
    '); -// $templateCache.put('ui-grid/cellEditor', '
    '); - - - })); - - describe('initialisation: ', function () { - - it('register api, rowEdit methods and events are registered', function () { - - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - - grid.renderingComplete(); - - expect( grid.api.rowEdit.on.saveRow ).toEqual( jasmine.any(Function) ); - expect( grid.api.rowEdit.getDirtyRows ).toEqual( jasmine.any(Function) ); - expect( grid.api.rowEdit.getErrorRows ).toEqual( jasmine.any(Function) ); - expect( grid.api.rowEdit.flushDirtyRows ).toEqual( jasmine.any(Function) ); - expect( grid.api.rowEdit.setRowsDirty ).toEqual( jasmine.any(Function) ); - expect( grid.api.rowEdit.setRowsClean ).toEqual( jasmine.any(Function) ); - - }); - - describe('register api,', function() { - - beforeEach(function() { - spyOn( uiGridRowEditService, 'endEditCell' ).and.callFake( function() {} ); - spyOn( uiGridRowEditService, 'beginEditCell' ).and.callFake( function() {} ); - spyOn( uiGridRowEditService, 'cancelEditCell' ).and.callFake( function() {} ); - }); - - it('listener in place on edit events', function () { - - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - - grid.renderingComplete(); - - grid.api.edit.raise.afterCellEdit( ); - grid.api.edit.raise.beginCellEdit( ); - grid.api.edit.raise.cancelCellEdit( ); - - expect( uiGridRowEditService.endEditCell ).toHaveBeenCalled(); - expect( uiGridRowEditService.beginEditCell ).toHaveBeenCalled(); - expect( uiGridRowEditService.cancelEditCell ).toHaveBeenCalled(); - - }); - }); - - }); - - describe( 'beginEditCell: ', function() { - beforeEach( function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - }); - - it( 'no edit timer in place', function() { - grid.api.edit.raise.beginCellEdit( grid.options.data[0], grid.options.columnDefs[0] ); - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - }); - - it( 'edit timer in place is cancelled', function() { - var called = false; - - grid.rows[0].rowEditSaveTimer = $interval( function() { called = true; }, 1000, 2 ); - $interval.flush(1500); - expect( called ).toEqual( true ); - - called = false; - grid.api.edit.raise.beginCellEdit( grid.options.data[0], grid.options.columnDefs[0] ); - - $interval.flush(1500); - expect( called ).toEqual( false ); - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - }); - }); - - describe( 'endEditCell: ', function() { - var called; - beforeEach( function() { - called = false; - spyOn( uiGridRowEditService, 'saveRow' ).and.callFake( function() { - return function() { called = true;}; - }); - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - }); - - it( 'no change to cell value, nothing done', function() { - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - - grid.api.edit.raise.afterCellEdit( grid.options.data[0], grid.options.columnDefs[0], '1', '1' ); - expect( uiGridRowEditService.saveRow ).not.toHaveBeenCalled(); - expect( grid.rows[0].isDirty ).toEqual( undefined ); - expect( grid.rowEdit.dirtyRows ).toEqual( undefined ); - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - }); - - it( 'timer is not present beforehand, interval triggered at 2000ms', function() { - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - - grid.api.edit.raise.afterCellEdit( grid.options.data[0], grid.options.columnDefs[0], '1', '2' ); - expect( uiGridRowEditService.saveRow ).toHaveBeenCalledWith( grid, grid.rows[0] ); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length ).toEqual( 1 ); - - expect( grid.rows[0].rowEditSaveTimer ).not.toEqual( undefined ); - - $interval.flush(1900); - expect( called ).toEqual(false); - - $interval.flush(200); - expect( called ).toEqual(true); - }); - - it( 'row already dirty so even though value not changed, interval triggered at 2000ms', function() { - grid.rows[0].isDirty = true; - grid.rowEdit.dirtyRows = [ grid.rows[0] ]; - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - - grid.api.edit.raise.afterCellEdit( grid.options.data[0], grid.options.columnDefs[0], '1', '1' ); - expect( uiGridRowEditService.saveRow ).toHaveBeenCalledWith( grid, grid.rows[0] ); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length ).toEqual( 1 ); - - expect( grid.rows[0].rowEditSaveTimer ).not.toEqual( undefined ); - - $interval.flush(1900); - expect( called ).toEqual(false); - - $interval.flush(200); - expect( called ).toEqual(true); - }); - - it( 'timer is not present beforehand, timer interval set to -1 so not created', function() { - grid.options.rowEditWaitInterval = -1; - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - - grid.api.edit.raise.afterCellEdit( grid.options.data[0], grid.options.columnDefs[0], '1', '2' ); - expect( uiGridRowEditService.saveRow ).not.toHaveBeenCalled(); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length ).toEqual( 1 ); - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - - $interval.flush(1900); - expect( called ).toEqual(false); - - $interval.flush(200); - expect( called ).toEqual(false); - }); - - it( 'edit timer is in place beforehand and is cancelled, a new one is created and triggered at non-standard 4000ms', function() { - grid.options.rowEditWaitInterval = 4000; - - grid.rows[0].rowEditSaveTimer = $interval( function() { called = true; }, 1000 ); - $interval.flush(900); - expect( called ).toEqual( false ); - - grid.api.edit.raise.afterCellEdit( grid.options.data[0], grid.options.columnDefs[0], '1', '2' ); - expect( uiGridRowEditService.saveRow ).toHaveBeenCalledWith( grid, grid.rows[0] ); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rowEdit.dirtyRows.length ).toEqual( 1 ); - - // old interval not called - $interval.flush(200); - expect( called ).toEqual( false ); - - // only 2.1 seconds, new interval not called yet - $interval.flush(1900); - expect( called ).toEqual(false); - - // 4.1 seconds, now should be called - $interval.flush(2000); - expect( called ).toEqual(true); - }); - }); - - - describe( 'cancelEditCell: ', function() { - beforeEach( function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - }); - - it( 'do nothing if row not previously dirty', function() { - grid.api.edit.raise.cancelCellEdit( grid.options.data[0], grid.options.columnDefs[0] ); - - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - }); - - it( 'reinstate timer if row was previously dirty', function() { - grid.rows[0].isDirty = true; - - grid.api.edit.raise.cancelCellEdit( grid.options.data[0], grid.options.columnDefs[0] ); - - expect( grid.rows[0].rowEditSaveTimer ).not.toEqual( undefined ); - }); - }); - - - describe( 'navigate: ', function() { - var oldCell; - var newCell; - - beforeEach( function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - uiGridCellNavService.initializeGrid( grid ); - grid.renderingComplete(); - - oldCell = { row: grid.rows[2], col: grid.columns[2] }; - newCell = { row: grid.rows[1], col: grid.columns[1] }; - }); - - it( 'new row dirty, had a timer, timer cancelled', function() { - grid.rows[1].rowEditSaveTimer = $interval( function() {}, 1000 ); - grid.rows[1].isDirty = true; - - grid.api.cellNav.raise.navigate( newCell, oldCell ); - - expect( grid.rows[1].rowEditSaveTimer ).toEqual( undefined ); - }); - - it( 'new row dirty, but is saving, timer not cancelled', function() { - grid.rows[1].rowEditSaveTimer = $interval( function() {}, 1000 ); - grid.rows[1].isDirty = true; - grid.rows[1].isSaving = true; - - grid.api.cellNav.raise.navigate( newCell, oldCell ); - - expect( grid.rows[1].rowEditSaveTimer ).not.toEqual( undefined ); - }); - - it( 'old row clean, no timer created', function() { - grid.api.cellNav.raise.navigate( newCell, oldCell ); - - expect( grid.rows[2].rowEditSaveTimer ).toEqual( undefined ); - }); - - it( 'old row dirty, timer created', function() { - grid.rows[2].isDirty = true; - - grid.api.cellNav.raise.navigate( newCell, oldCell ); - - expect( grid.rows[2].rowEditSaveTimer ).not.toEqual( undefined ); - }); - - it( 'old row saving, no timer created', function() { - grid.rows[2].isSaving = true; - grid.api.cellNav.raise.navigate( newCell, oldCell ); - - expect( grid.rows[2].rowEditSaveTimer ).toEqual( undefined ); - }); - }); - - - describe( 'saveRow and promises: ', function() { - beforeEach( function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - }); - - it( 'saveRow on previously errored row, promise resolved successfully', function() { - var promise = $q.defer(); - - grid.rows[0].isDirty = true; - grid.rows[0].isError = true; - grid.rowEdit.dirtyRows = [ grid.rows[0] ]; - grid.rowEdit.errorRows = [ grid.rows[0] ]; - grid.api.rowEdit.on.saveRow( $scope, function(){ - grid.api.rowEdit.setSavePromise( grid.options.data[0], promise.promise); - }); - - uiGridRowEditService.saveRow( grid, grid.rows[0] )(); - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rows[0].isDirty ).toEqual(true); - expect( grid.rows[0].isError ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( grid.rowEdit.errorRows.length ).toEqual(1); - - $rootScope.$apply(); - expect( grid.rows[0].rowEditSavePromise ).not.toEqual(undefined, 'save promise should be set'); - - promise.resolve(1); - $rootScope.$apply(); - - expect( grid.rows[0].isSaving ).toEqual(undefined); - expect( grid.rows[0].isDirty ).toEqual(undefined); - expect( grid.rows[0].isError ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(0); - expect( grid.rowEdit.errorRows.length ).toEqual(0); - expect( grid.rowEdit.rowEditSavePromise ).toEqual(undefined); - }); - - it( 'saveRow on dirty row, promise rejected so goes to error state', function() { - var promise = $q.defer(); - - grid.rows[0].isDirty = true; - grid.rowEdit.dirtyRows = [ grid.rows[0] ]; - grid.api.rowEdit.on.saveRow( $scope, function(){ - grid.api.rowEdit.setSavePromise( grid.options.data[0], promise.promise); - }); - - uiGridRowEditService.saveRow( grid, grid.rows[0] )(); - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rows[0].isDirty ).toEqual(true); - expect( grid.rows[0].isError ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( grid.rowEdit.errorRows ).toEqual(undefined); - - $rootScope.$apply(); - expect( grid.rows[0].rowEditSavePromise ).not.toEqual(undefined, 'save promise should be set'); - - promise.reject(); - $rootScope.$apply(); - - expect( grid.rows[0].isSaving ).toEqual(undefined); - expect( grid.rows[0].isDirty ).toEqual(true); - expect( grid.rows[0].isError ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( grid.rowEdit.errorRows.length ).toEqual(1); - expect( grid.rowEdit.rowEditSavePromise ).toEqual(undefined); - }); - }); - - - describe( 'flushDirtyRows: ', function() { - beforeEach( function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - }); - - it( 'three dirty rows, all save successfully', function() { - var promises = [$q.defer(), $q.defer(), $q.defer()]; - var promiseCounter = 0; - var success = false; - var failure = false; - - grid.rows[0].isDirty = true; - grid.rows[2].isDirty = true; - grid.rows[3].isDirty = true; - - grid.rowEdit.dirtyRows = [ grid.rows[0], grid.rows[2], grid.rows[3] ]; - - grid.api.rowEdit.on.saveRow( $scope, function( rowEntity ){ - grid.api.rowEdit.setSavePromise( rowEntity, promises[promiseCounter].promise); - promiseCounter++; - }); - - var overallPromise = uiGridRowEditService.flushDirtyRows( grid ); - overallPromise.then( function() { success = true; }, function() { failure = true; }); - - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rows[1].isSaving ).toEqual(undefined); - expect( grid.rows[2].isSaving ).toEqual(true); - expect( grid.rows[3].isSaving ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(3); - - promises[0].resolve(1); - $rootScope.$apply(); - - expect( grid.rows[0].isSaving ).toEqual(undefined); - expect( grid.rows[0].isDirty ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(2); - expect( success ).toEqual(false); - - promises[1].resolve(1); - promises[2].resolve(1); - $rootScope.$apply(); - - expect( grid.rows[2].isSaving ).toEqual(undefined); - expect( grid.rows[2].isDirty ).toEqual(undefined); - expect( grid.rows[3].isSaving ).toEqual(undefined); - expect( grid.rows[3].isDirty ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(0); - expect( success ).toEqual(true); - expect( failure ).toEqual(false); - }); - - it( 'one dirty rows, already saving, doesn\'t call save again', function() { - var promises = [$q.defer()]; - var promiseCounter = 0; - var success = false; - var failure = false; - - grid.rows[0].isDirty = true; - - grid.rowEdit.dirtyRows = [ grid.rows[0] ]; - - grid.api.rowEdit.on.saveRow( $scope, function( rowEntity ){ - grid.api.rowEdit.setSavePromise( rowEntity, promises[promiseCounter].promise); - promiseCounter++; - }); - - // set row saving - uiGridRowEditService.saveRow( grid, grid.rows[0] )(); - - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( promiseCounter ).toEqual(1); - - // flush dirty rows, expect no new promise - var overallPromise = uiGridRowEditService.flushDirtyRows( grid ); - overallPromise.then( function() { success = true; }, function() { failure = true; }); - - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( promiseCounter ).toEqual(1); - - promises[0].resolve(1); - $rootScope.$apply(); - - expect( grid.rows[0].isSaving ).toEqual(undefined); - expect( grid.rows[0].isDirty ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(0); - expect( success ).toEqual(true); - }); - - it( 'three dirty rows, one save fails', function() { - var promises = [$q.defer(), $q.defer(), $q.defer()]; - var promiseCounter = 0; - var success = false; - var failure = false; - - grid.rows[0].isDirty = true; - grid.rows[2].isDirty = true; - grid.rows[3].isDirty = true; - - grid.rowEdit.dirtyRows = [ grid.rows[0], grid.rows[2], grid.rows[3] ]; - - grid.api.rowEdit.on.saveRow( $scope, function( rowEntity ){ - grid.api.rowEdit.setSavePromise( rowEntity, promises[promiseCounter].promise); - promiseCounter++; - }); - - var overallPromise = uiGridRowEditService.flushDirtyRows( grid ); - overallPromise.then( function() { success = true; }, function() { failure = true; }); - - expect( grid.rows[0].isSaving ).toEqual(true); - expect( grid.rows[1].isSaving ).toEqual(undefined); - expect( grid.rows[2].isSaving ).toEqual(true); - expect( grid.rows[3].isSaving ).toEqual(true); - expect( grid.rowEdit.dirtyRows.length ).toEqual(3); - - promises[0].resolve(1); - $rootScope.$apply(); - - expect( grid.rows[0].isSaving ).toEqual(undefined); - expect( grid.rows[0].isDirty ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(2); - expect( success ).toEqual(false); - - promises[1].reject(); - promises[2].resolve(1); - $rootScope.$apply(); - - expect( grid.rows[2].isSaving ).toEqual(undefined); - expect( grid.rows[2].isDirty ).toEqual(true); - expect( grid.rows[2].isError ).toEqual(true); - expect( grid.rows[3].isSaving ).toEqual(undefined); - expect( grid.rows[3].isDirty ).toEqual(undefined); - expect( grid.rowEdit.dirtyRows.length ).toEqual(1); - expect( grid.rowEdit.errorRows.length ).toEqual(1); - expect( success ).toEqual(false); - expect( failure ).toEqual(true); - }); - - it( 'no dirty rows, no error is thrown', function() { - expect(function() { - uiGridRowEditService.flushDirtyRows( grid ); - }).not.toThrow(); - }); - }); - - - describe( 'setRowsDirty', function() { - it( 'rows are set dirty', function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - - grid.api.rowEdit.setRowsDirty( [ grid.options.data[0], grid.options.data[1] ]); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rows[0].rowEditSaveTimer ).not.toEqual( undefined ); - expect( grid.rows[1].isDirty ).toEqual( true ); - expect( grid.rows[1].rowEditSaveTimer ).not.toEqual( undefined ); - }); - }); - - - describe( 'setRowsClean', function() { - it( 'rows are set clean', function() { - uiGridRowEditService.initializeGrid( $scope, grid ); - uiGridEditService.initializeGrid( grid ); - grid.renderingComplete(); - - grid.api.rowEdit.setRowsDirty( [ grid.options.data[0], grid.options.data[1] ]); - expect( grid.rows[0].isDirty ).toEqual( true ); - expect( grid.rows[0].rowEditSaveTimer ).not.toEqual( undefined ); - expect( grid.rows[1].isDirty ).toEqual( true ); - expect( grid.rows[1].rowEditSaveTimer ).not.toEqual( undefined ); - expect( grid.rowEdit.dirtyRows.length).toEqual(2); - - grid.rows[0].isError = true; - grid.rowEdit.errorRows = []; - grid.rowEdit.errorRows.push( grid.rows[0] ); - expect( grid.rowEdit.errorRows.length).toEqual(1); - - grid.api.rowEdit.setRowsClean( [ grid.options.data[0], grid.options.data[1] ]); - - expect( grid.rows[0].isDirty ).toEqual( undefined ); - expect( grid.rows[0].rowEditSaveTimer ).toEqual( undefined ); - expect( grid.rows[1].isDirty ).toEqual( undefined ); - expect( grid.rows[1].rowEditSaveTimer ).toEqual( undefined ); - expect( grid.rowEdit.dirtyRows.length).toEqual(0); - expect( grid.rowEdit.errorRows.length).toEqual(0); - }); - }); -}); diff --git a/src/features/saveState/test/saveState.spec.js b/src/features/saveState/test/saveState.spec.js deleted file mode 100644 index aa41d4ad7f..0000000000 --- a/src/features/saveState/test/saveState.spec.js +++ /dev/null @@ -1,793 +0,0 @@ -describe('ui.grid.saveState uiGridSaveStateService', function () { - var uiGridSaveStateService; - var uiGridSaveStateConstants; - var uiGridSelectionService; - var uiGridCellNavService; - var uiGridGroupingService; - var uiGridTreeViewService; - var uiGridPinningService; - var gridClassFactory; - var grid; - var $compile; - var $scope; - var $document; - var $timeout; - - beforeEach(module('ui.grid.saveState')); - - - beforeEach(inject(function (_uiGridSaveStateService_, _gridClassFactory_, _uiGridSaveStateConstants_, - _$compile_, _$rootScope_, _$document_, _uiGridSelectionService_, - _uiGridCellNavService_, _uiGridGroupingService_, _uiGridTreeViewService_, - _uiGridPinningService_, _$timeout_) { - uiGridSaveStateService = _uiGridSaveStateService_; - uiGridSaveStateConstants = _uiGridSaveStateConstants_; - uiGridSelectionService = _uiGridSelectionService_; - uiGridCellNavService = _uiGridCellNavService_; - uiGridGroupingService = _uiGridGroupingService_; - uiGridTreeViewService = _uiGridTreeViewService_; - uiGridPinningService = _uiGridPinningService_; - gridClassFactory = _gridClassFactory_; - $compile = _$compile_; - $scope = _$rootScope_.$new(); - $document = _$document_; - $timeout = _$timeout_; - - grid = gridClassFactory.createGrid({}); - grid.options.columnDefs = [ - {field: 'col1', name: 'col1', displayName: 'Col1', width: 50, pinnedLeft:true }, - {field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number'}, - {field: 'col3', name: 'col3', displayName: 'Col3', width: 100}, - {field: 'col4', name: 'col4', displayName: 'Col4', width: 200, pinnedRight:true } - ]; - - _uiGridSaveStateService_.initializeGrid(grid); - - var data = []; - for (var i = 0; i < 4; i++) { - data.push({col1:'a_'+i, col2:'b_'+i, col3:'c_'+i, col4:'d_'+i}); - } - grid.options.data = data; - - $timeout(function () { - grid.addRowHeaderColumn({name: 'header'}); - }); - $timeout.flush(); - expect(grid.columns.length).toBe(5); - - - - grid.modifyRows(grid.options.data); - grid.rows[1].visible = false; - grid.getOnlyDataColumns()[2].visible = false; - grid.setVisibleRows(grid.rows); - grid.setVisibleColumns(grid.columns); - - grid.gridWidth = 500; - grid.getOnlyDataColumns()[0].drawnWidth = 50; - grid.getOnlyDataColumns()[1].drawnWidth = '*'; - grid.getOnlyDataColumns()[2].drawnWidth = 100; - grid.getOnlyDataColumns()[3].drawnWidth = 200; - })); - - - describe('defaultGridOptions', function() { - var options; - beforeEach(function() { - options = {}; - }); - - it('set all options to default', function() { - uiGridSaveStateService.defaultGridOptions(options); - expect( options ).toEqual({ - saveWidths: true, - saveOrder: true, - saveScroll: false, - saveFocus: true, - saveVisible: true, - saveSort: true, - saveFilter: true, - saveSelection: true, - saveGrouping: true, - saveGroupingExpandedStates: false, - saveTreeView: true, - savePinning: true - }); - }); - - it('set all options to non-default', function() { - var callback = function() {}; - options = { - saveWidths: false, - saveOrder: false, - saveScroll: true, - // saveFocus: false, -- leave undefined, should default based on presence of saveScroll - saveVisible: false, - saveSort: false, - saveFilter: false, - saveSelection: false, - saveGrouping: false, - saveGroupingExpandedStates: true, - saveTreeView: false, - savePinning: false - }; - uiGridSaveStateService.defaultGridOptions(options); - expect( options ).toEqual({ - saveWidths: false, - saveOrder: false, - saveScroll: true, - saveFocus: false, - saveVisible: false, - saveSort: false, - saveFilter: false, - saveSelection: false, - saveGrouping: false, - saveGroupingExpandedStates: true, - saveTreeView: false, - savePinning: false - }); - }); - }); - - - describe('saveColumns', function() { - it('save columns', function() { - expect( uiGridSaveStateService.saveColumns( grid ) ).toEqual([ - { name: 'col1', visible: true, width: 50, sort: {}, filters: [ {} ] }, - { name: 'col2', visible: true, width: '*', sort: {}, filters: [ {} ] }, - { name: 'col3', visible: false, width: 100, sort: {}, filters: [ {} ] }, - { name: 'col4', visible: true, width: 200, sort: {}, filters: [ {} ] } - ]); - }); - - it('save columns with most options turned off', function() { - grid.options.saveWidths = false; - grid.options.saveVisible = false; - grid.options.saveSort = false; - grid.options.saveFilter = false; - - expect( uiGridSaveStateService.saveColumns( grid ) ).toEqual([ - { name: 'col1' }, - { name: 'col2' }, - { name: 'col3' }, - { name: 'col4' } - ]); - }); - - describe('pinning enabled', function() { - - beforeEach(function(){ - uiGridPinningService.initializeGrid(grid); - grid.buildColumns(); - grid.getOnlyDataColumns()[2].visible = false; - grid.setVisibleColumns(grid.columns); - }); - - it('save columns', function() { - expect( uiGridSaveStateService.saveColumns( grid ) ).toEqual([ - { name: 'col1', visible: true, width: 50, sort: {}, filters: [ {} ], pinned: 'left' }, - { name: 'col2', visible: true, width: '*', sort: {}, filters: [ {} ], pinned: '' }, - { name: 'col3', visible: false, width: 100, sort: {}, filters: [ {} ], pinned: '' }, - { name: 'col4', visible: true, width: 200, sort: {}, filters: [ {} ], pinned: 'right' } - ]); - }); - - it('save columns with most options turned off', function() { - grid.options.saveWidths = false; - grid.options.saveVisible = false; - grid.options.saveSort = false; - grid.options.saveFilter = false; - grid.options.savePinning = false; - - expect( uiGridSaveStateService.saveColumns( grid ) ).toEqual([ - { name: 'col1' }, - { name: 'col2' }, - { name: 'col3' }, - { name: 'col4' } - ]); - }); - }); - }); - - describe('savePagination', function() { - beforeEach(function() { - grid.options.paginationPageSize = 25; - grid.options.paginationCurrentPage = 2; - grid.api.pagination = true; - }); - - it('saves paginationCurrentPage', function() { - expect(uiGridSaveStateService.savePagination( grid ) ).toEqual({ - paginationCurrentPage: 2, - paginationPageSize: 25 - }); - }); - - }); - - - describe('saveScrollFocus', function() { - it('does nothing when no cellNav module initialized', function() { - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( {} ); - }); - - it('save focus, no focus present, tries to save scroll instead', function() { - uiGridCellNavService.initializeGrid(grid); - - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: false } ); - }); - - describe('save focus, focus present, no row identity', function() { - beforeEach(function () { - uiGridCellNavService.initializeGrid(grid); - spyOn( grid.api.cellNav, 'getFocusedCell').and.callFake(function() { - return { row: grid.rows[2], col: grid.getOnlyDataColumns()[3] }; - }); - }); - it('', function() { - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: true, colName: 'col4', rowVal: { identity: false, row: 1 } } ); - }); - }); - - describe('save focus, focus present, no col', function() { - beforeEach(function() { - uiGridCellNavService.initializeGrid(grid); - spyOn(grid.api.cellNav, 'getFocusedCell').and.callFake(function() { - return { row: grid.rows[2], col: null }; - }); - }); - it('', function() { - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: true, rowVal: { identity: false, row: 1 } } ); - }); - }); - - describe('save focus, focus present, no row', function() { - beforeEach(function() { - uiGridCellNavService.initializeGrid(grid); - spyOn( grid.api.cellNav, 'getFocusedCell' ).and.callFake(function() { - return { row: null, col: grid.getOnlyDataColumns()[3] }; - }); - }); - it('', function() { - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: true, colName: 'col4' } ); - }); - }); - - describe('save focus, focus present, row identity present', function() { - beforeEach(function() { - uiGridCellNavService.initializeGrid(grid); - - grid.options.saveRowIdentity = function ( rowEntity ){ - return rowEntity.col1; - }; - spyOn( grid.api.cellNav, 'getFocusedCell' ).and.callFake(function() { - return { row: grid.rows[2], col: grid.getOnlyDataColumns()[3] }; - }); - }); - it('', function() { - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: true, colName: 'col4', rowVal: { identity: true, row: 'a_2' } } ); - }); - }); - - it('save scroll, no prevscroll', function() { - uiGridCellNavService.initializeGrid(grid); - grid.options.saveFocus = false; - grid.options.saveScroll = true; - - grid.renderContainers.body.grid.renderContainers.body.prevColScrollIndex = undefined; - grid.renderContainers.body.grid.renderContainers.body.prevRowScrollIndex = undefined; - - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: false } ); - }); - - it('save scroll, no row identity', function() { - uiGridCellNavService.initializeGrid(grid); - grid.options.saveFocus = false; - grid.options.saveScroll = true; - - grid.renderContainers.body.grid.renderContainers.body.prevColScrollIndex = 2; - grid.renderContainers.body.grid.renderContainers.body.prevRowScrollIndex = 2; - - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: false, colName: 'col4', rowVal: { identity: false, row: 2 } } ); - }); - - it('save scroll, row identity present', function() { - uiGridCellNavService.initializeGrid(grid); - grid.options.saveFocus = false; - grid.options.saveScroll = true; - grid.options.saveRowIdentity = function ( rowEntity ){ - return rowEntity.col1; - }; - - grid.renderContainers.body.grid.renderContainers.body.prevColScrollIndex = 2; - grid.renderContainers.body.grid.renderContainers.body.prevRowScrollIndex = 2; - - expect( uiGridSaveStateService.saveScrollFocus( grid ) ).toEqual( { focus: false, colName: 'col4', rowVal: { identity: true, row: 'a_3' } } ); - }); - }); - - - describe('saveSelection', function() { - it('does nothing when no selection module initialized', function() { - expect( uiGridSaveStateService.saveSelection( grid ) ).toEqual( [] ); - }); - - it('saves no selection, without identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - expect( uiGridSaveStateService.saveSelection( grid ) ).toEqual( [] ); - }); - - it('saves no selection, with identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - expect( uiGridSaveStateService.saveSelection( grid ) ).toEqual( [] ); - }); - - it('saves selected rows, without identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.api.selection.selectRow(grid.options.data[0]); - grid.api.selection.selectRow(grid.options.data[3]); // note that row 1 is not visible, so this will be visible row 2 - - expect( uiGridSaveStateService.saveSelection( grid ) ).toEqual( [ { identity: false, row: 0 }, { identity: false, row: 2 } ] ); - }); - - it('saves selected rows, with identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - grid.api.selection.selectRow(grid.options.data[0]); - grid.api.selection.selectRow(grid.options.data[3]); - - expect( uiGridSaveStateService.saveSelection( grid ) ).toEqual( [ { identity: true, row: 'a_0' }, { identity: true, row: 'a_3' } ] ); - }); - }); - - - describe( 'get rowVal', function() { - it( 'null gridRow', function() { - expect( uiGridSaveStateService.getRowVal( grid, null )).toEqual(null); - }); - - it( 'gridRow, not visible', function() { - expect( uiGridSaveStateService.getRowVal( grid, grid.rows[1] )).toEqual( { identity: false, row: -1 }); - }); - - it( 'gridRow, visible', function() { - expect( uiGridSaveStateService.getRowVal( grid, grid.rows[2] )).toEqual( { identity: false, row: 1 }); - }); - - }); - - - describe('restoreColumns', function() { - it('restore columns, all options turned on', function() { - grid.options.saveWidths = true; - grid.options.saveOrder = true; - grid.options.saveVisible = true; - grid.options.saveSort = true; - grid.options.saveFilter = true; - - var colVisChangeCount = 0; - var colFilterChangeCount = 0; - var colSortChangeCount = 0; - var onSortChangedHook = jasmine.createSpy('onSortChangedHook'); - - grid.api.core.on.columnVisibilityChanged( $scope, function( column ) { - colVisChangeCount++; - }); - - grid.api.core.on.filterChanged( $scope, function() { - colFilterChangeCount++; - }); - - grid.api.core.on.sortChanged( $scope, onSortChangedHook ); - - uiGridSaveStateService.restoreColumns( grid, [ - { name: 'col2', visible: false, width: 90, sort: [ {blah: 'blah'} ], filters: [ {} ] }, - { name: 'col1', visible: true, width: '*', sort: [], filters: [ {'blah': 'blah'} ] }, - { name: 'col4', visible: false, width: 120, sort: { direction: 'asc', priority: 1 }, filters: [ {} ] }, - { name: 'col3', visible: true, width: 220, sort: { direction: 'asc', priority: 0 }, filters: [ {} ] } - ]); - - expect( grid.getOnlyDataColumns()[0].name ).toEqual('col2', 'column 0 name should be col2'); - expect( grid.getOnlyDataColumns()[1].name ).toEqual('col1', 'column 1 name should be col1'); - expect( grid.getOnlyDataColumns()[2].name ).toEqual('col4', 'column 2 name should be col4'); - expect( grid.getOnlyDataColumns()[3].name ).toEqual('col3', 'column 3 name should be col3'); - - expect( grid.getOnlyDataColumns()[0].visible ).toEqual(false, 'column 0 visible should be false'); - expect( grid.getOnlyDataColumns()[1].visible ).toEqual(true, 'column 1 visible should be true'); - expect( grid.getOnlyDataColumns()[2].visible ).toEqual(false, 'column 2 visible should be false'); - expect( grid.getOnlyDataColumns()[3].visible ).toEqual(true, 'column 3 visible should be true'); - - expect( grid.getOnlyDataColumns()[0].colDef.visible ).toEqual(false, 'coldef 0 visible should be false'); - expect( grid.getOnlyDataColumns()[1].colDef.visible ).toEqual(true, 'coldef 1 visible should be true'); - expect( grid.getOnlyDataColumns()[2].colDef.visible ).toEqual(false, 'coldef 2 visible should be false'); - expect( grid.getOnlyDataColumns()[3].colDef.visible ).toEqual(true, 'coldef 3 visible should be true'); - - expect( grid.getOnlyDataColumns()[0].width ).toEqual(90); - expect( grid.getOnlyDataColumns()[1].width ).toEqual('*'); - expect( grid.getOnlyDataColumns()[2].width ).toEqual(120); - expect( grid.getOnlyDataColumns()[3].width ).toEqual(220); - - expect( grid.getOnlyDataColumns()[0].sort ).toEqual([ { blah: 'blah' } ]); - expect( grid.getOnlyDataColumns()[1].sort ).toEqual([]); - expect( grid.getOnlyDataColumns()[2].sort ).toEqual({ direction: 'asc', priority: 1 }); - expect( grid.getOnlyDataColumns()[3].sort ).toEqual({ direction: 'asc', priority: 0 }); - - expect( grid.getOnlyDataColumns()[0].filters ).toEqual([ {} ]); - expect( grid.getOnlyDataColumns()[1].filters ).toEqual([ { blah: 'blah' } ]); - expect( grid.getOnlyDataColumns()[2].filters ).toEqual([ {} ]); - expect( grid.getOnlyDataColumns()[3].filters ).toEqual([ {} ]); - - expect( colVisChangeCount ).toEqual( 4, '4 columns changed visibility'); - expect( colFilterChangeCount ).toEqual( 1, '1 columns changed filter'); - - expect( onSortChangedHook.calls.count() ).toEqual( 1 ); - - //removing this expectation because is is failing on some safari and android builds - //expect( onSortChangedHook ).toHaveBeenCalledWith( - // grid, - // [ grid.getOnlyDataColumns()[3], grid.getOnlyDataColumns()[2] ] - //); - }); - - it('restore columns, all options turned off', function() { - grid.options.saveWidths = false; - grid.options.saveOrder = false; - grid.options.saveVisible = false; - grid.options.saveSort = false; - grid.options.saveFilter = false; - - var colVisChangeCount = 0; - var colFilterChangeCount = 0; - var colSortChangeCount = 0; - - grid.api.core.on.columnVisibilityChanged( $scope, function( column ) { - colVisChangeCount++; - }); - - grid.api.core.on.filterChanged( $scope, function() { - colFilterChangeCount++; - }); - - grid.api.core.on.sortChanged( $scope, function() { - colSortChangeCount++; - }); - - uiGridSaveStateService.restoreColumns( grid, [ - { name: 'col2', visible: false, width: 90, sort: [ {blah: 'blah'} ], filters: [ {} ] }, - { name: 'col1', visible: true, width: '*', sort: [], filters: [ {'blah': 'blah'} ] }, - { name: 'col4', visible: false, width: 120, sort: [], filters: [ {} ] }, - { name: 'col3', visible: true, width: 220, sort: [], filters: [ {} ] } - ]); - - expect( grid.getOnlyDataColumns()[0].name ).toEqual('col1', 'column 0 name should be col1'); - expect( grid.getOnlyDataColumns()[1].name ).toEqual('col2', 'column 1 name should be col2'); - expect( grid.getOnlyDataColumns()[2].name ).toEqual('col3', 'column 2 name should be col3'); - expect( grid.getOnlyDataColumns()[3].name ).toEqual('col4', 'column 3 name should be col4'); - - expect( grid.getOnlyDataColumns()[0].visible ).toEqual(true, 'column 0 visible should be true'); - expect( grid.getOnlyDataColumns()[1].visible ).toEqual(true, 'column 1 visible should be true'); - expect( grid.getOnlyDataColumns()[2].visible ).toEqual(false, 'column 2 visible should be false'); - expect( grid.getOnlyDataColumns()[3].visible ).toEqual(true, 'column 3 visible should be true'); - - expect( grid.getOnlyDataColumns()[0].colDef.visible ).toEqual(undefined, 'coldef 0 visible should be undefined'); - expect( grid.getOnlyDataColumns()[1].colDef.visible ).toEqual(undefined, 'coldef 1 visible should be undefined'); - expect( grid.getOnlyDataColumns()[2].colDef.visible ).toEqual(undefined, 'coldef 2 visible should be undefined'); - expect( grid.getOnlyDataColumns()[3].colDef.visible ).toEqual(undefined, 'coldef 3 visible should be undefined'); - - expect( grid.getOnlyDataColumns()[0].width ).toEqual(50); - expect( grid.getOnlyDataColumns()[1].width ).toEqual('*'); - expect( grid.getOnlyDataColumns()[2].width ).toEqual(100); - expect( grid.getOnlyDataColumns()[3].width ).toEqual(200); - - expect( grid.getOnlyDataColumns()[0].sort ).toEqual({}); - expect( grid.getOnlyDataColumns()[1].sort ).toEqual({}); - expect( grid.getOnlyDataColumns()[2].sort ).toEqual({}); - expect( grid.getOnlyDataColumns()[3].sort ).toEqual({}); - - expect( grid.getOnlyDataColumns()[0].filters ).toEqual([ {} ]); - expect( grid.getOnlyDataColumns()[1].filters ).toEqual([ {} ]); - expect( grid.getOnlyDataColumns()[2].filters ).toEqual([ {} ]); - expect( grid.getOnlyDataColumns()[3].filters ).toEqual([ {} ]); - - expect( colVisChangeCount ).toEqual( 0, '0 columns changed visibility'); - expect( colFilterChangeCount ).toEqual( 0, '0 columns changed filter'); - expect( colSortChangeCount ).toEqual( 0, '0 columns changed sort'); - }); - }); - - describe('restorePagination', function() { - var pagination = { - paginationCurrentPage: 2, - paginationPageSize: 25 - }; - - describe('when pagination is on', function() { - beforeEach(function() { - grid.options.paginationPageSize = 1; - grid.api.pagination = true; - uiGridSaveStateService.restorePagination( grid, pagination ); - }); - - it('sets the paginationPageSize', function() { - expect(grid.options.paginationPageSize).toEqual(25); - }); - - it('sets the paginationCurrentPage', function() { - expect(grid.options.paginationCurrentPage).toEqual(2); - }); - }); - - describe('when pagination is off', function() { - beforeEach(function() { - grid.api.pagination = false; - uiGridSaveStateService.restorePagination( grid, pagination ); - }); - - it('does not modify paginationPageSize', function() { - expect(grid.options.paginationPageSize).toBeUndefined(); - }); - - it('does not modify paginationCurrentPage', function() { - expect(grid.options.paginationCurrentPage).toBeUndefined(); - }); - - - }); - }); - - - describe('restoreScrollFocus', function() { - it('does nothing when no cellNav module initialized', function() { - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: false, colName: 'col4', rowVal: { identity: true, row: 'a_2'} } ); - }); - - describe('restores', function() { - beforeEach(function() { - uiGridCellNavService.initializeGrid(grid); - spyOn( grid.api.core, 'scrollTo' ); - spyOn( grid.api.cellNav, 'scrollToFocus'); - }); - - it('no row/col, without identity function', function () { - uiGridSaveStateService.restoreScrollFocus(grid, $scope, {}); - - uiGridSaveStateService.restoreScrollFocus(grid, $scope, {}); - - expect(grid.api.core.scrollTo).not.toHaveBeenCalled(); - expect(grid.api.cellNav.scrollToFocus).not.toHaveBeenCalled(); - }); - - it('focus row only, without identity function', function() { - - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, rowVal: { identity: false, row: 2 } } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( grid.rows[3].entity, undefined ); - }); - - it('focus row only, with identity function', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, rowVal: { identity: true, row: 'a_3' } } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( grid.rows[3].entity, undefined ); - }); - - it('focus col only, without identity function', function() { - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, colName: 'col2' } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( null, grid.options.columnDefs[1] ); - }); - it('focus col only, with identity function', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, colName: 'col2' } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( null, grid.options.columnDefs[1] ); - }); - it('focus col and row, without identity function', function() { - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, colName: 'col2', rowVal: { identity: false, row: 2 } } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( grid.rows[3].entity, grid.options.columnDefs[1] ); - }); - - it('focus col and row, with identity function', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreScrollFocus( grid, $scope, { focus: true, colName: 'col2', rowVal: { identity: true, row: 'a_3' } } ); - - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( grid.rows[3].entity, grid.options.columnDefs[1] ); - }); - }); - - }); - - - describe('restoreSelection', function() { - it('does nothing when no selection module initialized', function() { - uiGridSaveStateService.restoreSelection( grid, [ { identity: false, row: 0 } ] ); - }); - - it('restores no selection, without identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - uiGridSaveStateService.restoreSelection( grid, [] ); - - expect( grid.api.selection.getSelectedGridRows.length ).toEqual( 0 ); - }); - - it('restores no selection, with identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreSelection( grid, [ ] ); - - expect( grid.api.selection.getSelectedGridRows.length ).toEqual( 0 ); - }); - - it('restores selected rows, without identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - uiGridSaveStateService.restoreSelection( grid, [ { identity: false, row: 0 }, { identity: false, row: 2 } ] ); - - expect( grid.api.selection.getSelectedGridRows().length ).toEqual( 2 ); - - // row 1 is not visible, so visible row 2 is actually grid row 3 - expect( grid.api.selection.getSelectedGridRows() ).toEqual( [ grid.rows[0], grid.rows[3] ] ); - }); - - it('restores selected rows, with identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreSelection( grid, [ { identity: true, row: 'a_0' }, {identity: true, row: 'a_3' } ] ); - - expect( grid.api.selection.getSelectedGridRows().length ).toEqual( 2 ); - - expect( grid.api.selection.getSelectedGridRows() ).toEqual( [ grid.rows[0], grid.rows[3] ] ); - }); - - it('restores invisible row, without identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - uiGridSaveStateService.restoreSelection( grid, [ { identity: false, row: -1 } ] ); - - expect( grid.api.selection.getSelectedGridRows().length ).toEqual( 0 ); - }); - - it('restores selected rows that aren\'t found, with identity function', function() { - uiGridSelectionService.initializeGrid(grid); - - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - uiGridSaveStateService.restoreSelection( grid, [ { identity: true, row: 'x_0' } ] ); - - expect( grid.api.selection.getSelectedGridRows().length ).toEqual( 0 ); - }); - }); - - describe('restoreGrouping', function() { - beforeEach( function() { - grid.api.grouping = { setGrouping: function() {}}; - spyOn( grid.api.grouping, 'setGrouping' ).and.callFake(function() {}); - }); - - it( 'calls setGrouping with config', function() { - uiGridSaveStateService.restoreGrouping( grid, { grouping: [], aggregations: [] }); - - expect(grid.api.grouping.setGrouping).toHaveBeenCalledWith( { grouping: [], aggregations: [] }); - }); - - it( 'doesn\'t call setGrouping when config missing', function() { - uiGridSaveStateService.restoreGrouping( grid, undefined); - - expect(grid.api.grouping.setGrouping).not.toHaveBeenCalled(); - }); - }); - - describe('restoreTreeView', function() { - beforeEach( function() { - grid.api.treeView = { setTreeView: function() {}}; - spyOn( grid.api.treeView, 'setTreeView' ).and.callFake(function() {}); - }); - - it( 'calls setTreeView with config', function() { - uiGridSaveStateService.restoreTreeView( grid, { test: 'test' }); - - expect(grid.api.treeView.setTreeView).toHaveBeenCalledWith( { test: 'test' }); - }); - - it( 'doesn\'t call setTreeView when config missing', function() { - uiGridSaveStateService.restoreTreeView( grid, undefined); - - expect(grid.api.treeView.setTreeView).not.toHaveBeenCalled(); - }); - }); - - - describe('findRowByIdentity', function() { - it('no row identity', function() { - expect( uiGridSaveStateService.findRowByIdentity( grid, { identity: true, row: 'a_2' } ) ).toEqual(null); - }); - - it('row found', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - expect( uiGridSaveStateService.findRowByIdentity( grid, { identity: true, row: 'a_2' } ) ).toEqual(grid.rows[2]); - }); - - it('row not found', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - expect( uiGridSaveStateService.findRowByIdentity( grid, { identity: true, row: 'a_9' } ) ).toEqual(null); - }); - }); - - describe( 'string test - save then restore', function() { - beforeEach(function() { - uiGridSelectionService.initializeGrid(grid); - uiGridCellNavService.initializeGrid(grid); - - spyOn( grid.api.cellNav, 'getFocusedCell' ).and.callFake( function() { - return { row: grid.rows[2], col: grid.getOnlyDataColumns()[3] }; - }); - - spyOn( grid.api.core, 'scrollTo' ); - spyOn( grid.api.cellNav, 'scrollToFocus' ); - }); - - it( 'some of everything', function() { - grid.options.saveRowIdentity = function( rowEntity ){ - return rowEntity.col1; - }; - - grid.api.selection.selectRow(grid.options.data[0]); - grid.api.selection.selectRow(grid.options.data[3]); - - var state = grid.api.saveState.save(); - - grid.api.selection.clearSelectedRows(); - grid.api.selection.selectRow(grid.options.data[2]); - - grid.api.saveState.restore( $scope, state ); - - expect( grid.api.selection.getSelectedGridRows() ).toEqual( [ grid.rows[0], grid.rows[3] ] ); - expect( grid.api.core.scrollTo ).not.toHaveBeenCalled(); - expect( grid.api.cellNav.scrollToFocus ).toHaveBeenCalledWith( grid.rows[2].entity, grid.options.columnDefs[3] ); - }); - }); -}); \ No newline at end of file diff --git a/src/features/selection/templates/gridFooterSelectedItems.html b/src/features/selection/templates/gridFooterSelectedItems.html deleted file mode 100644 index cba43a7553..0000000000 --- a/src/features/selection/templates/gridFooterSelectedItems.html +++ /dev/null @@ -1,4 +0,0 @@ - - ({{"search.selectedItems" | t}} {{grid.selection.selectedCount}}) - diff --git a/src/features/selection/templates/selectionHeaderCell.html b/src/features/selection/templates/selectionHeaderCell.html deleted file mode 100644 index 730154d4ef..0000000000 --- a/src/features/selection/templates/selectionHeaderCell.html +++ /dev/null @@ -1,10 +0,0 @@ -
    - -
    - - -
    -
    diff --git a/src/features/selection/templates/selectionRowHeader.html b/src/features/selection/templates/selectionRowHeader.html deleted file mode 100644 index d5ccbf04a6..0000000000 --- a/src/features/selection/templates/selectionRowHeader.html +++ /dev/null @@ -1,8 +0,0 @@ -
    -
    - - -
    -
    diff --git a/src/features/selection/templates/selectionRowHeaderButtons.html b/src/features/selection/templates/selectionRowHeaderButtons.html deleted file mode 100644 index ed1f8d5885..0000000000 --- a/src/features/selection/templates/selectionRowHeaderButtons.html +++ /dev/null @@ -1,6 +0,0 @@ -
    -   -
    diff --git a/src/features/selection/templates/selectionSelectAllButtons.html b/src/features/selection/templates/selectionSelectAllButtons.html deleted file mode 100644 index b4fab6566d..0000000000 --- a/src/features/selection/templates/selectionSelectAllButtons.html +++ /dev/null @@ -1,5 +0,0 @@ -
    -
    diff --git a/src/features/selection/test/uiGridSelectionDirective.spec.js b/src/features/selection/test/uiGridSelectionDirective.spec.js deleted file mode 100644 index db3eff1355..0000000000 --- a/src/features/selection/test/uiGridSelectionDirective.spec.js +++ /dev/null @@ -1,126 +0,0 @@ -describe('ui.grid.selection uiGridSelectionDirective', function() { - var parentScope, - elm, - scope, - gridCtrl, - $compile, - $rootScope, - $timeout, - uiGridConstants; - - /* - NOTES - - We have to flush $timeout because the header calculations are done post-$timeout, as that's when the header has been fully rendered. - - We have to actually attach the grid element to the document body, otherwise it will not have a rendered height. - */ - function compileUiGridSelectionDirective(parentScope) { - var elm = angular.element('
    '); - - document.body.appendChild(elm[0]); - $compile(elm)(parentScope); - $timeout.flush(); - parentScope.$digest(); - - return elm; - } - - beforeEach(function() { - module('ui.grid.selection'); - - inject(function(_$compile_, _$rootScope_, _$timeout_, _uiGridConstants_) { - $compile = _$compile_; - $rootScope = _$rootScope_; - $timeout = _$timeout_; - uiGridConstants = _uiGridConstants_; - }); - - parentScope = $rootScope.$new(); - parentScope.options = { - columnDefs : [{field: 'id'}], - data: [], - isRowSelectable: function(gridRow) { - return gridRow.entity.id % 2 === 0; - } - }; - - for (var i = 0; i < 10; i++) { - parentScope.options.data.push({id: i}); - } - - elm = compileUiGridSelectionDirective(parentScope); - scope = elm.scope(); - gridCtrl = elm.controller('uiGrid'); - }); - - it('should add the row header selection buttons', function() { - expect($(elm).find('.ui-grid-header .ui-grid-selection-row-header-buttons').length).toEqual(1); - }); - - it('should set the "enableSelection" field of the row using the function specified in "isRowSelectable"', function() { - for (var i = 0; i < gridCtrl.grid.rows.length; i++) { - var currentRow = gridCtrl.grid.rows[i]; - expect(currentRow.enableSelection).toEqual(currentRow.entity.id % 2 === 0); - } - }); - - it('should add cellFocus to the row header columnDef"', function() { - for (var i = 0; i < gridCtrl.grid.columns.length; i++) { - var currentCol = gridCtrl.grid.columns[i]; - if (currentCol.name === "selectionRowHeaderCol"){ - expect(currentCol.colDef.allowCellFocus).toBe(true); - } - } - }); - - describe('with filtering turned on', function () { - beforeEach(function () { - parentScope.options.enableFiltering = true; - elm = compileUiGridSelectionDirective(parentScope); - }); - - afterEach(function () { - $(elm).remove(); - }); - - it("doesn't prevent headers from shrinking when filtering gets turned off", function () { - // Header height with filtering on - var filteringHeight = $(elm).find('.ui-grid-header').height(); - - parentScope.options.enableFiltering = false; - elm.controller('uiGrid').grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); - $timeout.flush(); - parentScope.$digest(); - - var noFilteringHeight = $(elm).find('.ui-grid-header').height(); - - expect(noFilteringHeight).not.toEqual(filteringHeight); - expect(noFilteringHeight < filteringHeight).toBe(true); - }); - }); - - describe('when row header selection is turned off', function() { - beforeEach(function () { - parentScope.options.enableRowHeaderSelection = false; - elm = compileUiGridSelectionDirective(parentScope); - }); - - it('should not add the row header selection buttons', function() { - expect($(elm).find('.ui-grid-header .ui-grid-selection-row-header-buttons').length).toEqual(0); - }); - }); - - describe('when isRowSelectable is not defined', function() { - beforeEach(function () { - delete parentScope.options.isRowSelectable; - elm = compileUiGridSelectionDirective(parentScope); - gridCtrl = elm.controller('uiGrid'); - }); - - it('should not define enableSelection', function() { - for (var i = 0; i < gridCtrl.grid.rows.length; i++) { - var currentRow = gridCtrl.grid.rows[i]; - expect(currentRow.enableSelection).toBeUndefined(); - } - }); - }); -}); diff --git a/src/features/selection/test/uiGridSelectionService.spec.js b/src/features/selection/test/uiGridSelectionService.spec.js deleted file mode 100644 index 66047ab046..0000000000 --- a/src/features/selection/test/uiGridSelectionService.spec.js +++ /dev/null @@ -1,383 +0,0 @@ -describe('ui.grid.selection uiGridSelectionService', function () { - var uiGridSelectionService; - var gridClassFactory; - var grid; - var $rootScope; - var $scope; - - beforeEach(module('ui.grid.selection')); - - beforeEach(inject(function (_uiGridSelectionService_,_gridClassFactory_, $templateCache, _uiGridSelectionConstants_, - _$rootScope_) { - uiGridSelectionService = _uiGridSelectionService_; - gridClassFactory = _gridClassFactory_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - - $templateCache.put('ui-grid/uiGridCell', '
    '); - $templateCache.put('ui-grid/editableCell', '
    '); - - grid = gridClassFactory.createGrid({showGridFooter:true}); - grid.options.columnDefs = [ - {field: 'col1', enableCellEdit: true} - ]; - - _uiGridSelectionService_.initializeGrid(grid); - var data = []; - for (var i = 0; i < 10; i++) { - data.push({col1:'a_' + i}); - } - grid.options.data = data; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - })); - - - describe('toggleSelection function', function () { - it('should toggle selected with multiselect', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, true); - expect(grid.rows[0].isSelected).toBe(true); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, true); - expect(grid.rows[0].isSelected).toBe(false); - }); - - it('should toggle selected without multiselect', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, false); - expect(grid.rows[0].isSelected).toBe(true); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[1], null, false); - expect(grid.rows[0].isSelected).toBe(false); - expect(grid.rows[1].isSelected).toBe(true); - }); - - it('should not toggle selected with enableSelection: false', function () { - grid.rows[0].enableSelection = false; - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, true); - expect(grid.rows[0].isSelected).toBe(undefined); - }); - - it('should toggle selected with noUnselect', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, false, true); - expect(grid.rows[0].isSelected).toBe(true, 'row should be selected, noUnselect doesn\'t stop rows being selected'); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, false, true); - expect(grid.rows[0].isSelected).toBe(true, 'row should still be selected, noUnselect prevents unselect'); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[1], null, false, true); - expect(grid.rows[0].isSelected).toBe(false, 'row should not be selected, noUnselect doesn\'t stop other rows being selected'); - expect(grid.rows[1].isSelected).toBe(true, 'new row should be selected'); - }); - - it('should remain selected', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], null, true); - uiGridSelectionService.toggleRowSelection(grid, grid.rows[1], null, true); - expect(grid.rows[0].isSelected).toBe(true); - expect(grid.rows[1].isSelected).toBe(true); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[1], null, false); - expect(grid.rows[0].isSelected).toBe(false, 'row should not be selected, last row selection was not a multiselect selection'); - expect(grid.rows[1].isSelected).toBe(true, 'row should be selected, multiple rows was selected before the selection'); - }); - - it('should clear selected', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0]); - expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(1); - uiGridSelectionService.clearSelectedRows(grid); - expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(0); - }); - - it('should update selectedCount', function () { - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0]); - expect(grid.api.selection.getSelectedCount()).toBe(1); - uiGridSelectionService.clearSelectedRows(grid); - expect(grid.api.selection.getSelectedCount()).toBe(0); - }); - - it('should utilize public apis', function () { - grid.api.selection.toggleRowSelection(grid.rows[0].entity); - expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(1); - grid.api.selection.clearSelectedRows(); - expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(0); - }); - }); - - describe('shiftSelect function', function() { - beforeEach(function() { - grid.setVisibleRows(grid.rows); - }); - - it('should select rows in between using shift key', function () { - grid.api.selection.toggleRowSelection(grid.rows[2].entity); - uiGridSelectionService.shiftSelect(grid, grid.rows[5], null, true); - expect(grid.rows[2].isSelected).toBe(true); - expect(grid.rows[3].isSelected).toBe(true); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[5].isSelected).toBe(true); - expect(grid.selection.selectedCount).toBe(4); - }); - - it('should skip non-selectable rows', function () { - grid.rows[4].enableSelection = false; - grid.api.selection.toggleRowSelection(grid.rows[2].entity); - uiGridSelectionService.shiftSelect(grid, grid.rows[5], null, true); - expect(grid.rows[2].isSelected).toBe(true); - expect(grid.rows[3].isSelected).toBe(true); - expect(grid.rows[4].isSelected).toBe(undefined); - expect(grid.rows[5].isSelected).toBe(true); - }); - - it('should reverse selection order if from is bigger then to', function () { - grid.api.selection.toggleRowSelection(grid.rows[5].entity); - uiGridSelectionService.shiftSelect(grid, grid.rows[2], null, true); - expect(grid.rows[2].isSelected).toBe(true); - expect(grid.rows[3].isSelected).toBe(true); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[5].isSelected).toBe(true); - }); - - it('should return if multiSelect is false', function () { - uiGridSelectionService.shiftSelect(grid, grid.rows[2], null, false); - expect(uiGridSelectionService.getSelectedRows(grid).length).toBe(0); - }); - }); - - describe('selectRow and unselectRow functions', function() { - it('select then unselect rows, including selecting rows already selected and unselecting rows not selected', function () { - grid.api.selection.selectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(true); - - grid.api.selection.selectRow(grid.rows[6].entity); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[6].isSelected).toBe(true); - - grid.api.selection.selectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[6].isSelected).toBe(true); - - grid.api.selection.unSelectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(false); - expect(grid.rows[6].isSelected).toBe(true); - - grid.api.selection.unSelectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(false); - expect(grid.rows[6].isSelected).toBe(true); - - grid.api.selection.unSelectRow(grid.rows[6].entity); - expect(grid.rows[4].isSelected).toBe(false); - expect(grid.rows[6].isSelected).toBe(false); - - grid.rows[4].enableSelection = false; - grid.api.selection.selectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(false); - }); - }); - - describe('setSelected function', function() { - it('select row and check the selected count is correct', function() { - - expect(grid.selection.selectedCount).toBe(0); - - grid.rows[0].setSelected(true); - expect(grid.rows[0].isSelected).toBe(true); - expect(grid.selection.selectedCount).toBe(1); - - // the second setSelected(true) should have no effect - grid.rows[0].setSelected(true); - expect(grid.rows[0].isSelected).toBe(true); - expect(grid.selection.selectedCount).toBe(1); - - grid.rows[0].setSelected(false); - expect(grid.rows[0].isSelected).toBe(false); - expect(grid.selection.selectedCount).toBe(0); - }); - }); - - describe('selectAllRows and clearSelectedRows functions', function() { - it('should select all rows, and select all rows when already all selected, then unselect again', function () { - grid.api.selection.selectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.selection.selectAll).toBe(false); - - grid.api.selection.selectRow(grid.rows[6].entity); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[6].isSelected).toBe(true); - expect(grid.selection.selectAll).toBe(false); - - grid.api.selection.selectAllRows(); - for (var i = 0; i < 10; i++) { - expect(grid.rows[i].isSelected).toBe(true); - } - expect(grid.selection.selectAll).toBe(true); - - grid.api.selection.selectAllRows(); - for (i = 0; i < 10; i++) { - expect(grid.rows[i].isSelected).toBe(true); - } - expect(grid.selection.selectAll).toBe(true); - - grid.api.selection.clearSelectedRows(); - for (i = 0; i < 10; i++) { - expect(grid.rows[i].isSelected).toBe(false); - } - expect(grid.selection.selectAll).toBe(false); - - grid.rows[8].enableSelection = false; - grid.api.selection.selectAllRows(); - expect(grid.rows[7].isSelected).toBe(true); - expect(grid.rows[8].isSelected).toBe(false); - }); - }); - - describe('toggle selected clears selectAll', function() { - it('should select all rows, toggle selection for one row removes selectAll', function () { - grid.api.selection.selectAllRows(); - for (var i = 0; i < 10; i++) { - expect(grid.rows[i].isSelected).toBe(true); - } - expect(grid.selection.selectAll).toBe(true); - - uiGridSelectionService.toggleRowSelection(grid, grid.rows[0], false); - expect(grid.selection.selectAll).toBe(false); - }); - }); - - describe('selectAllVisibleRows function', function() { - it('should select all visible rows', function () { - grid.api.selection.selectRow(grid.rows[4].entity); - expect(grid.rows[4].isSelected).toBe(true); - - grid.api.selection.selectRow(grid.rows[6].entity); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[6].isSelected).toBe(true); - - grid.rows[3].visible = true; - grid.rows[4].visible = true; - grid.rows[6].visible = false; - grid.rows[7].visible = true; - grid.rows[8].enableSelection = false; - grid.rows[9].visible = true; - expect(grid.selection.selectAll).toBe(false); - - grid.api.selection.selectAllVisibleRows(); - expect(grid.rows[3].isSelected).toBe(true); - expect(grid.rows[4].isSelected).toBe(true); - expect(grid.rows[6].isSelected).toBe(false); - expect(grid.rows[7].isSelected).toBe(true); - expect(grid.rows[8].isSelected).toBe(undefined); - expect(grid.rows[9].isSelected).toBe(true); - expect(grid.selection.selectAll).toBe(true); - expect(grid.selection.selectedCount).toBe(8); - }); - }); - - describe('selectRowByVisibleIndex function', function() { - it('should select specified row', function () { - grid.rows[1].visible = false; - grid.setVisibleRows(grid.rows); - - grid.api.selection.selectRowByVisibleIndex(0); - expect(grid.rows[0].isSelected).toBe(true); - - grid.api.selection.selectRowByVisibleIndex(1); - expect(grid.rows[2].isSelected).toBe(true); - - grid.rows[3].enableSelection = false; - grid.api.selection.selectRowByVisibleIndex(2); - expect(grid.rows[3].isSelected).toBe(undefined); - }); - }); - - describe('selectionChanged events', function(){ - var selectionFunctions = {}; - var singleCalls; - var batchCalls; - beforeEach( function() { - // can't use spy as the callback hits the function directly - singleCalls = []; - batchCalls = []; - - // row 5 isn't visible - // row 6 is already selected - // row 7 isn't visible and is already selected - grid.rows[5].visible = false; - grid.rows[7].visible = false; - grid.api.selection.toggleRowSelection( grid.rows[6].entity ); - grid.api.selection.toggleRowSelection( grid.rows[7].entity ); - selectionFunctions.single = function( row, evt ){ singleCalls.push({row: row, evt: evt}); }; - selectionFunctions.batch = function( rows, evt ) { batchCalls.push({rows: rows, evt: evt});}; - grid.api.selection.on.rowSelectionChanged( $scope, selectionFunctions.single ); - grid.api.selection.on.rowSelectionChangedBatch( $scope, selectionFunctions.batch ); - }); - - it('select all rows, batch', function() { - grid.api.selection.selectAllRows(); - expect( singleCalls.length ).toEqual( 0 ); - expect( batchCalls.length ).toEqual( 1 ); - expect( batchCalls[0].rows.length ).toEqual( 8, "2 rows already selected" ); - }); - - it('select all rows, not batch', function() { - grid.options.enableSelectionBatchEvent = false; - grid.api.selection.selectAllRows(); - expect( singleCalls.length ).toEqual( 8, "2 rows already selected" ); - expect( batchCalls.length ).toEqual( 0 ); - }); - - it('select all visible rows, batch', function() { - grid.api.selection.selectAllVisibleRows(); - expect( singleCalls.length ).toEqual( 0 ); - expect( batchCalls.length ).toEqual( 1 ); - expect( batchCalls[0].rows.length ).toEqual( 8, "8 visible rows, one already selected, one invisible row deselected" ); - }); - - it('select all visible rows, not batch', function() { - grid.options.enableSelectionBatchEvent = false; - grid.api.selection.selectAllVisibleRows(); - expect( singleCalls.length ).toEqual( 8, "8 visible rows, one already selected, one invisible row deselected" ); - expect( batchCalls.length ).toEqual( 0 ); - }); - - // not testing toggle - simple - // not testing shift select - too messy and same logic as others - - it('clear selected rows, batch', function() { - grid.api.selection.clearSelectedRows(); - expect( singleCalls.length ).toEqual( 0 ); - expect( batchCalls.length ).toEqual( 1 ); - expect( batchCalls[0].rows.length ).toEqual( 2, "2 selected rows" ); - }); - - it('clear selected rows, not batch', function() { - grid.options.enableSelectionBatchEvent = false; - grid.api.selection.clearSelectedRows(); - expect( singleCalls.length ).toEqual( 2, "2 selected rows" ); - expect( batchCalls.length ).toEqual( 0 ); - }); - - it('should pass event object, batch', function () { - var mockEvent = {currentTarget: 'test clearSelectedRows'}; - grid.setVisibleRows(grid.rows); - grid.api.selection.clearSelectedRows(mockEvent); - expect( batchCalls.length ).toEqual( 1 ); - expect( batchCalls[0].evt.currentTarget ).toEqual( 'test clearSelectedRows' ); - mockEvent = {currentTarget: 'test shiftSelect'}; - uiGridSelectionService.shiftSelect(grid, grid.rows[3], mockEvent, true); - expect( batchCalls.length ).toEqual( 2 ); - expect( batchCalls[1].evt.currentTarget ).toEqual( 'test shiftSelect' ); - mockEvent = {currentTarget: 'test selectAllRows'}; - grid.api.selection.selectAllRows(mockEvent); - expect( batchCalls.length ).toEqual( 3 ); - expect( batchCalls[2].evt.currentTarget ).toEqual( 'test selectAllRows' ); - }); - - it('should pass event object, not batch', function () { - grid.options.enableSelectionBatchEvent = false; - var mockEvent = {currentTarget: 'test'}; - grid.api.selection.selectRow(grid.rows[4].entity, mockEvent); - expect( singleCalls.length ).toEqual( 1 ); - expect( singleCalls[0].evt.currentTarget ).toEqual( 'test' ); - }); - }); -}); diff --git a/src/features/tree-base/templates/treeBaseExpandAllButtons.html b/src/features/tree-base/templates/treeBaseExpandAllButtons.html deleted file mode 100644 index b43348beb6..0000000000 --- a/src/features/tree-base/templates/treeBaseExpandAllButtons.html +++ /dev/null @@ -1,5 +0,0 @@ -
    -
    diff --git a/src/features/tree-base/templates/treeBaseHeaderCell.html b/src/features/tree-base/templates/treeBaseHeaderCell.html deleted file mode 100644 index 329899d0b2..0000000000 --- a/src/features/tree-base/templates/treeBaseHeaderCell.html +++ /dev/null @@ -1,9 +0,0 @@ -
    -
    - - -
    -
    diff --git a/src/features/tree-base/templates/treeBaseRowHeader.html b/src/features/tree-base/templates/treeBaseRowHeader.html deleted file mode 100644 index 6fda8bd760..0000000000 --- a/src/features/tree-base/templates/treeBaseRowHeader.html +++ /dev/null @@ -1,5 +0,0 @@ -
    - - -
    diff --git a/src/features/tree-base/templates/treeBaseRowHeaderButtons.html b/src/features/tree-base/templates/treeBaseRowHeaderButtons.html deleted file mode 100644 index 0185a60953..0000000000 --- a/src/features/tree-base/templates/treeBaseRowHeaderButtons.html +++ /dev/null @@ -1,10 +0,0 @@ -
    - - -   -
    diff --git a/src/features/tree-base/test/tree-base.spec.js b/src/features/tree-base/test/tree-base.spec.js deleted file mode 100644 index f6e27696ab..0000000000 --- a/src/features/tree-base/test/tree-base.spec.js +++ /dev/null @@ -1,821 +0,0 @@ -describe('ui.grid.treeBase uiGridTreeBaseService', function () { - var uiGridTreeBaseService, - uiGridTreeBaseConstants, - gridClassFactory, - grid, - $rootScope, - $scope, - GridRow, - gridUtil, - uiGridConstants; - - beforeEach(function() { - module('ui.grid.treeBase'); - - inject(function (_uiGridTreeBaseService_,_gridClassFactory_, $templateCache, _uiGridTreeBaseConstants_, - _$rootScope_, _GridRow_, _gridUtil_, _uiGridConstants_) { - uiGridTreeBaseService = _uiGridTreeBaseService_; - uiGridTreeBaseConstants = _uiGridTreeBaseConstants_; - gridClassFactory = _gridClassFactory_; - $rootScope = _$rootScope_; - GridRow = _GridRow_; - gridUtil = _gridUtil_; - uiGridConstants = _uiGridConstants_; - }); - $scope = $rootScope.$new(); - - grid = gridClassFactory.createGrid({}); - grid.options.columnDefs = [ - {field: 'col0'}, - {field: 'col1'}, - {field: 'col2'}, - {field: 'col3'} - ]; - - spyOn(grid, 'addRowHeaderColumn').and.callThrough(); - uiGridTreeBaseService.initializeGrid(grid, $scope); - $scope.$apply(); - - var data = []; - for (var i = 0; i < 10; i++) { - data.push({col0: 'a_' + Math.floor(i/4), col1: Math.floor(i/2), col2: 'c_' + i, col3: i}); - } - data[0].$$treeLevel = 0; - data[1].$$treeLevel = 1; - data[3].$$treeLevel = 1; - data[4].$$treeLevel = 2; - data[7].$$treeLevel = 0; - data[9].$$treeLevel = 1; - - grid.options.data = data; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - }); - - - describe( 'initializeGrid and defaultGridOptions', function() { - it( 'initializeGrid defaults things and creates rowsProcessor as expected', function() { - var previousRowsProcessors = grid.rowsProcessors.length; - uiGridTreeBaseService.initializeGrid( grid, $scope ); - - expect( grid.treeBase ).toEqual( { numberLevels : 0, expandAll : false, tree : [] }, 'grid.treeBase should be defaulted' ); - expect( grid.api.treeBase.expandAllRows ).toEqual( jasmine.any(Function), 'expandAllRows should be defined as an example function' ); - expect( grid.api.treeBase.on.rowExpanded ).toEqual( jasmine.any(Function), 'rowExpanded should be defined as an example event' ); - - expect( grid.rowsProcessors.length ).toEqual( previousRowsProcessors + 1 ); - }); - - it( 'defaultGridOptions defaults things as expected', function() { - var options = {}; - uiGridTreeBaseService.defaultGridOptions( options ); - - expect( options ).toEqual( { - treeRowHeaderBaseWidth: 30, - treeIndent: 10, - showTreeRowHeader: true, - showTreeExpandNoChildren: true, - treeRowHeaderAlwaysVisible: true, - treeCustomAggregations: {}, - enableExpandAll: true - }); - }); - it('should call addRowHeaderColumn', function() { - expect(grid.addRowHeaderColumn).toHaveBeenCalledWith(jasmine.any(Object), -100); - }); - }); - - - describe( 'tree expand/collapse and event handling', function() { - var expandCount, collapseCount, treeRows; - beforeEach(function() { - expandCount = 0; - collapseCount = 0; - - grid.api.treeBase.on.rowExpanded( $scope, function(row){ - expandCount++; - }); - - grid.api.treeBase.on.rowCollapsed( $scope, function(row){ - collapseCount++; - }); - - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - - grid.rows.forEach(function( row ){ - row.visible = true; - }); - }); - - it( 'expandAll', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandAllRows(); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 10, 'all rows are visible' ); - expect( expandCount ).toEqual(10); - }); - - it( 'expandRow', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandRow(grid.rows[0]); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 4, 'children of row 0 are also visible' ); - expect( expandCount ).toEqual(1); - }); - - it( 'expandRowChildren', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandRowChildren(grid.rows[0]); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 8, 'all children of row 0 are also visible' ); - expect( expandCount ).toEqual(7, 'called for row 0, 1, 2, 3, 4, 5 and 6'); - }); - - it( 'collapseRow', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandAllRows(); - grid.api.treeBase.collapseRow(grid.rows[7]); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 8, 'children of row 7 are hidden' ); - expect( collapseCount ).toEqual( 1 ); - }); - - it( 'collapseRowChildren', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandAllRows(); - grid.api.treeBase.collapseRowChildren(grid.rows[0]); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 4, 'children of row 0 are hidden' ); - expect( collapseCount ).toEqual( 7, 'called for row 0, 1, 2, 3, 4, 5, and 6' ); - }); - - it( 'collapseAllRows', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - grid.api.treeBase.expandAllRows(); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 10, 'all rows visible' ); - - grid.api.treeBase.collapseAllRows(); - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 2, 'only level 0 is visible' ); - expect( collapseCount ).toEqual( 10 ); - }); - - it( 'getRowChildren', function() { - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - - treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( grid.api.treeBase.getRowChildren( grid.rows[7] ).length ).toEqual(2); - }); - }); - - - describe( 'treeRows', function() { - it( 'tree the rows', function() { - var treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - expect( treeRows.length ).toEqual( 2, 'only the level 0 rows are visible' ); - expect( grid.treeBase.numberLevels).toEqual(3, 'three levels in the tree'); - }); - }); - - - describe( 'renderTree', function() { - it( 'renders a tree of no nodes', function() { - grid.treeBase.tree = []; - - var rows = uiGridTreeBaseService.renderTree( grid.treeBase.tree ); - expect( rows ).toEqual([]); - }); - - it( 'renders a tree of one node', function() { - grid.treeBase.tree = [ - { row: { name: 'testRow', visible: true }, state: 'collapsed', children: [] } - ]; - - var rows = uiGridTreeBaseService.renderTree( grid.treeBase.tree ); - expect( rows ).toEqual([ - { name: 'testRow', visible: true } - ]); - }); - - it( 'renders a nested tree with collapsed and expanded nodes, and some invisible nodes', function() { - grid.treeBase.tree = [ - { row: { name: 'testRow1', visible: true }, state: 'collapsed', children: [ - { row: { name: 'testRow1-1', visible: true }, state: 'collapsed', children: [] }, - { row: { name: 'testRow1-2', visible: false }, state: 'collapsed', children: [] } - ]}, - { row: { name: 'testRow2', visible: true }, state: 'expanded', children: [ - { row: { name: 'testRow2-1', visible: true }, state: 'collapsed', children: [] }, - { row: { name: 'testRow2-2', visible: false }, state: 'collapsed', children: [] } - ]}, - { row: { name: 'testRow2', visible: false }, state: 'expanded', children: [ - { row: { name: 'testRow3-1', visible: true }, state: 'collapsed', children: [] }, - { row: { name: 'testRow3-2', visible: false }, state: 'collapsed', children: [] } - ]} - ]; - - var rows = uiGridTreeBaseService.renderTree( grid.treeBase.tree ); - expect( rows ).toEqual([ - { name: 'testRow1', visible: true }, - { name: 'testRow2', visible: true }, - { name: 'testRow2-1', visible: true }, - { name: 'testRow3-1', visible: true } - ]); - }); - }); - - - describe( 'createTree', function() { - it( 'create tree with no nodes', function() { - var rows = [ - ]; - var tree = uiGridTreeBaseService.createTree( grid, rows ); - - expect( tree ).toEqual( [], 'empty tree' ); - expect( grid.treeBase.numberLevels).toEqual(0, 'zero levels in the tree'); - expect( grid.treeBase.tree).toEqual( [], 'empty tree'); - }); - - it( 'create tree with one row', function() { - var rows = [ - { uid: 1, entity: { $$treeLevel: 0 }, visible: true } - ]; - var tree = uiGridTreeBaseService.createTree( grid, rows ); - - expect( rows.length ).toEqual( 1, 'still only 1 row' ); - expect( rows[0].treeNode ).toEqual( grid.treeBase.tree[0], 'treeNode is the first node in the tree' ); - delete rows[0].treeNode; - expect( rows[0] ).toEqual( { uid: 1, treeLevel: 0, entity: { $$treeLevel: 0 }, visible: true }, 'treeLevel copied down' ); - expect( grid.treeBase.numberLevels).toEqual(1, 'one level in the tree'); - expect( grid.treeBase.tree.length).toEqual( 1, 'one node at root level of tree'); - expect( grid.treeBase.tree[0].row).toEqual( rows[0], 'node is for row 0'); - delete grid.treeBase.tree[0].row; - expect( grid.treeBase.tree[0]).toEqual({ state : 'collapsed', parentRow : null, aggregations : [], children : [ ] }); - }); - - it( 'create tree with five rows', function() { - var rows = [ - { uid: 1, entity: { $$treeLevel: 0 } }, - { uid: 2, entity: { $$treeLevel: 1 } }, - { uid: 3, entity: { $$treeLevel: 0 } }, - { uid: 4, entity: { $$treeLevel: 1 } }, - { uid: 5, entity: { $$treeLevel: 1 } } - ]; - - var tree = uiGridTreeBaseService.createTree( grid, rows ); - - // overall settings - expect( grid.treeBase.numberLevels).toEqual(2, 'two levels in the tree'); - - // rows - expect( rows.length ).toEqual( 5, 'still only 5 rows' ); - - // row 0 - expect( rows[0].treeNode ).toEqual( grid.treeBase.tree[0], 'row 0 treeNode is the first node in the tree' ); - delete rows[0].treeNode; - expect( rows[0] ).toEqual( { uid: 1, treeLevel: 0, entity: { $$treeLevel: 0 } }, 'row 0 treeLevel copied down' ); - - // row 1 - expect( rows[1].treeNode ).toEqual( grid.treeBase.tree[0].children[0], 'row 1 treeNode is the first child of first node in the tree' ); - delete rows[1].treeNode; - expect( rows[1] ).toEqual( { uid: 2, treeLevel: 1, entity: { $$treeLevel: 1 } }, 'row 1 treeLevel copied down' ); - - // row 2 - expect( rows[2].treeNode ).toEqual( grid.treeBase.tree[1], 'row 2 treeNode is the second node in the tree' ); - delete rows[2].treeNode; - expect( rows[2] ).toEqual( { uid: 3, treeLevel: 0, entity: { $$treeLevel: 0 } }, 'row 2 treeLevel copied down' ); - - // row 3 - expect( rows[3].treeNode ).toEqual( grid.treeBase.tree[1].children[0], 'row 3 treeNode is the first child of second node in the tree' ); - delete rows[3].treeNode; - expect( rows[3] ).toEqual( { uid: 4, treeLevel: 1, entity: { $$treeLevel: 1 } }, 'row 3 treeLevel copied down' ); - - // row 4 - expect( rows[4].treeNode ).toEqual( grid.treeBase.tree[1].children[1], 'row 4 treeNode is the second child of the second node in the tree' ); - delete rows[4].treeNode; - expect( rows[4] ).toEqual( { uid: 5, treeLevel: 1, entity: { $$treeLevel: 1 } }, 'row 4 treeLevel copied down' ); - - // tree checking - expect( grid.treeBase.tree.length).toEqual( 2, 'two nodes at root level of tree'); - - // first parent - expect( grid.treeBase.tree[0].row).toEqual( rows[0], 'first parent node is for row 0'); - delete grid.treeBase.tree[0].row; - - // second parent - expect( grid.treeBase.tree[1].row).toEqual( rows[2], 'second parent node is for row 2'); - delete grid.treeBase.tree[1].row; - - // first child of first parent - expect( grid.treeBase.tree[0].children[0].row).toEqual( rows[1], 'first child of first parent node is for row 1'); - delete grid.treeBase.tree[0].children[0].row; - expect( grid.treeBase.tree[0].children[0].parentRow).toEqual( rows[0], 'parent of first child of first parent points up the tree to row 0'); - delete grid.treeBase.tree[0].children[0].parentRow; - - // first child of second parent - expect( grid.treeBase.tree[1].children[0].row).toEqual( rows[3], 'first child of second parent node is for row 3'); - delete grid.treeBase.tree[1].children[0].row; - expect( grid.treeBase.tree[1].children[0].parentRow).toEqual( rows[2], 'parent of first child of second parent points up the tree to row 2'); - delete grid.treeBase.tree[1].children[0].parentRow; - - // second child of second parent - expect( grid.treeBase.tree[1].children[1].row).toEqual( rows[4], 'second child of second parent node is for row 4'); - delete grid.treeBase.tree[1].children[1].row; - expect( grid.treeBase.tree[1].children[1].parentRow).toEqual( rows[2], 'parent of second child of second parent points up the tree to row 2'); - delete grid.treeBase.tree[1].children[1].parentRow; - - expect( grid.treeBase.tree ).toEqual([ - { state : 'collapsed', parentRow : null, aggregations : [], children : [ - { state : 'collapsed', aggregations : [], children : [] } - ]}, - { state : 'collapsed', parentRow : null, aggregations : [], children : [ - { state : 'collapsed', aggregations : [], children : [] }, - { state : 'collapsed', aggregations : [], children : [] } - ]} - ]); - }); - - - describe( 'create tree with ten rows including leaf nodes and aggregations', function() { - var rows; - beforeEach(function () { - rows = [ - { uid: 1, entity: { $$treeLevel: 0, col3: 5 }, visible: true }, - { uid: 2, entity: { $$treeLevel: 1, col3: 7 }, visible: true }, - { uid: '2-1', entity: { col3: 11 }, visible: true }, - { uid: 3, entity: { $$treeLevel: 0, col3: null }, visible: true }, - { uid: '3-1', entity: { col3: 2 }, visible: true }, - { uid: 4, entity: { $$treeLevel: 1, col3: 20 }, visible: true }, - { uid: '4-1', entity: { col3: 9 }, visible: true }, - { uid: '4-2', entity: { col3: 11 }, visible: true }, - { uid: 5, entity: { $$treeLevel: 1, col3: 'test' }, visible: true }, - { uid: '5-1', entity: { col3: 21 }, visible: true } - ]; - spyOn( grid, 'getCellValue').and.callFake( function( row, col ) { return row.entity.col3; } ); - }); - - it('', function() { - grid.columns[3].treeAggregationType = 'sum'; - grid.columns[3].uid = 'col3'; - - var tree = uiGridTreeBaseService.createTree( grid, rows ); - - // overall settings - expect( grid.treeBase.numberLevels).toEqual(2, 'two levels in the tree'); - - // rows - expect( rows.length ).toEqual( 10, 'still only 10 rows' ); - - // some more checking of aggregations would be nice, but they've been unit tested at the function level - }); - }); - }); - - - - describe( 'addOrUseNode', function() { - it( 'root row that has no old reference to a node, default state should be collapsed', function() { - var fakeRow = { - treeLevel: 0 - }; - - grid.treeBase.tree = []; - - var parents = []; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree ).toEqual( [ { - state: 'collapsed', - row: fakeRow, - parentRow: null, - aggregations: [], - children: [] - }], 'tree should now have this row at the root level'); - - expect( fakeRow ).toEqual( { - treeNode: grid.treeBase.tree[0], - treeLevel: 0 - }, 'this row should have a reference to the node in the tree' ); - }); - - - it( 'root row that has an old reference to a node, uses state from that node', function() { - var fakeRow = { - treeNode: { state: 'expanded' }, - treeLevel: 0 - }; - - grid.treeBase.tree = []; - - var parents = []; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree ).toEqual([{ - state: 'expanded', - row: fakeRow, - parentRow: null, - aggregations: [], - children: [] - }], 'tree should now have this row in the children'); - - expect( fakeRow ).toEqual( { - treeNode: grid.treeBase.tree[0], - treeLevel: 0 - }, 'this row should have a reference to the node in the tree' ); - }); - - - it( 'child row that has no old reference to a node, default state should be collapsed', function() { - var fakeRootRow = { - treeLevel: 0 - }; - - var fakeRow = { - treeLevel: 1 - }; - - grid.treeBase.tree = [{ - state: 'expanded', - row: fakeRootRow, - parentRow: null, - aggregations: [], - children: [] - }]; - - fakeRootRow.treeNode = grid.treeBase.tree[0]; - - var parents = [ fakeRootRow ]; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree[0].children[0] ).toEqual( { - state: 'collapsed', - row: fakeRow, - parentRow: fakeRootRow, - aggregations: [], - children: [] - }, 'tree should now have this row in the children of the fakeRootRow'); - - expect( fakeRow ).toEqual( { - treeNode: fakeRootRow.treeNode.children[0], - treeLevel: 1 - }, 'this row should have a reference to the node in the tree' ); - }); - - - it( 'child row that has an old reference to a node, default state should be collapsed', function() { - var fakeRootRow = { - treeLevel: 0 - }; - - var fakeRow = { - treeNode: { state: 'expanded' }, - treeLevel: 1 - }; - - grid.treeBase.tree = [{ - state: 'expanded', - row: fakeRootRow, - parentRow: null, - aggregations: [], - children: [] - }]; - - fakeRootRow.treeNode = grid.treeBase.tree[0]; - - var parents = [ fakeRootRow ]; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree[0].children[0] ).toEqual( { - state: 'expanded', - row: fakeRow, - parentRow: fakeRootRow, - aggregations: [], - children: [] - }, 'tree should now have this row in the children of the fakeRootRow'); - - expect( fakeRow ).toEqual( { - treeNode: fakeRootRow.treeNode.children[0], - treeLevel: 1 - }, 'this row should have a reference to the node in the tree' ); - }); - - - it( 'leaf row at the root level', function() { - var fakeRow = { - }; - - grid.treeBase.tree = []; - - var parents = []; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree[0] ).toEqual( { - state: 'collapsed', - row: fakeRow, - parentRow: null, - aggregations: [], - children: [] - }, 'tree should now have this row in the children of the fakeRootRow'); - - expect( fakeRow ).toEqual( { - treeNode: grid.treeBase.tree[0] - }, 'this row should have a reference to the node in the tree' ); - }); - - - it( 'leaf row at the child level', function() { - var fakeRootRow = { - treeLevel: 0 - }; - - var fakeRow = { - }; - - grid.treeBase.tree = [{ - state: 'expanded', - row: fakeRootRow, - parentRow: null, - children: [] - }]; - - fakeRootRow.treeNode = grid.treeBase.tree[0]; - - var parents = [ fakeRootRow ]; - var aggregations = []; - - uiGridTreeBaseService.addOrUseNode( grid, fakeRow, parents, aggregations ); - - expect( grid.treeBase.tree[0].children[0] ).toEqual( { - state: 'collapsed', - row: fakeRow, - parentRow: fakeRootRow, - aggregations: [], - children: [] - }, 'tree should now have this row in the children of the fakeRootRow'); - - expect( fakeRow ).toEqual( { - treeNode: fakeRootRow.treeNode.children[0] - }, 'this row should have a reference to the node in the tree' ); - }); - }); - - - describe( 'sortTree', function() { - it( 'sort empty tree', function() { - grid.treeBase.tree = []; - uiGridTreeBaseService.sortTree( grid ); - expect( grid.treeBase.tree ).toEqual( [] ); - }); - - it( 'sort single level tree, no sort criteria, one row', function() { - grid.treeBase.tree = [ - { state: 'collapsed', row: { uid: 1, entity: { field1: 1 } }, children: [] } - ]; - grid.treeBase.tree[0].row.treeNode = grid.treeBase.tree[0]; - - uiGridTreeBaseService.sortTree( grid ); - - delete grid.treeBase.tree[0].row.treeNode; - expect( grid.treeBase.tree ).toEqual([ - { state: 'collapsed', row: { uid: 1, entity: { field1: 1 } }, children: [] } - ]); - }); - - it( 'sort our tree', function() { - grid.columns[1].sort = { direction: uiGridConstants.ASC }; - grid.columns[2].sort = { direction: uiGridConstants.DESC }; - grid.columns[1].type = 'string'; - grid.columns[2].type = 'number'; - - var treeRows = uiGridTreeBaseService.treeRows.call( grid, grid.rows.slice(0) ); - - expect( grid.treeBase.tree.length ).toEqual(2); - expect( grid.treeBase.tree[0].children.length ).toEqual(2); - expect( grid.treeBase.tree[1].children.length ).toEqual(2); - }); - }); - - - describe( 'fixFilter', function() { - it( 'fix empty tree', function() { - grid.treeBase.tree = []; - uiGridTreeBaseService.fixFilter( grid ); - expect( grid.treeBase.tree ).toEqual( [] ); - }); - - it( 'fix tree with mix of visible and invisible rows, collapsed and not collapsed', function() { - grid.treeBase.tree = [ - { row: { uid: '1', visible: true }, state: 'expanded', children: [ - { row: { uid: '1-1', visible: false }, state: 'expanded', children: [ - { row: { uid: '1-1-1', visible: false }, state: 'expanded', children: []}, - { row: { uid: '1-1-2', visible: true }, state: 'expanded', children: []} - ]}, - { row: { uid: '1-2', visible: false }, state: 'collapsed', children: [ - { row: { uid: '1-2-1', visible: false }, state: 'expanded', children: []}, - { row: { uid: '1-2-2', visible: true }, state: 'expanded', children: []} - ]}, - { row: { uid: '1-3', visible: false }, state: 'collapsed', children: [ - { row: { uid: '1-3-1', visible: false }, state: 'expanded', children: []}, - { row: { uid: '1-3-2', visible: false }, state: 'expanded', children: []} - ]} - ]}, - { row: { uid: '2', visible: false }, state: 'collapsed', children: [ - { row: { uid: '2-1', visible: true }, state: 'expanded', children: [ - ]} - ]}, - { row: { uid: '3', visible: false }, state: 'expanded', children: [ - { row: { uid: '3-1', visible: true }, state: 'collapsed', children: [ - ]} - ]}, - { row: { uid: '4', visible: false }, state: 'expanded', children: [ - { row: { uid: '4-1', visible: false }, state: 'collapsed', children: [ - ]} - ]} - ]; - - // setup the treeNode references - grid.treeBase.tree[0].row.treeNode = grid.treeBase.tree[0]; - grid.treeBase.tree[1].row.treeNode = grid.treeBase.tree[1]; - grid.treeBase.tree[2].row.treeNode = grid.treeBase.tree[2]; - grid.treeBase.tree[3].row.treeNode = grid.treeBase.tree[3]; - - grid.treeBase.tree[0].children[0].row.treeNode = grid.treeBase.tree[0].children[0]; - grid.treeBase.tree[0].children[1].row.treeNode = grid.treeBase.tree[0].children[1]; - grid.treeBase.tree[0].children[2].row.treeNode = grid.treeBase.tree[0].children[2]; - grid.treeBase.tree[1].children[0].row.treeNode = grid.treeBase.tree[1].children[0]; - grid.treeBase.tree[2].children[0].row.treeNode = grid.treeBase.tree[2].children[0]; - - grid.treeBase.tree[0].children[0].children[0].row.treeNode = grid.treeBase.tree[0].children[0].children[0]; - grid.treeBase.tree[0].children[0].children[1].row.treeNode = grid.treeBase.tree[0].children[0].children[1]; - grid.treeBase.tree[0].children[1].children[0].row.treeNode = grid.treeBase.tree[0].children[1].children[0]; - grid.treeBase.tree[0].children[1].children[1].row.treeNode = grid.treeBase.tree[0].children[1].children[1]; - grid.treeBase.tree[0].children[2].children[0].row.treeNode = grid.treeBase.tree[0].children[2].children[0]; - grid.treeBase.tree[0].children[2].children[1].row.treeNode = grid.treeBase.tree[0].children[2].children[1]; - - // setup the parentRow references - grid.treeBase.tree[0].children[0].parentRow = grid.treeBase.tree[0].row; - grid.treeBase.tree[0].children[1].parentRow = grid.treeBase.tree[0].row; - grid.treeBase.tree[1].children[0].parentRow = grid.treeBase.tree[1].row; - grid.treeBase.tree[2].children[0].parentRow = grid.treeBase.tree[2].row; - grid.treeBase.tree[3].children[0].parentRow = grid.treeBase.tree[3].row; - - grid.treeBase.tree[0].children[0].children[0].parentRow = grid.treeBase.tree[0].children[0].row; - grid.treeBase.tree[0].children[0].children[1].parentRow = grid.treeBase.tree[0].children[0].row; - grid.treeBase.tree[0].children[1].children[0].parentRow = grid.treeBase.tree[0].children[1].row; - grid.treeBase.tree[0].children[1].children[1].parentRow = grid.treeBase.tree[0].children[1].row; - grid.treeBase.tree[0].children[2].children[0].parentRow = grid.treeBase.tree[0].children[2].row; - grid.treeBase.tree[0].children[2].children[1].parentRow = grid.treeBase.tree[0].children[2].row; - - uiGridTreeBaseService.fixFilter( grid ); - - expect( grid.treeBase.tree[1].row.visible ).toEqual( true, 'tree[1] should have changed to visible' ); - expect( grid.treeBase.tree[2].row.visible ).toEqual( true, 'tree[2] should have changed to visible' ); - expect( grid.treeBase.tree[3].row.visible ).toEqual( false, 'tree[3] has no visible children, shouldn\'t have changed to visible' ); - expect( grid.treeBase.tree[0].children[0].row.visible ).toEqual( true, 'tree[0].children[0] should have changed to visible' ); - expect( grid.treeBase.tree[0].children[1].row.visible ).toEqual( true, 'tree[0].children[1] should have changed to visible' ); - expect( grid.treeBase.tree[0].children[2].row.visible ).toEqual( false, 'tree[0].children[2] has no visible children, shouldn\'t have changed to visible' ); - }); - }); - - describe( 'getAggregations', function() { - it( 'no aggregations', function() { - expect( uiGridTreeBaseService.getAggregations(grid) ).toEqual( [] ); - }); - - it( 'two aggregations, one looks up label', function() { - // treeBase has added a rowHeader column, so columns shifted right by one - grid.columns[2].treeAggregation = { type: 'sum', label: uiGridTreeBaseService.nativeAggregations().sum.label }; - grid.columns[2].treeAggregationFn = uiGridTreeBaseService.nativeAggregations().sum.aggregationFn; - - grid.columns[3].treeAggregationFn = angular.noop; - grid.columns[3].treeAggregation = {label: 'custom- '}; - - var result = uiGridTreeBaseService.getAggregations(grid); - expect( result.length ).toEqual(2, '2 aggregated columns'); - expect( result[0].col.name ).toEqual('col1', 'col1 is first aggregation'); - delete result[0].col; - expect( result[1].col.name ).toEqual('col2', 'col2 is second aggregation'); - delete result[1].col; - expect( result ).toEqual([ - { - type: 'sum', - label: 'total: ' - }, - { - label: 'custom- ' - } - ]); - }); - }); - - - describe( 'aggregate', function() { - it( 'no parents', function() { - var parents = [ - ]; - - uiGridTreeBaseService.aggregate(grid, grid.rows[0], parents ); - - expect( parents ).toEqual([ - ]); - }); - - it( 'no aggregations', function() { - var parents = [ - { treeNode: { aggregations: [] } }, - { treeNode: { aggregations: [] } } - ]; - - uiGridTreeBaseService.aggregate(grid, grid.rows[0], parents ); - - expect( parents ).toEqual([ - { treeNode: { aggregations: [] } }, - { treeNode: { aggregations: [] } } - ]); - }); - - it( 'some aggregations over two parents', function() { - var customAggregation = function( aggregation, fieldValue, numValue ) { - aggregation.custom = numValue / 2; - }; - - grid.columns[4].treeAggregationFn = customAggregation; - - var parents = [ - { treeNode: { aggregations: [ - { col: grid.columns[4], custom: 20 } - ]}}, - { treeNode: { aggregations: [ - { col: grid.columns[4], custom: 19 } - ]}} - ]; - - uiGridTreeBaseService.aggregate(grid, grid.rows[2], parents ); - - // remove column references, they make it impossible to see what's going on in failure messages - parents.forEach(function(parent){ - parent.treeNode.aggregations.forEach( function(aggregation){ - delete aggregation.col; - }); - }); - - expect(parents[0].treeNode.aggregations[0]).toEqual({ custom: 1 }); - - expect(parents[1].treeNode.aggregations[0]).toEqual({ custom: 1 }); - - }); - }); - - - describe( 'finaliseAggregations', function() { - it( 'no aggregations', function() { - var fakeRow = { treeNode: { aggregations: [ - ]}}; - - uiGridTreeBaseService.finaliseAggregations( fakeRow ); - - expect( fakeRow ).toEqual( { treeNode: { aggregations: [ - ]}}); - }); - - it( 'some aggregations', function() { - var fakeColumn = { uid: '123', treeAggregationUpdateEntity: true, customTreeAggregationFinalizerFn: function( aggregation ){ - aggregation.rendered = 'custom'; - }}; - - var fakeRow = { entity: {}, treeNode: { aggregations: [ - { value: 10, label: 'test: ', col: fakeColumn }, - { value: 10, label: 'test: ', col: { uid: '345', treeAggregationUpdateEntity: true } } - ]}}; - - uiGridTreeBaseService.finaliseAggregations( fakeRow ); - - delete fakeRow.treeNode.aggregations[0].col; - delete fakeRow.treeNode.aggregations[1].col; - - expect( fakeRow ).toEqual( { entity: { - $$123: { value: 10, label: 'test: ', rendered: 'custom' }, - $$345: { value: 10, label: 'test: ', rendered: 'test: 10' } - }, treeNode: { aggregations: [ - { value: 10, label: 'test: ', rendered: 'custom'}, - { value: 10, label: 'test: ', rendered: 'test: 10' } - ]}}); - }); - }); -}); diff --git a/src/features/tree-view/templates/treeViewExpandAllButtons.html b/src/features/tree-view/templates/treeViewExpandAllButtons.html deleted file mode 100644 index f6f126a871..0000000000 --- a/src/features/tree-view/templates/treeViewExpandAllButtons.html +++ /dev/null @@ -1,2 +0,0 @@ -
    -
    \ No newline at end of file diff --git a/src/features/tree-view/templates/treeViewHeaderCell.html b/src/features/tree-view/templates/treeViewHeaderCell.html deleted file mode 100644 index 4c4b02e8ff..0000000000 --- a/src/features/tree-view/templates/treeViewHeaderCell.html +++ /dev/null @@ -1,5 +0,0 @@ -
    -
    - -
    -
    diff --git a/src/features/tree-view/templates/treeViewRowHeader.html b/src/features/tree-view/templates/treeViewRowHeader.html deleted file mode 100644 index 5a0475c579..0000000000 --- a/src/features/tree-view/templates/treeViewRowHeader.html +++ /dev/null @@ -1,3 +0,0 @@ -
    - -
    diff --git a/src/features/tree-view/templates/treeViewRowHeaderButtons.html b/src/features/tree-view/templates/treeViewRowHeaderButtons.html deleted file mode 100644 index 30cda00931..0000000000 --- a/src/features/tree-view/templates/treeViewRowHeaderButtons.html +++ /dev/null @@ -1,4 +0,0 @@ -
    - -   -
    \ No newline at end of file diff --git a/src/features/tree-view/test/tree-view.spec.js b/src/features/tree-view/test/tree-view.spec.js deleted file mode 100644 index 7892aa8e16..0000000000 --- a/src/features/tree-view/test/tree-view.spec.js +++ /dev/null @@ -1,50 +0,0 @@ -describe('ui.grid.treeView uiGridTreeViewService', function () { - var uiGridTreeViewService; - var uiGridTreeViewConstants; - var gridClassFactory; - var grid; - var $rootScope; - var $scope; - var GridRow; - - beforeEach(module('ui.grid.treeView')); - - beforeEach(inject(function (_uiGridTreeViewService_,_gridClassFactory_, $templateCache, _uiGridTreeViewConstants_, - _$rootScope_, _GridRow_) { - uiGridTreeViewService = _uiGridTreeViewService_; - uiGridTreeViewConstants = _uiGridTreeViewConstants_; - gridClassFactory = _gridClassFactory_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - GridRow = _GridRow_; - - $templateCache.put('ui-grid/uiGridCell', '
    '); - $templateCache.put('ui-grid/editableCell', '
    '); - - grid = gridClassFactory.createGrid({}); - grid.options.columnDefs = [ - {field: 'col0'}, - {field: 'col1'}, - {field: 'col2'}, - {field: 'col3'} - ]; - - _uiGridTreeViewService_.initializeGrid(grid, $scope); - var data = []; - for (var i = 0; i < 10; i++) { - data.push({col0: 'a_' + Math.floor(i/4), col1: 'b_' + Math.floor(i/2), col2: 'c_' + i, col3: 'd_' + i}); - } - data[0].$$treeLevel = 0; - data[1].$$treeLevel = 1; - data[3].$$treeLevel = 1; - data[4].$$treeLevel = 2; - data[7].$$treeLevel = 0; - data[9].$$treeLevel = 1; - - grid.options.data = data; - - grid.buildColumns(); - grid.modifyRows(grid.options.data); - })); - -}); diff --git a/src/features/validate/less/validate.less b/src/features/validate/less/validate.less deleted file mode 100644 index 86646d7f67..0000000000 --- a/src/features/validate/less/validate.less +++ /dev/null @@ -1,5 +0,0 @@ -@import '../../../less/variables'; - -div.ui-grid-cell-contents.invalid { - border: @invalidValueBorder; -} \ No newline at end of file diff --git a/src/features/validate/templates/cellTitleValidator.html b/src/features/validate/templates/cellTitleValidator.html deleted file mode 100644 index ff0cd35309..0000000000 --- a/src/features/validate/templates/cellTitleValidator.html +++ /dev/null @@ -1,5 +0,0 @@ -
    - {{COL_FIELD CUSTOM_FILTERS}} -
    \ No newline at end of file diff --git a/src/features/validate/templates/cellTooltipValidator.html b/src/features/validate/templates/cellTooltipValidator.html deleted file mode 100644 index 5ad0fa6f65..0000000000 --- a/src/features/validate/templates/cellTooltipValidator.html +++ /dev/null @@ -1,9 +0,0 @@ -
    - {{COL_FIELD CUSTOM_FILTERS}} -
    \ No newline at end of file diff --git a/src/features/validate/test/uiGridValidateDirective.spec.js b/src/features/validate/test/uiGridValidateDirective.spec.js deleted file mode 100644 index a117ab6de1..0000000000 --- a/src/features/validate/test/uiGridValidateDirective.spec.js +++ /dev/null @@ -1,180 +0,0 @@ -describe('uiGridValidateDirective', function () { - var scope; - var element; - var recompile; - var digest; - var uiGridConstants; - var $timeout; - - beforeEach(module('ui.grid.validate', 'ui.grid.edit')); - - beforeEach(inject(function ($rootScope, $compile, _uiGridConstants_, _$timeout_, $templateCache) { - - scope = $rootScope.$new(); - scope.options = {enableCellEdit: true}; - scope.options.data = [ - {col1: 'A1', col2: 'B1'}, - {col1: 'A2', col2: 'B2'} - ]; - - scope.options.columnDefs = [ - {field: 'col1', validators: {required: true}, - cellTemplate: 'ui-grid/cellTitleValidator'}, - {field: 'col2', validators: {minLength: 2}, - cellTemplate: 'ui-grid/cellTooltipValidator'} - ]; - - - recompile = function () { - $compile(element)(scope); - $rootScope.$digest(); - }; - - digest = function() { - $rootScope.$digest(); - }; - - uiGridConstants = _uiGridConstants_; - $timeout = _$timeout_; - - })); - - - it('should add a validate property to the grid', function () { - - element = angular.element('
    '); - recompile(); - - var gridScope = element.scope().$$childHead; - - var validate = gridScope.grid.validate; - - expect(validate).toBeDefined(); - - }); - - it('should run validators on a edited cell', function () { - - element = angular.element('
    '); - recompile(); - - var cells = element.find('.ui-grid-cell-contents.ng-scope'); - - for (var i = 0; i < cells.length; i++) { - var cellContent = cells[i]; - var cellValue = cellContent.textContent; - var event = jQuery.Event("keydown"); - - var cell = angular.element(cellContent.parentElement); - cell.dblclick(); - $timeout.flush(); - expect(cell.find('input').length).toBe(1); - - switch (cellValue) { - case 'A1': - cell.find('input').controller('ng-model').$setViewValue(''); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(true); - break; - case 'B1': - cell.find('input').controller('ng-model').$setViewValue('B'); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(true); - break; - case 'A2': - cell.find('input').controller('ng-model').$setViewValue('A'); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(false); - break; - case 'B2': - cell.find('input').controller('ng-model').$setViewValue('B2+'); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(false); - break; - } - } - }); - - it('should run validators on a edited invalid cell', function () { - element = angular.element('
    '); - recompile(); - - var cells = element.find('.ui-grid-cell-contents.ng-scope'); - var cellContent = cells[0]; - var cellValue = cellContent.textContent; - var event = jQuery.Event("keydown"); - - var cell = angular.element(cellContent.parentElement); - cell.dblclick(); - $timeout.flush(); - expect(cell.find('input').length).toBe(1); - - cell.find('input').controller('ng-model').$setViewValue(''); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(true); - - cell.dblclick(); - $timeout.flush(); - expect(cell.find('input').length).toBe(1); - - cell.find('input').controller('ng-model').$setViewValue('A1'); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(false); - }); - - it('should raise an event when validation fails', function () { - - element = angular.element('
    '); - recompile(); - - var cells = element.find('.ui-grid-cell-contents.ng-scope'); - var cellContent = cells[1]; - var cellValue = cellContent.textContent; - var event = jQuery.Event("keydown"); - var scope = angular.element(cellContent).scope(); - var grid = scope.grid; - - var listenerObject; - - grid.api.validate.on.validationFailed(scope, function(rowEntity, colDef, newValue, oldValue) { - listenerObject = [rowEntity, colDef, newValue, oldValue]; - }); - - var validationFailedSpy = jasmine.createSpy('validationFailed'); - validationFailedSpy.and.callThrough(); - validationFailedSpy(grid.api.validate.raise, 'validationFailed'); - - var cell = angular.element(cellContent.parentElement); - cell.dblclick(); - $timeout.flush(); - expect(cell.find('input').length).toBe(1); - - cell.find('input').controller('ng-model').$setViewValue('B'); - event = jQuery.Event("keydown"); - event.keyCode = uiGridConstants.keymap.TAB; - cell.find('input').trigger(event); - digest(); - expect(cellContent.classList.contains('invalid')).toBe(true); - expect(validationFailedSpy).toHaveBeenCalled(); - expect(angular.equals(listenerObject, [grid.options.data[0], grid.options.columnDefs[1], 'B', 'B1'])).toBe(true); - - }); -}); diff --git a/src/features/validate/test/uiGridValidateService.spec.js b/src/features/validate/test/uiGridValidateService.spec.js deleted file mode 100644 index 019467516c..0000000000 --- a/src/features/validate/test/uiGridValidateService.spec.js +++ /dev/null @@ -1,216 +0,0 @@ -describe('ui.grid.validate uiGridValidateService', function () { - var uiGridValidateService; - var $rootScope; - - beforeEach(module('ui.grid.validate')); - - beforeEach(inject(function (_uiGridValidateService_, _$rootScope_) { - uiGridValidateService = _uiGridValidateService_; - $rootScope = _$rootScope_; - })); - - it('should create an empty validatorFactories object', function() { - expect(angular.equals(uiGridValidateService.validatorFactories, {})).toBe(true); - }); - - it('should add a validator when calling setValidator', function() { - uiGridValidateService.setValidator('test', angular.noop, angular.noop); - expect(uiGridValidateService.validatorFactories.test).toBeDefined(); - }); - - it('should return a validator function when calling getValidator with an argument', function() { - var fooFactory = function(argument) { - return function() { - return 'foo'+argument; - }; - }; - uiGridValidateService.setValidator('foo', fooFactory, angular.noop); - expect(uiGridValidateService.getValidator('foo','bar')()).toBe('foobar'); - }); - - it('should return a message function when calling getMessage with an argument', function() { - var messageFunction = function(argument) { - return 'message'+argument; - }; - uiGridValidateService.setValidator('foo', angular.noop, messageFunction); - expect(uiGridValidateService.getMessage('foo','bar')).toBe('messagebar'); - }); - - it('should return true when calling isInvalid on an invalid cell', function() { - var colDef = {name: 'foo'}; - var entity = {'$$invalidfoo': true}; - - expect(uiGridValidateService.isInvalid(entity, colDef)).toBe(true); - }); - - it('should return false when calling isInvalid on a valid cell', function() { - var colDef = {name: 'foo'}; - var entity = {'$$invalidfoo': false}; - - expect(uiGridValidateService.isInvalid(entity, colDef)).toBeFalsy(); - - colDef = {name: 'bar'}; - expect(uiGridValidateService.isInvalid(entity, colDef)).toBeFalsy(); - }); - - it('should set a cell as invalid when calling setInvalid on a valid cell', function() { - var colDef = {name: 'foo'}; - var entity = {}; - - uiGridValidateService.setInvalid(entity, colDef); - expect(entity['$$invalidfoo']).toBe(true); - - entity = {'$$invalidfoo': false}; - - uiGridValidateService.setInvalid(entity, colDef); - expect(entity['$$invalidfoo']).toBe(true); - }); - - it('should set a cell as valid when calling setValid on an invalid cell', function() { - var colDef = {name: 'foo'}; - var entity = {'$$invalidfoo': true}; - - uiGridValidateService.setValid(entity, colDef); - - expect(entity['$$invalidfoo']).toBeUndefined(); - }); - - it('should add an error to a cell when calling setError on that cell', function() { - var colDef = {name: 'foo'}; - var entity = {}; - - uiGridValidateService.setError(entity, colDef, 'bar'); - expect(entity['$$errorsfoo'].bar).toBe(true); - - entity['$$errorsfoo'].bar = false; - - uiGridValidateService.setError(entity, colDef, 'bar'); - expect(entity['$$errorsfoo'].bar).toBe(true); - }); - - it('should remove an error to a cell when calling clearError on that cell', function() { - var colDef = {name: 'foo'}; - var entity = {'$$errorsfoo': {bar: true} }; - - uiGridValidateService.clearError(entity, colDef, 'bar'); - expect(entity['$$errorsfoo'].bar).toBeUndefined(); - - }); - - it('should return an array with all error messages (alphabetically sorted) when calling getErrorMessages on a cell', function() { - var colDef = {name: 'test', validators: {foo: 'foo', bar: 'bar'}}; - var entity = {'$$errorstest': {foo: true, bar: true} }; - - var fooMessage = function(argument) {return argument + 'Message';}; - var barMessage = function(argument) {return argument + 'Message';}; - - uiGridValidateService.setValidator('foo', angular.noop, fooMessage); - uiGridValidateService.setValidator('bar', angular.noop, barMessage); - - var messages = uiGridValidateService.getErrorMessages(entity, colDef); - expect(messages[0]).toBe('barMessage'); - expect(messages[1]).toBe('fooMessage'); - - }); - - it('should execute all validators when calling runValidators on a cell and set/clear errors', function() { - var colDef = {name: 'test', validators: {foo: 'foo', bar: 'bar'}}; - var entity = {}; - - var validatorFactory = function (argument) {return function() {return argument === 'foo';};}; - - uiGridValidateService.setValidator('foo', validatorFactory, angular.noop); - uiGridValidateService.setValidator('bar', validatorFactory, angular.noop); - - uiGridValidateService.runValidators(entity, colDef, 1, 0); - - $rootScope.$apply(); - - expect(entity['$$errorstest'].bar).toBe(true); - expect(entity['$$invalidtest']).toBe(true); - - expect(entity['$$errorstest'].foo).toBeFalsy(); - - - }); - - it('should return a promise when calling runValidators on a cell', function() { - var colDef = {name: 'test', validators: {foo: 'foo', bar: 'bar'}}; - var entity = {}; - - var validatorFactory = function (argument) {return function() {return argument === 'foo';};}; - - uiGridValidateService.setValidator('foo', validatorFactory, angular.noop); - uiGridValidateService.setValidator('bar', validatorFactory, angular.noop); - - var promise = uiGridValidateService.runValidators(entity, colDef, 1, 0); - - expect(promise).toBeDefined(); - - $rootScope.$apply(); - - expect(entity['$$errorstest'].bar).toBe(true); - expect(entity['$$invalidtest']).toBe(true); - - expect(entity['$$errorstest'].foo).toBeFalsy(); - - }); - - it('should not execute any validator when calling runValidators with newValue === oldValue', function() { - var colDef = {name: 'test', validators: {foo: 'foo', bar: 'bar'}}; - var entity = {}; - - var validatorFactory = function (argument) {return function() {return argument === 'foo';};}; - - uiGridValidateService.setValidator('foo', validatorFactory, angular.noop); - uiGridValidateService.setValidator('bar', validatorFactory, angular.noop); - - uiGridValidateService.runValidators(entity, colDef, 1, 1); - - $rootScope.$apply(); - - expect(entity['$$errorstest']).toBeUndefined(); - expect(entity['$$invalidtest']).toBeUndefined(); - - }); - - it('should run an external validator if an external validator factory is set', function() { - - var colDef = {name: 'test', validators: {foo: 'foo'}}; - var entity = {}; - - var externalFooValidator = function() {return function() {return false;};}; - var externalFactoryFunction = function(name, argument) { - if (name === 'foo') { - return {validatorFactory: externalFooValidator, messageFunction: angular.noop}; - } - }; - - uiGridValidateService.setExternalFactoryFunction(externalFactoryFunction); - - var validatorFactory = function (argument) {return function() {return argument === 'foo';};}; - - uiGridValidateService.setValidator('foo', validatorFactory, angular.noop); - - uiGridValidateService.runValidators(entity, colDef, 1, 0); - - $rootScope.$apply(); - - expect(entity['$$errorstest'].foo).toBe(true); - expect(entity['$$invalidtest']).toBe(true); - - }); - - describe('should call setValidator three times when calling createDefaultValidators', function() { - beforeEach(function() { - spyOn(uiGridValidateService, 'setValidator'); - }); - it('', function() { - uiGridValidateService.createDefaultValidators(); - - expect(uiGridValidateService.setValidator.calls.count()).toBe(3); - }); - - }); - -}); diff --git a/src/font/ui-grid.eot b/src/fonts/ui-grid.eot similarity index 99% rename from src/font/ui-grid.eot rename to src/fonts/ui-grid.eot index 3b34315879..59cf0aed25 100644 Binary files a/src/font/ui-grid.eot and b/src/fonts/ui-grid.eot differ diff --git a/src/font/ui-grid.svg b/src/fonts/ui-grid.svg similarity index 100% rename from src/font/ui-grid.svg rename to src/fonts/ui-grid.svg diff --git a/src/font/ui-grid.ttf b/src/fonts/ui-grid.ttf similarity index 99% rename from src/font/ui-grid.ttf rename to src/fonts/ui-grid.ttf index f33fd25508..b1a4b06116 100644 Binary files a/src/font/ui-grid.ttf and b/src/fonts/ui-grid.ttf differ diff --git a/src/font/ui-grid.woff b/src/fonts/ui-grid.woff similarity index 100% rename from src/font/ui-grid.woff rename to src/fonts/ui-grid.woff diff --git a/src/i18n/ui-grid.auto-resize.js b/src/i18n/ui-grid.auto-resize.js new file mode 100644 index 0000000000..c3deb08e36 --- /dev/null +++ b/src/i18n/ui-grid.auto-resize.js @@ -0,0 +1,68 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + /** + * @ngdoc overview + * @name ui.grid.autoResize + * + * @description + * + * #ui.grid.autoResize + * + * + * + * This module provides auto-resizing functionality to UI-Grid. + */ + var module = angular.module('ui.grid.autoResize', ['ui.grid']); + + /** + * @ngdoc directive + * @name ui.grid.autoResize.directive:uiGridAutoResize + * @element div + * @restrict A + * + * @description Stacks on top of the ui-grid directive and + * adds the a watch to the grid's height and width which refreshes + * the grid content whenever its dimensions change. + * + */ + module.directive('uiGridAutoResize', ['gridUtil', function(gridUtil) { + return { + require: 'uiGrid', + scope: false, + link: function($scope, $elm, $attrs, uiGridCtrl) { + var debouncedRefresh; + + function getDimensions() { + return { + width: gridUtil.elementWidth($elm), + height: gridUtil.elementHeight($elm) + }; + } + + function refreshGrid(prevWidth, prevHeight, width, height) { + if ($elm[0].offsetParent !== null) { + uiGridCtrl.grid.gridWidth = width; + uiGridCtrl.grid.gridHeight = height; + uiGridCtrl.grid.queueGridRefresh() + .then(function() { + uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevHeight, prevWidth, height, width); + }); + } + } + + debouncedRefresh = gridUtil.debounce(refreshGrid, 400); + + $scope.$watchCollection(getDimensions, function(newValues, oldValues) { + if (!angular.equals(newValues, oldValues)) { + debouncedRefresh(oldValues.width, oldValues.height, newValues.width, newValues.height); + } + }); + } + }; + }]); +})(); diff --git a/src/i18n/ui-grid.auto-resize.min.js b/src/i18n/ui-grid.auto-resize.min.js new file mode 100644 index 0000000000..c7cd2d213a --- /dev/null +++ b/src/i18n/ui-grid.auto-resize.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";angular.module("ui.grid.autoResize",["ui.grid"]).directive("uiGridAutoResize",["gridUtil",function(n){return{require:"uiGrid",scope:!1,link:function(i,r,e,u){var t;t=n.debounce(function(i,e,t,n){null!==r[0].offsetParent&&(u.grid.gridWidth=t,u.grid.gridHeight=n,u.grid.queueGridRefresh().then(function(){u.grid.api.core.raise.gridDimensionChanged(e,i,n,t)}))},400),i.$watchCollection(function(){return{width:n.elementWidth(r),height:n.elementHeight(r)}},function(i,e){angular.equals(i,e)||t(e.width,e.height,i.width,i.height)})}}}])}(); \ No newline at end of file diff --git a/src/features/cellnav/js/cellnav.js b/src/i18n/ui-grid.cellnav.js similarity index 58% rename from src/features/cellnav/js/cellnav.js rename to src/i18n/ui-grid.cellnav.js index 152febb271..c86aaec631 100644 --- a/src/features/cellnav/js/cellnav.js +++ b/src/i18n/ui-grid.cellnav.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -99,7 +104,6 @@ case uiGridCellNavConstants.direction.PG_DOWN: return this.getRowColPageDown(curRow, curCol); } - }; UiGridCellNav.prototype.initializeSelection = function () { @@ -109,9 +113,7 @@ return null; } - var curRowIndex = 0; - var curColIndex = 0; - return new GridRowColumn(focusableRows[0], focusableCols[0]); //return same row + return new GridRowColumn(focusableRows[0], focusableCols[0]); // return same row }; UiGridCellNav.prototype.getRowColLeft = function (curRow, curCol) { @@ -120,24 +122,24 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 1 + // could not find column in focusable Columns so set it to 1 if (curColIndex === -1) { curColIndex = 1; } var nextColIndex = curColIndex === 0 ? focusableCols.length - 1 : curColIndex - 1; - //get column to left + // get column to left if (nextColIndex >= curColIndex) { // On the first row // if (curRowIndex === 0 && curColIndex === 0) { // return null; // } if (curRowIndex === 0) { - return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row } else { - //up one row and far right column + // up one row and far right column return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[nextColIndex]); } } @@ -154,7 +156,7 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 0 + // could not find column in focusable Columns so set it to 0 if (curColIndex === -1) { curColIndex = 0; } @@ -162,10 +164,10 @@ if (nextColIndex <= curColIndex) { if (curRowIndex === focusableRows.length - 1) { - return new GridRowColumn(curRow, focusableCols[nextColIndex]); //return same row + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row } else { - //down one row and far left column + // down one row and far left column return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[nextColIndex]); } } @@ -180,16 +182,16 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 0 + // could not find column in focusable Columns so set it to 0 if (curColIndex === -1) { curColIndex = 0; } if (curRowIndex === focusableRows.length - 1) { - return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row } else { - //down one row + // down one row return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]); } }; @@ -200,17 +202,17 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 0 + // could not find column in focusable Columns so set it to 0 if (curColIndex === -1) { curColIndex = 0; } var pageSize = this.bodyContainer.minRowsToRender(); if (curRowIndex >= focusableRows.length - pageSize) { - return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); //return last row + return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); // return last row } else { - //down one page + // down one page return new GridRowColumn(focusableRows[curRowIndex + pageSize], focusableCols[curColIndex]); } }; @@ -221,16 +223,16 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 0 + // could not find column in focusable Columns so set it to 0 if (curColIndex === -1) { curColIndex = 0; } if (curRowIndex === 0) { - return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row } else { - //up one row + // up one row return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[curColIndex]); } }; @@ -241,17 +243,17 @@ var curColIndex = focusableCols.indexOf(curCol); var curRowIndex = focusableRows.indexOf(curRow); - //could not find column in focusable Columns so set it to 0 + // could not find column in focusable Columns so set it to 0 if (curColIndex === -1) { curColIndex = 0; } var pageSize = this.bodyContainer.minRowsToRender(); if (curRowIndex - pageSize < 0) { - return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); //return first row + return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); // return first row } else { - //up one page + // up one page return new GridRowColumn(focusableRows[curRowIndex - pageSize], focusableCols[curColIndex]); } }; @@ -267,14 +269,16 @@ */ module.service('uiGridCellNavService', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', '$q', 'uiGridCellNavFactory', 'GridRowColumn', 'ScrollEvent', function (gridUtil, uiGridConstants, uiGridCellNavConstants, $q, UiGridCellNav, GridRowColumn, ScrollEvent) { + var service = { + initializeGrid: function (grid) { grid.registerColumnBuilder(service.cellNavColumnBuilder); /** - * @ngdoc object - * @name ui.grid.cellNav:Grid.cellNav + * @ngdoc object + * @name ui.grid.cellNav.Grid:cellNav * @description cellNav properties added to grid class */ grid.cellNav = {}; @@ -298,7 +302,7 @@ * @eventOf ui.grid.cellNav.api:PublicApi * @description raised when the active cell is changed *
    -                 *      gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol){})
    +                 *      gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol) {})
                      * 
    * @param {object} newRowCol new position * @param {object} oldRowCol old position @@ -378,7 +382,7 @@ * @param {object} rowCol the rowCol to evaluate */ rowColSelectIndex: function (rowCol) { - //return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) && + // return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) && var index = -1; for (var i = 0; i < grid.cellNav.focusedCells.length; i++) { if (grid.cellNav.focusedCells[i].col.uid === rowCol.col.uid && @@ -394,18 +398,8 @@ }; grid.api.registerEventsFromObject(publicApi.events); - grid.api.registerMethodsFromObject(publicApi.methods); - return publicApi; - }, - uninitializeGrid: function (grid, publicApi) { - if (publicApi) { - return; - } - - grid.unregisterColumnBulder(service.cellNavColumnBuilder); - grid.api.unRegisterEventsFromObject(publicApi.events); - grid.api.unRegisterMethodsFromObject(publicApi.methods); + grid.api.registerMethodsFromObject(publicApi.methods); }, defaultGridOptions: function (gridOptions) { @@ -481,7 +475,7 @@ return uiGridCellNavConstants.direction.UP; } - if (evt.keyCode === uiGridConstants.keymap.PG_UP){ + if (evt.keyCode === uiGridConstants.keymap.PG_UP) { return uiGridCellNavConstants.direction.PG_UP; } @@ -490,7 +484,7 @@ return uiGridCellNavConstants.direction.DOWN; } - if (evt.keyCode === uiGridConstants.keymap.PG_DOWN){ + if (evt.keyCode === uiGridConstants.keymap.PG_DOWN) { return uiGridCellNavConstants.direction.PG_DOWN; } @@ -554,7 +548,7 @@ // Broadcast the navigation if (gridRow !== null && gridCol !== null) { - grid.cellNav.broadcastCellNav(rowCol); + grid.cellNav.broadcastCellNav(rowCol, null, null); } }); }, @@ -572,7 +566,7 @@ * we include (thisColIndex / totalNumberCols) % of this column width * @param {Grid} grid the grid you'd like to act upon, usually available * from gridApi.grid - * @param {gridCol} upToCol the column to total up to and including + * @param {GridColumn} upToCol the column to total up to and including */ getLeftWidth: function (grid, upToCol) { var width = 0; @@ -585,7 +579,7 @@ // total column widths up-to but not including the passed in column grid.renderContainers.body.visibleColumnCache.forEach( function( col, index ) { - if ( index < lastIndex ){ + if ( index < lastIndex ) { width += col.drawnWidth; } }); @@ -645,169 +639,134 @@ return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { var _scope = $scope; - var api; var grid = uiGridCtrl.grid; + uiGridCellNavService.initializeGrid(grid); + + uiGridCtrl.cellNav = {}; + + // Ensure that the object has all of the methods we expect it to + uiGridCtrl.cellNav.makeRowCol = function (obj) { + if (!(obj instanceof GridRowColumn)) { + obj = new GridRowColumn(obj.row, obj.col); + } + return obj; + }; + + uiGridCtrl.cellNav.getActiveCell = function () { + var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus'); + if (elms.length > 0) { + return elms[0]; + } + + return undefined; + }; + + uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); + + newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol); + + uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt); + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt); + }; + + uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () { + grid.cellNav.focusedCells = []; + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT); + }; - function setupCellNav() { - uiGridCtrl.cellNav = {}; + uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); - //Ensure that the object has all of the methods we expect it to - uiGridCtrl.cellNav.makeRowCol = function (obj) { - if (!(obj instanceof GridRowColumn)) { - obj = new GridRowColumn(obj.row, obj.col); + rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol); + + var row = rowCol.row, + col = rowCol.col; + + var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); + + if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1 || (grid.cellNav.lastRowCol.col === col && grid.cellNav.lastRowCol.row === row)) { + var newRowCol = new GridRowColumn(row, col); + + if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col || grid.options.enableCellEditOnFocus) { + grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol, originEvt); + grid.cellNav.lastRowCol = newRowCol; } - return obj; - }; - - uiGridCtrl.cellNav.getActiveCell = function () { - var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus'); - if (elms.length > 0){ - return elms[0]; + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) { + grid.cellNav.focusedCells.push(rowCol); + } else { + grid.cellNav.focusedCells = [rowCol]; } - - return undefined; - }; - - uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) { - modifierDown = !(modifierDown === undefined || !modifierDown); - - newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol); - - uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt); - _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt); - }; - - uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () { - grid.cellNav.focusedCells = []; - _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT); - }; - - uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) { - modifierDown = !(modifierDown === undefined || !modifierDown); - - rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol); - - var row = rowCol.row, - col = rowCol.col; - + } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown && + rowColSelectIndex >= 0) { + + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + } + }; + + uiGridCtrl.cellNav.handleKeyDown = function (evt) { + var direction = uiGridCellNavService.getDirection(evt); + if (direction === null) { + return null; + } + + var containerId = 'body'; + if (evt.uiGridTargetRenderContainerId) { + containerId = evt.uiGridTargetRenderContainerId; + } + + // Get the last-focused row+col combo + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol) { + // Figure out which new row+combo we're navigating to + var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col); + var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols(); var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); - - if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1) { - var newRowCol = new GridRowColumn(row, col); - - if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col){ - grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol, originEvt); - grid.cellNav.lastRowCol = newRowCol; - } - if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) { - grid.cellNav.focusedCells.push(rowCol); - } else { - grid.cellNav.focusedCells = [rowCol]; - } - } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown && - rowColSelectIndex >= 0) { - + // Shift+tab on top-left cell should exit cellnav on render container + if ( + // Navigating left + direction === uiGridCellNavConstants.direction.LEFT && + // New col is last col (i.e. wrap around) + rowCol.col === focusableCols[focusableCols.length - 1] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + evt.shiftKey + ) { grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; } - }; - - uiGridCtrl.cellNav.handleKeyDown = function (evt) { - var direction = uiGridCellNavService.getDirection(evt); - if (direction === null) { - return null; - } - - var containerId = 'body'; - if (evt.uiGridTargetRenderContainerId) { - containerId = evt.uiGridTargetRenderContainerId; - } - - // Get the last-focused row+col combo - var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); - if (lastRowCol) { - // Figure out which new row+combo we're navigating to - var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col); - var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols(); - var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); - // Shift+tab on top-left cell should exit cellnav on render container - if ( - // Navigating left - direction === uiGridCellNavConstants.direction.LEFT && - // New col is last col (i.e. wrap around) - rowCol.col === focusableCols[focusableCols.length - 1] && - // Staying on same row, which means we're at first row - rowCol.row === lastRowCol.row && - evt.keyCode === uiGridConstants.keymap.TAB && - evt.shiftKey - ) { - grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); - uiGridCtrl.cellNav.clearFocus(); - return true; - } - // Tab on bottom-right cell should exit cellnav on render container - else if ( - direction === uiGridCellNavConstants.direction.RIGHT && - // New col is first col (i.e. wrap around) - rowCol.col === focusableCols[0] && - // Staying on same row, which means we're at first row - rowCol.row === lastRowCol.row && - evt.keyCode === uiGridConstants.keymap.TAB && - !evt.shiftKey - ) { - grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); - uiGridCtrl.cellNav.clearFocus(); - return true; - } - - // Scroll to the new cell, if it's not completely visible within the render container's viewport - grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () { - uiGridCtrl.cellNav.broadcastCellNav(rowCol, null, evt); - }); - - - evt.stopPropagation(); - evt.preventDefault(); - - return false; + // Tab on bottom-right cell should exit cellnav on render container + else if ( + direction === uiGridCellNavConstants.direction.RIGHT && + // New col is first col (i.e. wrap around) + rowCol.col === focusableCols[0] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + !evt.shiftKey + ) { + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; } - }; - } - function setupGrid() { - api = uiGridCellNavService.initializeGrid(grid); - setupCellNav(); - } + // Scroll to the new cell, if it's not completely visible within the render container's viewport + grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () { + uiGridCtrl.cellNav.broadcastCellNav(rowCol, null, evt); + }); - function teardownGrid() { - uiGridCtrl.cellNav.clearFocus(); - uiGridCellNavService.uninitializeGrid(grid, api); - delete uiGridCtrl.cellNav; - api = undefined; - _scope.$broadcast('uib.cellNavState', false); - } - function updateGridState(state) { - if (state === undefined || state === 'true' && !api) { - setupGrid(); - } else if (api && state === 'false') { - teardownGrid(); - } - } + evt.stopPropagation(); + evt.preventDefault(); - $attrs.$observe('uiGridCellnav', function(value) { - updateGridState(value); - if (value === undefined || value === 'true') { - uiGridCtrl.grid.buildColumns().then(function() { - _scope.$broadcast('uib.cellNavState', true); - }); + return false; } - }); - - updateGridState($attrs.uiGridCellnav); + }; }, post: function ($scope, $elm, $attrs, uiGridCtrl) { - var _scope = $scope; var grid = uiGridCtrl.grid; var usesAria = true; @@ -821,11 +780,11 @@ usesAria = false; } - function addAriaLiveRegion(){ + function addAriaLiveRegion() { // Thanks to google docs for the inspiration behind how to do this // XXX: Why is this entire mess nessasary? // Because browsers take a lot of coercing to get them to read out live regions - //http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/ + // http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/ var ariaNotifierDomElt = '
    ')($scope); - $elm.append(focuser); - - focuser.on('focus', function (evt) { - evt.uiGridTargetRenderContainerId = containerId; - var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); - if (rowCol === null) { - rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null); - if (rowCol.row && rowCol.col) { - uiGridCtrl.cellNav.broadcastCellNav(rowCol); - } - } - }); - focuser.on('focusout', function(evt) { - if (uiGridCtrl.cellNav) { - uiGridCtrl.cellNav.clearFocus(); - } - }); + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } - $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function(evt, rowCol) { - if (!focuser.is(':focus') && rowCol) { - focuser.focus(); - } - }); - - uiGridCellnavCtrl.setAriaActivedescendant = function(id){ - $elm.attr('aria-activedescendant', id); - }; - - uiGridCellnavCtrl.removeAriaActivedescendant = function(id){ - if ($elm.attr('aria-activedescendant') === id){ - $elm.attr('aria-activedescendant', ''); - } - }; - - - uiGridCtrl.focus = function () { - gridUtil.focus.byElement(focuser[0]); - //allow for first time grid focus - }; - - var viewPortKeyDownWasRaisedForRowCol = null; - // Bind to keydown events in the render container - focuser.on('keydown', function (evt) { - evt.uiGridTargetRenderContainerId = containerId; - var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); - var raiseViewPortKeyDown = uiGridCtrl.grid.options.keyDownOverrides.some(function (override) { - return Object.keys(override).every( function (property) { - return override[property] === evt[property]; - }); - }); - var result = raiseViewPortKeyDown ? null : uiGridCtrl.cellNav.handleKeyDown(evt); - if (result === null) { - uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol); - viewPortKeyDownWasRaisedForRowCol = rowCol; - } - }); - //Bind to keypress events in the render container - //keypress events are needed by edit function so the key press - //that initiated an edit is not lost - //must fire the event in a timeout so the editor can - //initialize and subscribe to the event on another event loop - focuser.on('keypress', function (evt) { - if (viewPortKeyDownWasRaisedForRowCol) { - $timeout(function () { - uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol); - },4); - - viewPortKeyDownWasRaisedForRowCol = null; - } - }); - - $scope.$on('$destroy', function(){ - //Remove all event handlers associated with this focuser. - focuser.off(); - }); + var containerId = renderContainerCtrl.containerId; + + var grid = uiGridCtrl.grid; + + // run each time a render container is created + uiGridCellNavService.decorateRenderContainers(grid); + + // focusser only created for body + if (containerId !== 'body') { + return; } - function tearDownFocuser() { - if (focuser) { - focuser.off(); - } + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells) { + $elm.attr('aria-multiselectable', true); + } + else { + $elm.attr('aria-multiselectable', false); } - function toggleFocuserFeature(state) { - if (state === lastState) { - return; + // add an element with no dimensions that can be used to set focus and capture keystrokes + var focuser = $compile('
    ')($scope); + $elm.append(focuser); + + focuser.on('focus', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (rowCol === null) { + rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null); + if (rowCol.row && rowCol.col) { + uiGridCtrl.cellNav.broadcastCellNav(rowCol); + } } + }); - lastState = state; - if (state) { - setupFocuser(); - } else { - tearDownFocuser(); - } - } + uiGridCellnavCtrl.setAriaActivedescendant = function(id) { + $elm.attr('aria-activedescendant', id); + }; - $scope.$on('uib.cellNavState', function(event, state) { - toggleFocuserFeature(state); + uiGridCellnavCtrl.removeAriaActivedescendant = function(id) { + if ($elm.attr('aria-activedescendant') === id) { + $elm.attr('aria-activedescendant', ''); + } + }; + + + uiGridCtrl.focus = function () { + gridUtil.focus.byElement(focuser[0]); + // allow for first time grid focus + }; + + var viewPortKeyDownWasRaisedForRowCol = null; + // Bind to keydown events in the render container + focuser.on('keydown', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + var raiseViewPortKeyDown = uiGridCtrl.grid.options.keyDownOverrides.some(function (override) { + return Object.keys(override).every( function (property) { + return override[property] === evt[property]; + }); + }); + var result = raiseViewPortKeyDown ? null : uiGridCtrl.cellNav.handleKeyDown(evt); + if (result === null) { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol, uiGridCtrl.cellNav.handleKeyDown); + viewPortKeyDownWasRaisedForRowCol = rowCol; + } + }); + // Bind to keypress events in the render container + // keypress events are needed by edit function so the key press + // that initiated an edit is not lost + // must fire the event in a timeout so the editor can + // initialize and subscribe to the event on another event loop + focuser.on('keypress', function (evt) { + if (viewPortKeyDownWasRaisedForRowCol) { + $timeout(function () { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol); + }, 4); + + viewPortKeyDownWasRaisedForRowCol = null; + } }); - toggleFocuserFeature(uiGridCtrl.grid.api.cellNav); + $scope.$on('$destroy', function() { + // Remove all event handlers associated with this focuser. + focuser.off(); + }); } }; } }; }]); - module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log','$compile', - function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log, $compile) { + module.directive('uiGridViewport', + function () { return { replace: true, - priority: -99999, //this needs to run very last + priority: -99999, // this needs to run very last require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'], scope: false, compile: function () { @@ -1070,83 +988,61 @@ post: function ($scope, $elm, $attrs, controllers) { var uiGridCtrl = controllers[0], renderContainerCtrl = controllers[1]; - var destroySteps = []; - function setupViewPort() { - var containerId = renderContainerCtrl.containerId; - //no need to process for other containers - if (containerId !== 'body') { + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = renderContainerCtrl.containerId; + // no need to process for other containers + if (containerId !== 'body') { + return; + } + + var grid = uiGridCtrl.grid; + + grid.api.core.on.scrollBegin($scope, function () { + + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { return; } - - var grid = uiGridCtrl.grid; - - destroySteps.push(grid.api.core.on.scrollBegin($scope, function (args) { - - // Skip if there's no currently-focused cell - var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); - if (lastRowCol === null) { - return; - } - - //if not in my container, move on - //todo: worry about horiz scroll - if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { - return; - } - - uiGridCtrl.cellNav.clearFocus(); - - })); - - destroySteps.push(grid.api.core.on.scrollEnd($scope, function (args) { - // Skip if there's no currently-focused cell - var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); - if (lastRowCol === null) { - return; - } - - //if not in my container, move on - //todo: worry about horiz scroll - if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { - return; - } - - uiGridCtrl.cellNav.broadcastCellNav(lastRowCol); - - })); - - destroySteps.push(grid.api.cellNav.on.navigate($scope, function () { - //focus again because it can be lost - uiGridCtrl.focus(); - })); - } - function teardownViewPort() { - destroySteps.forEach(function (destroy) { - destroy(); - }); - destroySteps = []; - } + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; + } + + uiGridCtrl.cellNav.clearFocus(); + + }); + + grid.api.core.on.scrollEnd($scope, function (args) { + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { + return; + } - function toggleViewPort(state) { - if (state) { - setupViewPort(); - } else { - teardownViewPort(); + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; } - } - - $scope.$on('uib.cellNavState', function(event, state) { - toggleViewPort(state); + + uiGridCtrl.cellNav.broadcastCellNav(lastRowCol); }); - toggleViewPort(uiGridCtrl.grid.api.cellNav); + grid.api.cellNav.on.navigate($scope, function () { + // focus again because it can be lost + uiGridCtrl.focus(); + }); } }; } }; - }]); + }); /** * @ngdoc directive @@ -1165,164 +1061,120 @@ link: function ($scope, $elm, $attrs, controllers) { var uiGridCtrl = controllers[0], uiGridCellnavCtrl = controllers[1]; - var destroySteps = []; - var lastState; + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } - function setupFeature() { - if (!$scope.col.colDef.allowCellFocus) { - return; - } + if (!$scope.col.colDef.allowCellFocus) { + return; + } - //Convinience local variables - var grid = uiGridCtrl.grid; - $scope.focused = false; + // Convinience local variables + var grid = uiGridCtrl.grid; + $scope.focused = false; - // Make this cell focusable but only with javascript/a mouse click - $elm.attr('tabindex', -1); - destroySteps.push(function() { - $elm.removeAttr('tabindex'); - }); + // Make this cell focusable but only with javascript/a mouse click + $elm.attr('tabindex', -1); - // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused - function clickHandler(evt) { - uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt); + // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused + $elm.find('div').on('click', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt); - evt.stopPropagation(); - $scope.$apply(); - } + evt.stopPropagation(); + $scope.$apply(); + }); - var clickElement = $elm.find('div'); - clickElement.on('click', clickHandler); - destroySteps.push(function() { - clickElement.off('click', clickHandler); - }); + /* + * XXX Hack for screen readers. + * This allows the grid to focus using only the screen reader cursor. + * Since the focus event doesn't include key press information we can't use it + * as our primary source of the event. + */ + $elm.on('mousedown', preventMouseDown); - /* - * XXX Hack for screen readers. - * This allows the grid to focus using only the screen reader cursor. - * Since the focus event doesn't include key press information we can't use it - * as our primary source of the event. - */ - $elm.on('mousedown', preventMouseDown); - destroySteps.push(function() { + // turn on and off for edit events + if (uiGridCtrl.grid.api.edit) { + uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () { $elm.off('mousedown', preventMouseDown); }); - //turn on and off for edit events - if (uiGridCtrl.grid.api.edit) { - uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () { - $elm.off('mousedown', preventMouseDown); - }); + uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); - uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () { - $elm.on('mousedown', preventMouseDown); - }); + uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); + } - uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () { - $elm.on('mousedown', preventMouseDown); - }); - } + // In case we created a new row, and we are the new created row by ngRepeat + // then this cell content might have been selected previously + refreshCellFocus(); - // In case we created a new row, and we are the new created row by ngRepeat - // then this cell content might have been selected previously - refreshCellFocus(); + function preventMouseDown(evt) { + // Prevents the foucus event from firing if the click event is already going to fire. + // If both events fire it will cause bouncing behavior. + evt.preventDefault(); + } - function preventMouseDown(evt) { - //Prevents the foucus event from firing if the click event is already going to fire. - //If both events fire it will cause bouncing behavior. - evt.preventDefault(); - } + // You can only focus on elements with a tabindex value + $elm.on('focus', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt); + evt.stopPropagation(); + $scope.$apply(); + }); - //You can only focus on elements with a tabindex value - function handleFocus(evt) { - uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt); - evt.stopPropagation(); - $scope.$apply(); - } + // This event is fired for all cells. If the cell matches, then focus is set + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus); - $elm.on('focus', handleFocus); - destroySteps.push(function() { - $elm.off('focus', handleFocus); - }); + // Refresh cell focus when a new row id added to the grid + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) { + // Clear the focus if it's set to avoid the wrong cell getting focused during + // a short period of time (from now until $timeout function executed) + clearFocus(); - // This event is fired for all cells. If the cell matches, then focus is set - destroySteps.push($scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus)); + $scope.$applyAsync(refreshCellFocus); + }, [uiGridConstants.dataChange.ROW]); - // Refresh cell focus when a new row id added to the grid - destroySteps.push(uiGridCtrl.grid.registerDataChangeCallback(function (grid) { - // Clear the focus if it's set to avoid the wrong cell getting focused during - // a short period of time (from now until $timeout function executed) + function refreshCellFocus() { + var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) { + return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col); + }); + if (isFocused) { + setFocused(); + } else { clearFocus(); - - $timeout(refreshCellFocus); - }, [uiGridConstants.dataChange.ROW])); - - function refreshCellFocus() { - var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) { - return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col); - }); - if (isFocused) { - setFocused(); - } else { - clearFocus(); - } - } - - function setFocused() { - if (!$scope.focused){ - var div = $elm.find('div'); - div.addClass('ui-grid-cell-focus'); - $elm.attr('aria-selected', true); - uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id')); - $scope.focused = true; - } } + } - function clearFocus() { - if ($scope.focused){ - var div = $elm.find('div'); - div.removeClass('ui-grid-cell-focus'); - $elm.attr('aria-selected', false); - uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id')); - $scope.focused = false; - } + function setFocused() { + if (!$scope.focused) { + var div = $elm.find('div'); + div.addClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', true); + uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id')); + $scope.focused = true; } - - $scope.$on('$destroy', function () { - destroySteps.forEach(function(destory) { - destory(); - }); - }); } - function teardownFeature() { - destroySteps.forEach(function(destroy) { - destroy(); - }); - - destroySteps = []; + function clearFocus() { + if ($scope.focused) { + var div = $elm.find('div'); + div.removeClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', false); + uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id')); + $scope.focused = false; + } } - function handleFeatureState(state) { - if (state === lastState) { - return; - } + $scope.$on('$destroy', function () { + dataChangeDereg(); - lastState = state; - if (state) { - setupFeature(); - } else { - teardownFeature(); - } - } - $scope.$on('uib.cellNavState', function(event, state) { - handleFeatureState(state); + // .off withouth paramaters removes all handlers + $elm.find('div').off(); + $elm.off(); }); - - handleFeatureState(uiGridCtrl.grid.api.cellNav); } }; }]); - })(); diff --git a/src/i18n/ui-grid.cellnav.min.js b/src/i18n/ui-grid.cellnav.min.js new file mode 100644 index 0000000000..e80917cac1 --- /dev/null +++ b/src/i18n/ui-grid.cellnav.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.cellNav",["ui.grid"]);e.constant("uiGridCellNavConstants",{FEATURE_NAME:"gridCellNav",CELL_NAV_EVENT:"cellNav",direction:{LEFT:0,RIGHT:1,UP:2,DOWN:3,PG_UP:4,PG_DOWN:5},EVENT_TYPE:{KEYDOWN:0,CLICK:1,CLEAR:2}}),e.factory("uiGridCellNavFactory",["gridUtil","uiGridConstants","uiGridCellNavConstants","GridRowColumn","$q",function(e,l,o,a,i){var n=function(e,l,i,o){this.rows=e.visibleRowCache,this.columns=l.visibleColumnCache,this.leftColumns=i?i.visibleColumnCache:[],this.rightColumns=o?o.visibleColumnCache:[],this.bodyContainer=e};return n.prototype.getFocusableCols=function(){return this.leftColumns.concat(this.columns,this.rightColumns).filter(function(e){return e.colDef.allowCellFocus})},n.prototype.getFocusableRows=function(){return this.rows.filter(function(e){return!1!==e.allowCellFocus})},n.prototype.getNextRowCol=function(e,l,i){switch(e){case o.direction.LEFT:return this.getRowColLeft(l,i);case o.direction.RIGHT:return this.getRowColRight(l,i);case o.direction.UP:return this.getRowColUp(l,i);case o.direction.DOWN:return this.getRowColDown(l,i);case o.direction.PG_UP:return this.getRowColPageUp(l,i);case o.direction.PG_DOWN:return this.getRowColPageDown(l,i)}},n.prototype.initializeSelection=function(){var e=this.getFocusableCols(),l=this.getFocusableRows();return 0===e.length||0===l.length?null:new a(l[0],e[0])},n.prototype.getRowColLeft=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=1);var r=0===n?i.length-1:n-1;return new a(n<=r?0===t?e:o[t-1]:e,i[r])},n.prototype.getRowColRight=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=n===i.length-1?0:n+1;return r<=n?t===o.length-1?new a(e,i[r]):new a(o[t+1],i[r]):new a(e,i[r])},n.prototype.getRowColDown=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);return-1===n&&(n=0),t===o.length-1?new a(e,i[n]):new a(o[t+1],i[n])},n.prototype.getRowColPageDown=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=this.bodyContainer.minRowsToRender();return t>=o.length-r?new a(o[o.length-1],i[n]):new a(o[t+r],i[n])},n.prototype.getRowColUp=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);return-1===n&&(n=0),new a(0===t?e:o[t-1],i[n])},n.prototype.getRowColPageUp=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=this.bodyContainer.minRowsToRender();return new a(t-r<0?o[0]:o[t-r],i[n])},n}]),e.service("uiGridCellNavService",["gridUtil","uiGridConstants","uiGridCellNavConstants","$q","uiGridCellNavFactory","GridRowColumn","ScrollEvent",function(e,l,i,o,n,t,r){var a={initializeGrid:function(o){o.registerColumnBuilder(a.cellNavColumnBuilder),o.cellNav={},o.cellNav.lastRowCol=null,o.cellNav.focusedCells=[],a.defaultGridOptions(o.options);var e={events:{cellNav:{navigate:function(e,l){},viewPortKeyDown:function(e,l){},viewPortKeyPress:function(e,l){}}},methods:{cellNav:{scrollToFocus:function(e,l){return a.scrollToFocus(o,e,l)},getFocusedCell:function(){return o.cellNav.lastRowCol},getCurrentSelection:function(){return o.cellNav.focusedCells},rowColSelectIndex:function(e){for(var l=-1,i=0;i 
    ',v=r(n)(e),l.prepend(v),e.$on(d.CELL_NAV_EVENT,function(e,l,i,o){if(!o||"focus"!==o.type){for(var n,t,r,a,c=[],s=C.api.cellNav.getCurrentSelection(),d=0;d
    ')(e);l.append(s),s.on("focus",function(e){e.uiGridTargetRenderContainerId=a;var l=n.grid.api.cellNav.getFocusedCell();null===l&&(l=n.grid.renderContainers[a].cellNav.getNextRowCol(g.direction.DOWN,null,null)).row&&l.col&&n.cellNav.broadcastCellNav(l)}),r.setAriaActivedescendant=function(e){l.attr("aria-activedescendant",e)},r.removeAriaActivedescendant=function(e){l.attr("aria-activedescendant")===e&&l.attr("aria-activedescendant","")},n.focus=function(){v.focus.byElement(s[0])};var d=null;s.on("keydown",function(i){i.uiGridTargetRenderContainerId=a;var e=n.grid.api.cellNav.getFocusedCell();null===(n.grid.options.keyDownOverrides.some(function(l){return Object.keys(l).every(function(e){return l[e]===i[e]})})?null:n.cellNav.handleKeyDown(i))&&(n.grid.api.cellNav.raise.viewPortKeyDown(i,e,n.cellNav.handleKeyDown),d=e)}),s.on("keypress",function(e){d&&(u(function(){n.grid.api.cellNav.raise.viewPortKeyPress(e,d)},4),d=null)}),e.$on("$destroy",function(){s.off()})}}}}}}}]),e.directive("uiGridViewport",function(){return{replace:!0,priority:-99999,require:["^uiGrid","^uiGridRenderContainer","?^uiGridCellnav"],scope:!1,compile:function(){return{pre:function(e,l,i,o){},post:function(e,l,i,o){var n=o[0],t=o[1];if(n.grid.api.cellNav&&"body"===t.containerId){var r=n.grid;r.api.core.on.scrollBegin(e,function(){var e=n.grid.api.cellNav.getFocusedCell();null!==e&&t.colContainer.containsColumn(e.col)&&n.cellNav.clearFocus()}),r.api.core.on.scrollEnd(e,function(e){var l=n.grid.api.cellNav.getFocusedCell();null!==l&&t.colContainer.containsColumn(l.col)&&n.cellNav.broadcastCellNav(l)}),r.api.cellNav.on.navigate(e,function(){n.focus()})}}}}}}),e.directive("uiGridCell",["$timeout","$document","uiGridCellNavService","gridUtil","uiGridCellNavConstants","uiGridConstants","GridRowColumn",function(e,l,i,o,u,v,C){return{priority:-150,restrict:"A",require:["^uiGrid","?^uiGridCellnav"],scope:!1,link:function(i,l,e,o){var n=o[0],t=o[1];if(n.grid.api.cellNav&&i.col.colDef.allowCellFocus){var r=n.grid;i.focused=!1,l.attr("tabindex",-1),l.find("div").on("click",function(e){n.cellNav.broadcastCellNav(new C(i.row,i.col),e.ctrlKey||e.metaKey,e),e.stopPropagation(),i.$apply()}),l.on("mousedown",c),n.grid.api.edit&&(n.grid.api.edit.on.beginCellEdit(i,function(){l.off("mousedown",c)}),n.grid.api.edit.on.afterCellEdit(i,function(){l.on("mousedown",c)}),n.grid.api.edit.on.cancelCellEdit(i,function(){l.on("mousedown",c)})),s(),l.on("focus",function(e){n.cellNav.broadcastCellNav(new C(i.row,i.col),!1,e),e.stopPropagation(),i.$apply()}),i.$on(u.CELL_NAV_EVENT,s);var a=n.grid.registerDataChangeCallback(function(e){d(),i.$applyAsync(s)},[v.dataChange.ROW]);i.$on("$destroy",function(){a(),l.find("div").off(),l.off()})}function c(e){e.preventDefault()}function s(){r.cellNav.focusedCells.some(function(e,l){return e.row===i.row&&e.col===i.col})?function(){if(!i.focused){var e=l.find("div");e.addClass("ui-grid-cell-focus"),l.attr("aria-selected",!0),t.setAriaActivedescendant(l.attr("id")),i.focused=!0}}():d()}function d(){i.focused&&(l.find("div").removeClass("ui-grid-cell-focus"),l.attr("aria-selected",!1),t.removeAriaActivedescendant(l.attr("id")),i.focused=!1)}}}}])}(); \ No newline at end of file diff --git a/src/i18n/ui-grid.core.js b/src/i18n/ui-grid.core.js new file mode 100644 index 0000000000..38681c0c47 --- /dev/null +++ b/src/i18n/ui-grid.core.js @@ -0,0 +1,12726 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + + angular.module('ui.grid.i18n', []); + angular.module('ui.grid', ['ui.grid.i18n']); +})(); + +(function () { + 'use strict'; + + /** + * @ngdoc object + * @name ui.grid.service:uiGridConstants + * @description Constants for use across many grid features + * + */ + + + angular.module('ui.grid').constant('uiGridConstants', { + LOG_DEBUG_MESSAGES: true, + LOG_WARN_MESSAGES: true, + LOG_ERROR_MESSAGES: true, + CUSTOM_FILTERS: /CUSTOM_FILTERS/g, + COL_FIELD: /COL_FIELD/g, + MODEL_COL_FIELD: /MODEL_COL_FIELD/g, + TOOLTIP: /title=\"TOOLTIP\"/g, + DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g, + TEMPLATE_REGEXP: /<.+>/, + FUNC_REGEXP: /(\([^)]*\))?$/, + DOT_REGEXP: /\./g, + APOS_REGEXP: /'/g, + BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/, + COL_CLASS_PREFIX: 'ui-grid-col', + ENTITY_BINDING: '$$this', + events: { + GRID_SCROLL: 'uiGridScroll', + COLUMN_MENU_SHOWN: 'uiGridColMenuShown', + ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged + COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick' + }, + // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html + keymap: { + TAB: 9, + STRG: 17, + CAPSLOCK: 20, + CTRL: 17, + CTRLRIGHT: 18, + CTRLR: 18, + SHIFT: 16, + RETURN: 13, + ENTER: 13, + BACKSPACE: 8, + BCKSP: 8, + ALT: 18, + ALTR: 17, + ALTRIGHT: 17, + SPACE: 32, + WIN: 91, + MAC: 91, + FN: null, + PG_UP: 33, + PG_DOWN: 34, + UP: 38, + DOWN: 40, + LEFT: 37, + RIGHT: 39, + ESC: 27, + DEL: 46, + F1: 112, + F2: 113, + F3: 114, + F4: 115, + F5: 116, + F6: 117, + F7: 118, + F8: 119, + F9: 120, + F10: 121, + F11: 122, + F12: 123 + }, + /** + * @ngdoc object + * @name ASC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + ASC: 'asc', + /** + * @ngdoc object + * @name DESC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + DESC: 'desc', + + + /** + * @ngdoc object + * @name filter + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter} + * to configure filtering on the column + * + * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify + * one of the built-in conditions. + * + * Available `condition` options are: + * - `uiGridConstants.filter.STARTS_WITH` + * - `uiGridConstants.filter.ENDS_WITH` + * - `uiGridConstants.filter.CONTAINS` + * - `uiGridConstants.filter.GREATER_THAN` + * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL` + * - `uiGridConstants.filter.LESS_THAN` + * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL` + * - `uiGridConstants.filter.NOT_EQUAL` + * + * + * Available `type` options are: + * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field + * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field + */ + filter: { + STARTS_WITH: 2, + ENDS_WITH: 4, + EXACT: 8, + CONTAINS: 16, + GREATER_THAN: 32, + GREATER_THAN_OR_EQUAL: 64, + LESS_THAN: 128, + LESS_THAN_OR_EQUAL: 256, + NOT_EQUAL: 512, + SELECT: 'select', + INPUT: 'input' + }, + + /** + * @ngdoc object + * @name aggregationTypes + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType} + * to specify the type of built-in aggregation the column should use. + * + * Available options are: + * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value + * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value + * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value + */ + aggregationTypes: { + sum: 2, + count: 4, + avg: 8, + min: 16, + max: 32 + }, + + /** + * @ngdoc array + * @name CURRENCY_SYMBOLS + * @propertyOf ui.grid.service:uiGridConstants + * @description A list of all presently circulating currency symbols that was copied from + * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols + * + * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols. + */ + CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден', + 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu', + 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв', + 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q', + 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/', + 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'], + + /** + * @ngdoc object + * @name scrollDirection + * @propertyOf ui.grid.service:uiGridConstants + * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection}, + * to indicate the direction the grid is currently scrolling in + * + * Available options are: + * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up + * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down + * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left + * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right + * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default + */ + scrollDirection: { + UP: 'up', + DOWN: 'down', + LEFT: 'left', + RIGHT: 'right', + NONE: 'none' + + }, + + /** + * @ngdoc object + * @name dataChange + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange}, + * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks}, + * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback} + * to specify the type of the event(s). + * + * Available options are: + * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events. + * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited + * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed + * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified + * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified + */ + dataChange: { + ALL: 'all', + EDIT: 'edit', + ROW: 'row', + COLUMN: 'column', + OPTIONS: 'options' + }, + + /** + * @ngdoc object + * @name scrollbars + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar} + * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar} + * to specify the scrollbar policy for that direction. + * + * Available options are: + * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction + * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction + * - `uiGridConstants.scrollbars.WHEN_NEEDED` - shows scrollbars in this direction when needed + */ + + scrollbars: { + NEVER: 0, + ALWAYS: 1, + WHEN_NEEDED: 2 + } + }); + +})(); + +angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) { + return { + priority: 0, + scope: false, + require: '?^uiGrid', + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + function compileTemplate() { + var compiledElementFn = $scope.col.compiledElementFn; + + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + } + + // If the grid controller is present, use it to get the compiled cell template function + if (uiGridCtrl && $scope.col.compiledElementFn) { + compileTemplate(); + } + + // No controller, compile the element manually (for unit tests) + else { + if ( uiGridCtrl && !$scope.col.compiledElementFn ) { + $scope.col.getCompiledElementFn() + .then(function (compiledElementFn) { + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + }).catch(angular.noop); + } + else { + var html = $scope.col.cellTemplate + .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field)) + .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + var cellElement = $compile(html)($scope); + $elm.append(cellElement); + } + } + }, + post: function($scope, $elm) { + var initColClass = $scope.col.getColClass(false), + classAdded; + + $elm.addClass(initColClass); + + function updateClass( grid ) { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.cellClass)) { + classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.cellClass; + } + contents.addClass(classAdded); + } + + if ($scope.col.cellClass) { + updateClass(); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]); + + // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise + // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things + function cellChangeFunction( n, o ) { + if ( n !== o ) { + if ( classAdded || $scope.col.cellClass ) { + updateClass(); + } + + // See if the column's internal class has changed + var newColClass = $scope.col.getColClass(false); + + if (newColClass !== initColClass) { + $elm.removeClass(initColClass); + $elm.addClass(newColClass); + initColClass = newColClass; + } + } + } + + // TODO(c0bra): Turn this into a deep array watch + var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction ); + + function deregisterFunction() { + dataChangeDereg(); + rowWatchDereg(); + } + + $scope.$on('$destroy', deregisterFunction); + $elm.on('$destroy', deregisterFunction); + } + }; + } + }; +}]); + +(function() { + +angular.module('ui.grid') +.service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil', +function ( i18nService, uiGridConstants, gridUtil ) { +/** + * @ngdoc service + * @name ui.grid.service:uiGridColumnMenuService + * + * @description Services for working with column menus, factored out + * to make the code easier to understand + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name initialize + * @description Sets defaults, puts a reference to the $scope on + * the uiGridController + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {controller} uiGridCtrl the uiGridController for the grid + * we're on + * + */ + initialize: function( $scope, uiGridCtrl ) { + $scope.grid = uiGridCtrl.grid; + + // Store a reference to this link/controller in the main uiGrid controller + // to allow showMenu later + uiGridCtrl.columnMenuScope = $scope; + + // Save whether we're shown or not so the columns can check + $scope.menuShown = false; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name setColMenuItemWatch + * @description Setup a watch on $scope.col.menuItems, and update + * menuItems based on this. $scope.col needs to be set by the column + * before calling the menu. + * @param {$scope} $scope the $scope from the uiGridColumnMenu + */ + setColMenuItemWatch: function ( $scope ) { + var deregFunction = $scope.$watch('col.menuItems', function (n) { + if (typeof(n) !== 'undefined' && n && angular.isArray(n)) { + n.forEach(function (item) { + if (typeof(item.context) === 'undefined' || !item.context) { + item.context = {}; + } + item.context.col = $scope.col; + }); + + $scope.menuItems = $scope.defaultMenuItems.concat(n); + } + else { + $scope.menuItems = $scope.defaultMenuItems; + } + }); + + $scope.$on( '$destroy', deregFunction ); + }, + + getGridOption: function( $scope, option ) { + return typeof($scope.grid) !== 'undefined' && $scope.grid && $scope.grid.options && $scope.grid.options[option]; + }, + + /** + * @ngdoc boolean + * @name enableSorting + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When enabled, this setting adds sort + * widgets to the column header, allowing sorting of the data in the individual column. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name sortable + * @description determines whether this column is sortable + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + sortable: function( $scope ) { + return Boolean( this.getGridOption($scope, 'enableSorting') && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name isActiveSort + * @description determines whether the requested sort direction is current active, to + * allow highlighting in the menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {string} direction the direction that we'd have selected for us to be active + * + */ + isActiveSort: function( $scope, direction ) { + return Boolean(typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name suppressRemoveSort + * @description determines whether we should suppress the removeSort option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + suppressRemoveSort: function( $scope ) { + return Boolean($scope.col && $scope.col.suppressRemoveSort); + }, + + + /** + * @ngdoc boolean + * @name enableHiding + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column + * using the column menu or the grid menu. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name hideable + * @description determines whether a column can be hidden, by checking the enableHiding columnDef option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + hideable: function( $scope ) { + return Boolean( + (this.getGridOption($scope, 'enableHiding') && + typeof($scope.col) !== 'undefined' && $scope.col && + ($scope.col.colDef && $scope.col.colDef.enableHiding !== false || !$scope.col.colDef)) || + (!this.getGridOption($scope, 'enableHiding') && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding) + ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getDefaultMenuItems + * @description returns the default menu items for a column menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + getDefaultMenuItems: function( $scope ) { + return [ + { + title: function() {return i18nService.getSafeText('sort.ascending');}, + icon: 'ui-grid-icon-sort-alt-up', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.ASC); + }, + shown: function () { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.ASC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.descending');}, + icon: 'ui-grid-icon-sort-alt-down', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.DESC); + }, + shown: function() { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.DESC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.remove');}, + icon: 'ui-grid-icon-cancel', + action: function ($event) { + $event.stopPropagation(); + $scope.unsortColumn(); + }, + shown: function() { + return service.sortable( $scope ) && + typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null && + !service.suppressRemoveSort( $scope ); + } + }, + { + title: function() {return i18nService.getSafeText('column.hide');}, + icon: 'ui-grid-icon-cancel', + shown: function() { + return service.hideable( $scope ); + }, + action: function ($event) { + $event.stopPropagation(); + $scope.hideColumn(); + } + } + ]; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getColumnElementPosition + * @description gets the position information needed to place the column + * menu below the column header + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + * @returns {hash} containing left, top, offset, height, width + * + */ + getColumnElementPosition: function( $scope, column, $columnElement ) { + var positionData = {}; + + positionData.left = $columnElement[0].offsetLeft; + positionData.top = $columnElement[0].offsetTop; + positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft; + + // Get the grid scrollLeft + positionData.offset = 0; + if (column.grid.options.offsetLeft) { + positionData.offset = column.grid.options.offsetLeft; + } + + positionData.height = gridUtil.elementHeight($columnElement, true); + positionData.width = gridUtil.elementWidth($columnElement, true); + + return positionData; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name repositionMenu + * @description Reposition the menu below the new column. If the menu has no child nodes + * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again + * later to fix it + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {hash} positionData a hash containing left, top, offset, height, width + * @param {element} $elm the column menu element that we want to reposition + * @param {element} $columnElement the column element that we want to reposition underneath + * + */ + repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) { + var menu = $elm[0].querySelectorAll('.ui-grid-menu'); + + // It's possible that the render container of the column we're attaching to is + // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft + // between the render container and the grid + var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container'), + renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left, + containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft; + + // repositionMenu is now always called after it's visible in the DOM, + // allowing us to simply get the width every time the menu is opened + var myWidth = gridUtil.elementWidth(menu, true), + paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10); + + if ( menu.length !== 0 ) { + var mid = menu[0].querySelectorAll('.ui-grid-menu-mid'); + + if ( mid.length !== 0 ) { + // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side + // Get the column menu right padding + paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10); + $scope.lastMenuPaddingRight = paddingRight; + column.lastMenuPaddingRight = paddingRight; + } + } + + var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight; + + if (left < positionData.offset + myWidth) { + left = Math.max(positionData.left - containerScrollLeft + positionData.parentLeft - paddingRight + myWidth, positionData.offset + myWidth); + } + + $elm.css('left', left + 'px'); + $elm.css('top', (positionData.top + positionData.height) + 'px'); + } + }; + return service; +}]) + + +.directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document', +function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) { +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridColumnMenu + * @description Provides the column menu framework, leverages uiGridMenu underneath + * + */ + + return { + priority: 0, + scope: true, + require: '^uiGrid', + templateUrl: 'ui-grid/uiGridColumnMenu', + replace: true, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridColumnMenuService.initialize( $scope, uiGridCtrl ); + + $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope ); + + // Set the menu items for use with the column menu. The user can later add additional items via the watch + $scope.menuItems = $scope.defaultMenuItems; + uiGridColumnMenuService.setColMenuItemWatch( $scope ); + + function updateCurrentColStatus(menuShown) { + if ($scope.col) { + $scope.col.menuShown = menuShown; + } + } + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name showMenu + * @description Shows the column menu. If the menu is already displayed it + * calls the menu to ask it to hide (it will animate), then it repositions the menu + * to the right place whilst hidden (it will make an assumption on menu width), + * then it asks the menu to show (it will animate), then it repositions the menu again + * once we can calculate it's size. + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + */ + $scope.showMenu = function(column, $columnElement, event) { + // Update the menu status for the current column + updateCurrentColStatus(false); + // Swap to this column + $scope.col = column; + updateCurrentColStatus(true); + + // Get the position information for the column element + var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement ); + + if ($scope.menuShown) { + // we want to hide, then reposition, then show, but we want to wait for animations + // we set a variable, and then rely on the menu-hidden event to call the reposition and show + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.hideThenShow = true; + + $scope.$broadcast('hide-menu', { originalEvent: event }); + } else { + $scope.menuShown = true; + + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.$broadcast('show-menu', { originalEvent: event }); + } + }; + + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name hideMenu + * @description Hides the column menu. + * @param {boolean} broadcastTrigger true if we were triggered by a broadcast + * from the menu itself - in which case don't broadcast again as we'll get + * an infinite loop + */ + $scope.hideMenu = function( broadcastTrigger ) { + $scope.menuShown = false; + updateCurrentColStatus(false); + if ( !broadcastTrigger ) { + $scope.$broadcast('hide-menu'); + } + }; + + + $scope.$on('menu-hidden', function() { + var menuItems = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0]; + + $elm[0].removeAttribute('style'); + + if ( $scope.hideThenShow ) { + delete $scope.hideThenShow; + + $scope.$broadcast('show-menu'); + + $scope.menuShown = true; + } else { + $scope.hideMenu( true ); + + if ($scope.col && $scope.col.visible) { + // Focus on the menu button + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false) + .catch(angular.noop); + } + } + + if (menuItems) { + menuItems.onkeydown = null; + angular.forEach(menuItems.children, function removeHandlers(item) { + item.onkeydown = null; + }); + } + }); + + $scope.$on('menu-shown', function() { + $timeout(function() { + uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); + + var hasVisibleMenuItems = $scope.menuItems.some(function (menuItem) { + return menuItem.shown(); + }); + + // automatically set the focus to the first button element in the now open menu. + if (hasVisibleMenuItems) { + gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true) + .catch(angular.noop); + } + + delete $scope.colElementPosition; + delete $scope.columnElement; + addKeydownHandlersToMenu(); + }); + }); + + + /* Column methods */ + $scope.sortColumn = function (event, dir) { + event.stopPropagation(); + + $scope.grid.sortColumn($scope.col, dir, true) + .then(function () { + $scope.grid.refresh(); + $scope.hideMenu(); + }).catch(angular.noop); + }; + + $scope.unsortColumn = function () { + $scope.col.unsort(); + + $scope.grid.refresh(); + $scope.hideMenu(); + }; + + function addKeydownHandlersToMenu() { + var menu = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0], + menuItems, + visibleMenuItems = []; + + if (menu) { + menu.onkeydown = function closeMenu(event) { + if (event.keyCode === uiGridConstants.keymap.ESC) { + event.preventDefault(); + $scope.hideMenu(); + } + }; + + menuItems = menu.querySelectorAll('.ui-grid-menu-item:not(.ng-hide)'); + angular.forEach(menuItems, function filterVisibleItems(item) { + if (item.offsetParent !== null) { + this.push(item); + } + }, visibleMenuItems); + + if (visibleMenuItems.length) { + if (visibleMenuItems.length === 1) { + visibleMenuItems[0].onkeydown = function singleItemHandler(event) { + circularFocusHandler(event, true); + }; + } else { + visibleMenuItems[0].onkeydown = function firstItemHandler(event) { + circularFocusHandler(event, false, event.shiftKey, visibleMenuItems.length - 1); + }; + visibleMenuItems[visibleMenuItems.length - 1].onkeydown = function lastItemHandler(event) { + circularFocusHandler(event, false, !event.shiftKey, 0); + }; + } + } + } + + function circularFocusHandler(event, isSingleItem, shiftKeyStatus, index) { + if (event.keyCode === uiGridConstants.keymap.TAB) { + if (isSingleItem) { + event.preventDefault(); + } else if (shiftKeyStatus) { + event.preventDefault(); + visibleMenuItems[index].focus(); + } + } + } + } + + // Since we are hiding this column the default hide action will fail so we need to focus somewhere else. + var setFocusOnHideColumn = function() { + $timeout(function() { + // Get the UID of the first + var focusToGridMenu = function() { + return gridUtil.focus.byId('grid-menu', $scope.grid); + }; + + var thisIndex; + $scope.grid.columns.some(function(element, index) { + if (angular.equals(element, $scope.col)) { + thisIndex = index; + return true; + } + }); + + var previousVisibleCol; + // Try and find the next lower or nearest column to focus on + $scope.grid.columns.some(function(element, index) { + if (!element.visible) { + return false; + } // This columns index is below the current column index + else if ( index < thisIndex) { + previousVisibleCol = element; + } // This elements index is above this column index and we haven't found one that is lower + else if ( index > thisIndex && !previousVisibleCol) { + // This is the next best thing + previousVisibleCol = element; + // We've found one so use it. + return true; + } // We've reached an element with an index above this column and the previousVisibleCol variable has been set + else if (index > thisIndex && previousVisibleCol) { + // We are done. + return true; + } + }); + // If found then focus on it + if (previousVisibleCol) { + var colClass = previousVisibleCol.getColClass(); + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason) { + if (reason !== 'canceled') { // If this is canceled then don't perform the action + // The fallback action is to focus on the grid menu + return focusToGridMenu(); + } + }).catch(angular.noop); + } else { + // Fallback action to focus on the grid menu + focusToGridMenu(); + } + }); + }; + + $scope.hideColumn = function () { + $scope.col.colDef.visible = false; + $scope.col.visible = false; + + $scope.grid.queueGridRefresh(); + $scope.hideMenu(); + $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col ); + + // We are hiding so the default action of focusing on the button that opened this menu will fail. + setFocusOnHideColumn(); + }; + }, + + controller: ['$scope', function ($scope) { + var self = this; + + $scope.$watch('menuItems', function (n) { + self.menuItems = n; + }); + }] + }; +}]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) { + + return { + compile: function() { + return { + pre: function ($scope, $elm) { + $scope.col.updateFilters = function( filterable ) { + $elm.children().remove(); + if ( filterable ) { + var template = $scope.col.filterHeaderTemplate; + if (template === undefined && $scope.col.providedFilterHeaderTemplate !== '') { + if ($scope.col.filterHeaderTemplatePromise) { + $scope.col.filterHeaderTemplatePromise.then(function () { + template = $scope.col.filterHeaderTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + } + }; + + $scope.$on( '$destroy', function() { + delete $scope.col.filterable; + delete $scope.col.updateFilters; + }); + }, + post: function ($scope, $elm) { + $scope.aria = i18nService.getSafeText('headerCell.aria'); + $scope.removeFilter = function(colFilter, index) { + colFilter.term = null; + // Set the focus to the filter input after the action disables the button + gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index); + }; + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile', + function ($timeout, gridUtil, uiGridConstants, $compile) { + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + replace: true, + require: '^uiGrid', + compile: function compile() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.footerCellTemplate; + + if (template === undefined && $scope.col.providedFooterCellTemplate !== '') { + if ($scope.col.footerCellTemplatePromise) { + $scope.col.footerCellTemplatePromise.then(function () { + template = $scope.col.footerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // $elm.addClass($scope.col.getColClass(false)); + $scope.grid = uiGridCtrl.grid; + + var initColClass = $scope.col.getColClass(false); + + $elm.addClass(initColClass); + + // apply any footerCellClass + var classAdded; + + var updateClass = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.footerCellClass)) { + classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.footerCellClass; + } + contents.addClass(classAdded); + }; + + if ($scope.col.footerCellClass) { + updateClass(); + } + + $scope.col.updateAggregationValue(); + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]); + + // listen for visible rows change and update aggregation values + $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); + $scope.grid.api.core.on.rowsRendered( $scope, updateClass ); + $scope.$on( '$destroy', dataChangeDereg ); + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) { + + return { + restrict: 'EA', + replace: true, + // priority: 1000, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function ($elm, $attrs) { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + containerCtrl.footer = $elm; + + var footerTemplate = $scope.grid.options.footerTemplate; + gridUtil.getTemplate(footerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.append(newElm); + + if (containerCtrl) { + // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }).catch(angular.noop); + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-footer link'); + + var grid = uiGridCtrl.grid; + + // Don't animate footer cells + gridUtil.disableAnimations($elm); + + containerCtrl.footer = $elm; + + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }; + } + }; + }]); + +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', + function($templateCache, $compile, uiGridConstants, gridUtil) { + return { + restrict: 'EA', + replace: true, + require: '^uiGrid', + scope: true, + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + $scope.grid = uiGridCtrl.grid; + + var footerTemplate = $scope.grid.options.gridFooterTemplate; + + gridUtil.getTemplate(footerTemplate) + .then(function(contents) { + var template = angular.element(contents), + newElm = $compile(template)($scope); + + $elm.append(newElm); + }).catch(angular.noop); + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', '$rootScope', + function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService, $rootScope) { + // Do stuff after mouse has been down this many ms on the header cell + var mousedownTimeout = 500, + changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa + + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + require: ['^uiGrid', '^uiGridRenderContainer'], + replace: true, + compile: function() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.headerCellTemplate; + if (template === undefined && $scope.col.providedHeaderCellTemplate !== '') { + if ($scope.col.headerCellTemplatePromise) { + $scope.col.headerCellTemplatePromise.then(function () { + template = $scope.col.headerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var renderContainerCtrl = controllers[1]; + + $scope.i18n = { + headerCell: i18nService.getSafeText('headerCell'), + sort: i18nService.getSafeText('sort') + }; + $scope.isSortPriorityVisible = function() { + // show sort priority if column is sorted and there is at least one other sorted column + return $scope.col && $scope.col.sort && angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index) { + return angular.isNumber(element.sort.priority) && element !== $scope.col; + }); + }; + $scope.getSortDirectionAriaLabel = function() { + var col = $scope.col; + // Trying to recreate this sort of thing but it was getting messy having it in the template. + // Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending': 'none')}}. + // {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''} + var label = col.sort && col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort && col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none); + + if ($scope.isSortPriorityVisible()) { + label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1); + } + return label; + }; + + $scope.grid = uiGridCtrl.grid; + + $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId]; + + var initColClass = $scope.col.getColClass(false); + $elm.addClass(initColClass); + + // Hide the menu by default + $scope.menuShown = false; + $scope.col.menuShown = false; + + // Put asc and desc sort directions in scope + $scope.asc = uiGridConstants.ASC; + $scope.desc = uiGridConstants.DESC; + + // Store a reference to menu element + var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); + + + // apply any headerCellClass + var classAdded, + previousMouseX; + + // filter watchers + var filterDeregisters = []; + + + /* + * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart). + * Once we have a down event, we need to work out whether we have a click, a drag, or a + * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so + * we ignore it. A hold would open the menu. + * + * So, on down event, we put in place handlers for move and up events, and a timer. If the + * timer expires before we see a move or up, then we have a long press and hence a column menu open. + * If the up happens before the timer, then we have a click, and we sort if the column is sortable. + * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature + * will handle it. + * + * To deal with touch enabled devices that also have mice, we only create our handlers when + * we get the down event, and we create the corresponding handlers - if we're touchstart then + * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup. + * + * We also suppress the click action whilst this is happening - otherwise after the mouseup there + * will be a click event and that can cause the column menu to close + * + */ + $scope.downFn = function( event ) { + event.stopPropagation(); + + if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { + event = event.originalEvent; + } + + // Don't show the menu if it's not the left button + if (event.button && event.button !== 0) { + return; + } + previousMouseX = event.pageX; + + $scope.mousedownStartTime = (new Date()).getTime(); + $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout); + + $scope.mousedownTimeout.then(function () { + if ( $scope.colMenu ) { + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); + } + }).catch(angular.noop); + + uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name}); + + $scope.offAllEvents(); + if ( event.type === 'touchstart') { + $document.on('touchend', $scope.upFn); + $document.on('touchmove', $scope.moveFn); + } else if ( event.type === 'mousedown' ) { + $document.on('mouseup', $scope.upFn); + $document.on('mousemove', $scope.moveFn); + } + }; + + $scope.upFn = function( event ) { + event.stopPropagation(); + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + + var mousedownEndTime = (new Date()).getTime(); + var mousedownTime = mousedownEndTime - $scope.mousedownStartTime; + + if (mousedownTime > mousedownTimeout) { + // long click, handled above with mousedown + } + else { + // short click + if ( $scope.sortable ) { + $scope.handleClick(event); + } + } + }; + + $scope.handleKeyDown = function(event) { + if (event.keyCode === 32 || event.keyCode === 13) { + event.preventDefault(); + $scope.handleClick(event); + } + }; + + $scope.moveFn = function( event ) { + // Chrome is known to fire some bogus move events. + var changeValue = event.pageX - previousMouseX; + if ( changeValue === 0 ) { return; } + + // we're a move, so do nothing and leave for column move (if enabled) to take over + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + }; + + $scope.clickFn = function ( event ) { + event.stopPropagation(); + $contentsElm.off('click', $scope.clickFn); + }; + + + $scope.offAllEvents = function() { + $contentsElm.off('touchstart', $scope.downFn); + $contentsElm.off('mousedown', $scope.downFn); + + $document.off('touchend', $scope.upFn); + $document.off('mouseup', $scope.upFn); + + $document.off('touchmove', $scope.moveFn); + $document.off('mousemove', $scope.moveFn); + + $contentsElm.off('click', $scope.clickFn); + }; + + $scope.onDownEvents = function( type ) { + // If there is a previous event, then wait a while before + // activating the other mode - i.e. if the last event was a touch event then + // don't enable mouse events for a wee while (500ms or so) + // Avoids problems with devices that emulate mouse events when you have touch events + + switch (type) { + case 'touchmove': + case 'touchend': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $timeout(function() { + $contentsElm.on('mousedown', $scope.downFn); + }, changeModeTimeout); + break; + case 'mousemove': + case 'mouseup': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('mousedown', $scope.downFn); + $timeout(function() { + $contentsElm.on('touchstart', $scope.downFn); + }, changeModeTimeout); + break; + default: + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $contentsElm.on('mousedown', $scope.downFn); + } + }; + + var setFilter = function (updateFilters) { + if ( updateFilters ) { + if ( typeof($scope.col.updateFilters) !== 'undefined' ) { + $scope.col.updateFilters($scope.col.filterable); + } + + // if column is filterable add a filter watcher + if ($scope.col.filterable) { + $scope.col.filters.forEach( function(filter, i) { + filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { + if (n !== o) { + uiGridCtrl.grid.api.core.raise.filterChanged( $scope.col ); + uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + uiGridCtrl.grid.queueGridRefresh(); + } + })); + }); + $scope.$on('$destroy', function() { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + }); + } else { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + } + } + }; + + var updateHeaderOptions = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.headerCellClass)) { + classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.headerCellClass; + } + contents.addClass(classAdded); + + $scope.$applyAsync(function() { + var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ? + $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body']; + $scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu && + $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ]; + }); + + // Figure out whether this column is sortable or not + $scope.sortable = Boolean($scope.col.enableSorting); + + // Figure out whether this column is filterable or not + var oldFilterable = $scope.col.filterable; + $scope.col.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); + + setFilter(oldFilterable !== $scope.col.filterable); + + // figure out whether we support column menus + $scope.colMenu = ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && + $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false); + + /** + * @ngdoc property + * @name enableColumnMenu + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description if column menus are enabled, controls the column menus for this specific + * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus + * using this option. If gridOptions.enableColumnMenus === false then you get no column + * menus irrespective of the value of this option ). Defaults to true. + * + * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS: + * + *
    +               *  .ui-grid-column-menu-button {
    +               *    display: block;
    +               *  }
    +               * 
    + */ + /** + * @ngdoc property + * @name enableColumnMenus + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description Override for column menus everywhere - if set to false then you get no + * column menus. Defaults to true. + * + */ + + $scope.offAllEvents(); + + if ($scope.sortable || $scope.colMenu) { + $scope.onDownEvents(); + + $scope.$on('$destroy', function () { + $scope.offAllEvents(); + }); + } + }; + + updateHeaderOptions(); + + if ($scope.col.filterContainer === 'columnMenu' && $scope.col.filterable) { + $rootScope.$on('menu-shown', function() { + $scope.$applyAsync(function () { + setFilter($scope.col.filterable); + }); + }); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]); + + $scope.$on( '$destroy', dataChangeDereg ); + + $scope.handleClick = function(event) { + // If the shift key is being held down, add this column to the sort + // Sort this column then rebuild the grid's rows + uiGridCtrl.grid.sortColumn($scope.col, event.shiftKey) + .then(function () { + if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); } + uiGridCtrl.grid.refresh(); + }).catch(angular.noop); + }; + + $scope.headerCellArrowKeyDown = function(event) { + if (event.keyCode === uiGridConstants.keymap.SPACE || event.keyCode === uiGridConstants.keymap.ENTER) { + event.preventDefault(); + $scope.toggleMenu(event); + } + }; + + $scope.toggleMenu = function(event) { + event.stopPropagation(); + + // If the menu is already showing and we're the column the menu is on + if (uiGridCtrl.columnMenuScope.menuShown && uiGridCtrl.columnMenuScope.col === $scope.col) { + // ... hide it + uiGridCtrl.columnMenuScope.hideMenu(); + } + // If the menu is NOT showing or is showing in a different column + else { + // ... show it on our column + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm); + } + }; + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent', + function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) { + var defaultTemplate = 'ui-grid/ui-grid-header', + emptyTemplate = 'ui-grid/ui-grid-no-header'; + + return { + restrict: 'EA', + replace: true, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function() { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + updateHeaderReferences(); + + var headerTemplate; + if (!$scope.grid.options.showHeader) { + headerTemplate = emptyTemplate; + } + else { + headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate; + } + + gridUtil.getTemplate(headerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.replaceWith(newElm); + + // And update $elm to be the new element + $elm = newElm; + + updateHeaderReferences(); + + if (containerCtrl) { + // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + + + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + angular.element(headerViewport).on('scroll', scrollHandler); + $scope.$on('$destroy', function () { + angular.element(headerViewport).off('scroll', scrollHandler); + }); + } + } + + $scope.grid.queueRefresh(); + }).catch(angular.noop); + + function updateHeaderReferences() { + containerCtrl.header = containerCtrl.colContainer.header = $elm; + + var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas'); + + if (headerCanvases.length > 0) { + containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0]; + } + else { + containerCtrl.headerCanvas = null; + } + } + + function scrollHandler() { + if (uiGridCtrl.grid.isScrollingHorizontally) { + return; + } + var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid); + var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + uiGridCtrl.grid.scrollContainers(null, scrollEvent); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-header link'); + + var grid = uiGridCtrl.grid; + + // Don't animate header cells + gridUtil.disableAnimations($elm); + + function updateColumnWidths() { + // this styleBuilder always runs after the renderContainer, so we can rely on the column widths + // already being populated correctly + + var columnCache = containerCtrl.colContainer.visibleColumnCache; + + // Build the CSS + // uiGridCtrl.grid.columns.forEach(function (column) { + var ret = ''; + var canvasWidth = 0; + columnCache.forEach(function (column) { + ret = ret + column.getColClassDefinition(); + canvasWidth += column.drawnWidth; + }); + + containerCtrl.colContainer.canvasWidth = canvasWidth; + + // Return the styles back to buildStyles which pops them into the `customStyles` scope variable + return ret; + } + + containerCtrl.header = $elm; + + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + } + + // todo: remove this if by injecting gridCtrl into unit tests + if (uiGridCtrl) { + uiGridCtrl.grid.registerStyleComputation({ + priority: 15, + func: updateColumnWidths + }); + } + } + }; + } + }; + }]); +})(); + +(function() { + +angular.module('ui.grid') +.service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) { + /** + * @ngdoc service + * @name ui.grid.uiGridGridMenuService + * + * @description Methods for working with the grid menu + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name initialize + * @description Sets up the gridMenu. Most importantly, sets our + * scope onto the grid object as grid.gridMenuScope, allowing us + * to operate when passed only the grid. Second most importantly, + * we register the 'addToGridMenu' and 'removeFromGridMenu' methods + * on the core api. + * @param {$scope} $scope the scope of this gridMenu + * @param {Grid} grid the grid to which this gridMenu is associated + */ + initialize: function( $scope, grid ) { + grid.gridMenuScope = $scope; + $scope.grid = grid; + $scope.registeredMenuItems = []; + + // not certain this is needed, but would be bad to create a memory leak + $scope.$on('$destroy', function() { + if ( $scope.grid && $scope.grid.gridMenuScope ) { + $scope.grid.gridMenuScope = null; + } + if ( $scope.grid ) { + $scope.grid = null; + } + if ( $scope.registeredMenuItems ) { + $scope.registeredMenuItems = null; + } + }); + + $scope.registeredMenuItems = []; + + /** + * @ngdoc function + * @name addToGridMenu + * @methodOf ui.grid.api:PublicApi + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} items menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu ); + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.api:PublicApi + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu ); + }, + + + /** + * @ngdoc function + * @name addToGridMenu + * @propertyOf ui.grid.uiGridGridMenuService + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} menuItems menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + addToGridMenu: function( grid, menuItems ) { + if ( !angular.isArray( menuItems ) ) { + gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items'); + } else { + if ( grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : []; + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems ); + } else { + gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid'); + } + } + }, + + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.uiGridGridMenuService + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found. If there is no gridMenuScope or registeredMenuItems + * then do nothing silently - the desired result is those menu items not be present and they + * aren't. + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + removeFromGridMenu: function( grid, id ) { + var foundIndex = -1; + + if ( grid && grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) { + if ( value.id === id ) { + if (foundIndex > -1) { + gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' ); + } else { + + foundIndex = index; + } + } + }); + } + + if ( foundIndex > -1 ) { + grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 ); + } + }, + + + /** + * @ngdoc array + * @name gridMenuCustomItems + * @propertyOf ui.grid.class:GridOptions + * @description (optional) An array of menu items that should be added to + * the gridMenu. Follow the format documented in the tutorial for column + * menu customisation. The context provided to the action function will + * include context.grid. An alternative if working with dynamic menus is to use the + * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles + * some of the management of items for you. + * + */ + /** + * @ngdoc boolean + * @name gridMenuShowHideColumns + * @propertyOf ui.grid.class:GridOptions + * @description true by default, whether the grid menu should allow hide/show + * of columns + * + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name getMenuItems + * @description Decides the menu items to show in the menu. This is a + * combination of: + * + * - the default menu items that are always included, + * - any menu items that have been provided through the addMenuItem api. These + * are typically added by features within the grid + * - any menu items included in grid.options.gridMenuCustomItems. These can be + * changed dynamically, as they're always recalculated whenever we show the + * menu + * @param {$scope} $scope the scope of this gridMenu, from which we can find all + * the information that we need + * @returns {Array} an array of menu items that can be shown + */ + getMenuItems: function( $scope ) { + var menuItems = [ + // this is where we add any menu items we want to always include + ]; + + if ( $scope.grid.options.gridMenuCustomItems ) { + if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ) { + gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not'); + } else { + menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems ); + } + } + + var clearFilters = [{ + title: i18nService.getSafeText('gridMenu.clearAllFilters'), + action: function ($event) { + $scope.grid.clearAllFilters(); + }, + shown: function() { + return $scope.grid.options.enableFiltering; + }, + order: 100 + }]; + menuItems = menuItems.concat( clearFilters ); + + menuItems = menuItems.concat( $scope.registeredMenuItems ); + + if ( $scope.grid.options.gridMenuShowHideColumns !== false ) { + menuItems = menuItems.concat( service.showHideColumns( $scope ) ); + } + + menuItems.sort(function(a, b) { + return a.order - b.order; + }); + + return menuItems; + }, + + + /** + * @ngdoc array + * @name gridMenuTitleFilter + * @propertyOf ui.grid.class:GridOptions + * @description (optional) A function that takes a title string + * (usually the col.displayName), and converts it into a display value. The function + * must return either a string or a promise. + * + * Used for internationalization of the grid menu column names - for angular-translate + * you can pass $translate as the function, for i18nService you can pass getSafeText as the + * function + * @example + *
    +     *   gridOptions = {
    +     *     gridMenuTitleFilter: $translate
    +     *   }
    +     * 
    + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name showHideColumns + * @description Adds two menu items for each of the columns in columnDefs. One + * menu item for hide, one menu item for show. Each is visible when appropriate + * (show when column is not visible, hide when column is visible). Each toggles + * the visible property on the columnDef using toggleColumnVisibility + * @param {$scope} $scope of a gridMenu, which contains a reference to the grid + */ + showHideColumns: function( $scope ) { + var showHideColumns = []; + if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) { + return showHideColumns; + } + + function isColumnVisible(colDef) { + return colDef.visible === true || colDef.visible === undefined; + } + + function getColumnIcon(colDef) { + return isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel'; + } + + $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; }; + + $scope.grid.options.columnDefs.forEach( function( colDef, index ) { + if ( $scope.grid.options.enableHiding !== false && colDef.enableHiding !== false || colDef.enableHiding ) { + // add hide menu item - shows an OK icon as we only show when column is already visible + var menuItem = { + icon: getColumnIcon(colDef), + action: function($event) { + $event.stopPropagation(); + + service.toggleColumnVisibility( this.context.gridCol ); + + if ($event.target && $event.target.firstChild) { + if (angular.element($event.target)[0].nodeName === 'I') { + $event.target.className = getColumnIcon(this.context.gridCol.colDef); + } + else { + $event.target.firstChild.className = getColumnIcon(this.context.gridCol.colDef); + } + } + }, + shown: function() { + return this.context.gridCol.colDef.enableHiding !== false; + }, + context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) }, + leaveOpen: true, + order: 301 + index + }; + service.setMenuItemTitle( menuItem, colDef, $scope.grid ); + showHideColumns.push( menuItem ); + } + }); + + // add header for columns + if ( showHideColumns.length ) { + showHideColumns.unshift({ + title: i18nService.getSafeText('gridMenu.columns'), + order: 300, + templateUrl: 'ui-grid/ui-grid-menu-header-item' + }); + } + + return showHideColumns; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name setMenuItemTitle + * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu + * item if it returns a string, otherwise waiting for the promise to resolve or reject then + * putting the result into the title + * @param {object} menuItem the menuItem we want to put the title on + * @param {object} colDef the colDef from which we can get displayName, name or field + * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter + * + */ + setMenuItemTitle: function( menuItem, colDef, grid ) { + var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field ); + + if ( typeof(title) === 'string' ) { + menuItem.title = title; + } else if ( title.then ) { + // must be a promise + menuItem.title = ""; + title.then( function( successValue ) { + menuItem.title = successValue; + }, function( errorValue ) { + menuItem.title = errorValue; + }).catch(angular.noop); + } else { + gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config'); + menuItem.title = 'badconfig'; + } + }, + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name toggleColumnVisibility + * @description Toggles the visibility of an individual column. Expects to be + * provided a context that has on it a gridColumn, which is the column that + * we'll operate upon. We change the visibility, and refresh the grid as appropriate + * @param {GridColumn} gridCol the column that we want to toggle + * + */ + toggleColumnVisibility: function( gridCol ) { + gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined ); + + gridCol.grid.refresh(); + gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol ); + } + }; + + return service; +}]) + +.directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService', +function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) { + + return { + priority: 0, + scope: true, + require: ['^uiGrid'], + templateUrl: 'ui-grid/ui-grid-menu-button', + replace: true, + + link: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + + // For the aria label + $scope.i18n = { + aria: i18nService.getSafeText('gridMenu.aria') + }; + + uiGridGridMenuService.initialize($scope, uiGridCtrl.grid); + + $scope.shown = false; + + $scope.toggleOnKeydown = function(event) { + if ( + event.keyCode === uiGridConstants.keymap.ENTER || + event.keyCode === uiGridConstants.keymap.SPACE || + (event.keyCode === uiGridConstants.keymap.ESC && $scope.shown) + ) { + $scope.toggleMenu(); + } + }; + + $scope.toggleMenu = function () { + if ( $scope.shown ) { + $scope.$broadcast('hide-menu'); + $scope.shown = false; + } else { + $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope ); + $scope.$broadcast('show-menu'); + $scope.shown = true; + } + }; + + $scope.$on('menu-hidden', function() { + $scope.shown = false; + gridUtil.focus.bySelector($elm, '.ui-grid-icon-container'); + }); + } + }; +}]); +})(); + +(function() { + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridMenu + * @element style + * @restrict A + * + * @description + * Allows us to interpolate expressions in ` + I am in a box. +
    + + + xit('should apply the right class to the element', function () { + element(by.css('.blah')).getCssValue('border-top-width') + .then(function(c) { + expect(c).toContain('1px'); + }); + }); + + + */ + + + angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) { + return { + link: function($scope, $elm) { + var interpolateFn = $interpolate($elm.text(), true); + + if (interpolateFn) { + $scope.$watch(interpolateFn, function(value) { + $elm.text(value); + }); + } + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridViewport', ['gridUtil', 'ScrollEvent', + function(gridUtil, ScrollEvent) { + return { + replace: true, + scope: {}, + controllerAs: 'Viewport', + templateUrl: 'ui-grid/uiGridViewport', + require: ['^uiGrid', '^uiGridRenderContainer'], + link: function($scope, $elm, $attrs, controllers) { + // gridUtil.logDebug('viewport post-link'); + + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.containerCtrl = containerCtrl; + + var rowContainer = containerCtrl.rowContainer; + var colContainer = containerCtrl.colContainer; + + var grid = uiGridCtrl.grid; + + $scope.grid = uiGridCtrl.grid; + + // Put the containers in scope so we can get rows and columns from them + $scope.rowContainer = containerCtrl.rowContainer; + $scope.colContainer = containerCtrl.colContainer; + + // Register this viewport with its container + containerCtrl.viewport = $elm; + + /** + * @ngdoc function + * @name customScroller + * @methodOf ui.grid.class:GridOptions + * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default. + * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers + * as this allows you to do that. + * + * + *
    Example
    + *
    +           *   $scope.gridOptions = {
    +           *       customScroller: function myScrolling(uiGridViewport, scrollHandler) {
    +           *           uiGridViewport.on('scroll', function myScrollingOverride(event) {
    +           *               // Do something here
    +           *
    +           *               scrollHandler(event);
    +           *           });
    +           *       }
    +           *   };
    +           * 
    + * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid). + * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid). + */ + if (grid && grid.options && grid.options.customScroller) { + grid.options.customScroller($elm, scrollHandler); + } else { + $elm.on('scroll', scrollHandler); + } + + var ignoreScroll = false; + + function scrollHandler() { + var newScrollTop = $elm[0].scrollTop; + var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid); + + var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop); + var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + scrollEvent.newScrollTop = newScrollTop; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + if ( vertScrollPercentage > -1 ) { + scrollEvent.y = { percentage: vertScrollPercentage }; + } + + grid.scrollContainers($scope.$parent.containerId, scrollEvent); + } + + if ($scope.$parent.bindScrollVertical) { + grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll); + } + + if ($scope.$parent.bindScrollHorizontal) { + grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter); + } + + function syncVerticalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + $elm[0].scrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport); + } + + function syncHorizontalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + + function syncHorizontalHeader(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.headerViewport) { + containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + function syncHorizontalFooter(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.footerViewport) { + containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); + }, + controller: ['$scope', function ($scope) { + this.rowStyle = function () { + var rowContainer = $scope.rowContainer; + var colContainer = $scope.colContainer; + + var styles = {}; + + if (rowContainer.currentTopRow !== 0) { + // top offset based on hidden rows count + var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)"; + + styles['transform'] = translateY; + styles['-webkit-transform'] = translateY; + styles['-ms-transform'] = translateY; + } + + if (colContainer.currentFirstColumn !== 0) { + if (colContainer.grid.isRTL()) { + styles['margin-right'] = colContainer.columnOffset + 'px'; + } + else { + styles['margin-left'] = colContainer.columnOffset + 'px'; + } + } + + return styles; + }; + }] + }; + } + ]); + +})(); + +(function() { + angular.module('ui.grid') + .directive('uiGridVisible', function uiGridVisibleAction() { + return function($scope, $elm, $attr) { + $scope.$watch($attr.uiGridVisible, function(visible) { + $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible'); + }); + }; + }); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants', + 'gridClassFactory', '$parse', '$compile', + function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants, + gridClassFactory, $parse, $compile) { + // gridUtil.logDebug('ui-grid controller'); + var self = this; + var deregFunctions = []; + + self.grid = gridClassFactory.createGrid($scope.uiGrid); + + // assign $scope.$parent if appScope not already assigned + self.grid.appScope = self.grid.appScope || $scope.$parent; + + $elm.addClass('grid' + self.grid.id); + self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl'; + + + // angular.extend(self.grid.options, ); + + // all properties of grid are available on scope + $scope.grid = self.grid; + + if ($attrs.uiGridColumns) { + deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) { + self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value; + self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + + self.grid.refreshCanvas(true); + }).catch(angular.noop); + }) ); + } + + // prevents an error from being thrown when the array is not defined yet and fastWatch is on + function getSize(array) { + return array ? array.length : 0; + } + + // if fastWatch is set we watch only the length and the reference, not every individual object + if (self.grid.options.fastWatch) { + self.uiGrid = $scope.uiGrid; + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { + if ( self.grid.appScope[$scope.uiGrid.data] ) { + return self.grid.appScope[$scope.uiGrid.data].length; + } else { + return undefined; + } + }, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function() { dataWatchFunction($scope.uiGrid.data); }) ); + } + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function() { columnDefsWatchFunction($scope.uiGrid.columnDefs); }) ); + } else { + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + } + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + } + + + function columnDefsWatchFunction(n, o) { + if (n && n !== o) { + self.grid.options.columnDefs = $scope.uiGrid.columnDefs; + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, { + orderByColumnDefs: true, + preCompileCellTemplates: true + }); + } + } + + var mostRecentData; + + function dataWatchFunction(newData) { + // gridUtil.logDebug('dataWatch fired'); + var promises = []; + + if ( self.grid.options.fastWatch ) { + if (angular.isString($scope.uiGrid.data)) { + newData = self.grid.appScope.$eval($scope.uiGrid.data); + } else { + newData = $scope.uiGrid.data; + } + } + + mostRecentData = newData; + + if (newData) { + // columns length is greater than the number of row header columns, which don't count because they're created automatically + var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0); + + if ( + // If we have no columns + !hasColumns && + // ... and we don't have a ui-grid-columns attribute, which would define columns for us + !$attrs.uiGridColumns && + // ... and we have no pre-defined columns + self.grid.options.columnDefs.length === 0 && + // ... but we DO have data + newData.length > 0 + ) { + // ... then build the column definitions from the data that we have + self.grid.buildColumnDefsFromData(newData); + } + + // If we haven't built columns before and either have some columns defined or some data defined + if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) { + // Build the column set, then pre-compile the column cell templates + promises.push(self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + }).catch(angular.noop)); + } + + $q.all(promises).then(function() { + // use most recent data, rather than the potentially outdated data passed into watcher handler + self.grid.modifyRows(mostRecentData) + .then(function () { + // if (self.viewport) { + self.grid.redrawInPlace(true); + // } + + $scope.$evalAsync(function() { + self.grid.refreshCanvas(true); + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW); + }); + }).catch(angular.noop); + }).catch(angular.noop); + } + } + + var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() { + self.grid.refreshCanvas(true); + }); + + $scope.$on('$destroy', function() { + deregFunctions.forEach( function( deregFn ) { deregFn(); }); + styleWatchDereg(); + }); + + self.fireEvent = function(eventName, args) { + args = args || {}; + + // Add the grid to the event arguments if it's not there + if (angular.isUndefined(args.grid)) { + args.grid = self.grid; + } + + $scope.$broadcast(eventName, args); + }; + + self.innerCompile = function innerCompile(elm) { + $compile(elm)($scope); + }; + }]); + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGrid + * @element div + * @restrict EA + * @param {Object} uiGrid Options for the grid to use + * + * @description Create a very basic grid. + * + * @example + + + var app = angular.module('app', ['ui.grid']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + }]); + + +
    +
    +
    +
    +
    + */ +angular.module('ui.grid').directive('uiGrid', uiGridDirective); + +uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants']; +function uiGridDirective($window, gridUtil, uiGridConstants) { + return { + templateUrl: 'ui-grid/ui-grid', + scope: { + uiGrid: '=' + }, + replace: true, + transclude: true, + controller: 'uiGridController', + compile: function () { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + // Initialize scrollbars (TODO: move to controller??) + uiGridCtrl.scrollbars = []; + grid.element = $elm; + + + // See if the grid has a rendered width, if not, wait a bit and try again + var sizeCheckInterval = 100; // ms + var maxSizeChecks = 20; // 2 seconds total + var sizeChecks = 0; + + // Setup (event listeners) the grid + setup(); + + // And initialize it + init(); + + // Mark rendering complete so API events can happen + grid.renderingComplete(); + + // If the grid doesn't have size currently, wait for a bit to see if it gets size + checkSize(); + + /*-- Methods --*/ + + function checkSize() { + // If the grid has no width and we haven't checked more than times, check again in milliseconds + if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) { + setTimeout(checkSize, sizeCheckInterval); + sizeChecks++; + } else { + $scope.$applyAsync(init); + } + } + + // Setup event listeners and watchers + function setup() { + var deregisterLeftWatcher, deregisterRightWatcher; + + // Bind to window resize events + angular.element($window).on('resize', gridResize); + + // Unbind from window resize events when the grid is destroyed + $elm.on('$destroy', function () { + angular.element($window).off('resize', gridResize); + deregisterLeftWatcher(); + deregisterRightWatcher(); + }); + + // If we add a left container after render, we need to watch and react + deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + + // If we add a right container after render, we need to watch and react + deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + } + + // Initialize the directive + function init() { + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + + // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from + grid.canvasWidth = uiGridCtrl.grid.gridWidth; + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows + if (grid.gridHeight - grid.scrollbarHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) { + autoAdjustHeight(); + } + + // Run initial canvas refresh + grid.refreshCanvas(true); + } + + // Set the grid's height ourselves in the case that its height would be unusably small + function autoAdjustHeight() { + // Figure out the new height + var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight; + var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0; + var footerHeight = grid.calcFooterHeight(); + + var scrollbarHeight = 0; + if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) { + scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + var maxNumberOfFilters = 0; + // Calculates the maximum number of filters in the columns + angular.forEach(grid.options.columnDefs, function(col) { + if (col.hasOwnProperty('filter')) { + if (maxNumberOfFilters < 1) { + maxNumberOfFilters = 1; + } + } + else if (col.hasOwnProperty('filters')) { + if (maxNumberOfFilters < col.filters.length) { + maxNumberOfFilters = col.filters.length; + } + } + }); + + if (grid.options.enableFiltering && !maxNumberOfFilters) { + var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) { + return col.enableFiltering === false; + }); + + if (!allColumnsHaveFilteringTurnedOff) { + maxNumberOfFilters = 1; + } + } + + var filterHeight = maxNumberOfFilters * headerHeight; + + var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight; + + $elm.css('height', newHeight + 'px'); + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + } + + // Resize the grid on window resize events + function gridResize() { + if (!gridUtil.isVisible($elm)) { + return; + } + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + grid.refreshCanvas(true); + } + } + }; + } + }; +} +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) { + return { + restrict: 'EA', + replace: true, + template: '
    ' + + '
    ' + + '
    ', + scope: { + side: '=uiGridPinnedContainer' + }, + require: '^uiGrid', + compile: function compile() { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link'); + + var grid = uiGridCtrl.grid; + + var myWidth = 0; + + $elm.addClass('ui-grid-pinned-container-' + $scope.side); + + // Monkey-patch the viewport width function + if ($scope.side === 'left' || $scope.side === 'right') { + grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth; + } + + function monkeyPatchedGetViewportWidth() { + /*jshint validthis: true */ + var self = this; + + var viewportWidth = 0; + self.visibleColumnCache.forEach(function (column) { + viewportWidth += column.drawnWidth; + }); + + var adjustment = self.getViewportAdjustment(); + + viewportWidth = viewportWidth + adjustment.width; + + return viewportWidth; + } + + function updateContainerWidth() { + if ($scope.side === 'left' || $scope.side === 'right') { + var cols = grid.renderContainers[$scope.side].visibleColumnCache; + var width = 0; + for (var i = 0; i < cols.length; i++) { + var col = cols[i]; + width += col.drawnWidth || col.width || 0; + } + + return width; + } + } + + function updateContainerDimensions() { + var ret = ''; + + // Column containers + if ($scope.side === 'left' || $scope.side === 'right') { + myWidth = updateContainerWidth(); + + // gridUtil.logDebug('myWidth', myWidth); + + // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it + $elm.attr('style', null); + + // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; + + ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } '; + } + + return ret; + } + + grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { + myWidth = updateContainerWidth(); + + // Subtract our own width + adjustment.width -= myWidth; + adjustment.side = $scope.side; + + return adjustment; + }); + + // Register style computation to adjust for columns in `side`'s render container + grid.registerStyleComputation({ + priority: 15, + func: updateContainerDimensions + }); + } + }; + } + }; + }]); +})(); + +(function () { + angular.module('ui.grid').config(['$provide', function($provide) { + $provide.decorator('i18nService', ['$delegate', function($delegate) { + $delegate.add('en', { + headerCell: { + aria: { + defaultFilterLabel: 'Filter for column', + removeFilter: 'Remove Filter', + columnMenuButtonLabel: 'Column Menu', + column: 'Column' + }, + priority: 'Priority:', + filterLabel: "Filter for column: " + }, + aggregate: { + label: 'items' + }, + groupPanel: { + description: 'Drag a column header here and drop it to group by that column.' + }, + search: { + aria: { + selected: 'Row selected', + notSelected: 'Row not selected' + }, + placeholder: 'Search...', + showingItems: 'Showing Items:', + selectedItems: 'Selected Items:', + totalItems: 'Total Items:', + size: 'Page Size:', + first: 'First Page', + next: 'Next Page', + previous: 'Previous Page', + last: 'Last Page' + }, + selection: { + aria: { + row: 'Row' + }, + selectAll: 'Select All', + displayName: 'Row Selection Checkbox' + }, + menu: { + text: 'Choose Columns:' + }, + sort: { + ascending: 'Sort Ascending', + descending: 'Sort Descending', + none: 'Sort None', + remove: 'Remove Sort' + }, + column: { + hide: 'Hide Column' + }, + aggregation: { + count: 'total rows: ', + sum: 'total: ', + avg: 'avg: ', + min: 'min: ', + max: 'max: ' + }, + pinning: { + pinLeft: 'Pin Left', + pinRight: 'Pin Right', + unpin: 'Unpin' + }, + columnMenu: { + close: 'Close' + }, + gridMenu: { + aria: { + buttonLabel: 'Grid Menu' + }, + columns: 'Columns:', + importerTitle: 'Import file', + exporterAllAsCsv: 'Export all data as csv', + exporterVisibleAsCsv: 'Export visible data as csv', + exporterSelectedAsCsv: 'Export selected data as csv', + exporterAllAsPdf: 'Export all data as pdf', + exporterVisibleAsPdf: 'Export visible data as pdf', + exporterSelectedAsPdf: 'Export selected data as pdf', + exporterAllAsExcel: 'Export all data as excel', + exporterVisibleAsExcel: 'Export visible data as excel', + exporterSelectedAsExcel: 'Export selected data as excel', + clearAllFilters: 'Clear all filters' + }, + importer: { + noHeaders: 'Column names were unable to be derived, does the file have a header?', + noObjects: 'Objects were not able to be derived, was there data in the file other than headers?', + invalidCsv: 'File was unable to be processed, is it valid CSV?', + invalidJson: 'File was unable to be processed, is it valid Json?', + jsonNotArray: 'Imported json file must contain an array, aborting.' + }, + pagination: { + aria: { + pageToFirst: 'Page to first', + pageBack: 'Page back', + pageSelected: 'Selected page', + pageForward: 'Page forward', + pageToLast: 'Page to last' + }, + sizes: 'items per page', + totalItems: 'items', + through: 'through', + of: 'of' + }, + grouping: { + group: 'Group', + ungroup: 'Ungroup', + aggregate_count: 'Agg: Count', + aggregate_sum: 'Agg: Sum', + aggregate_max: 'Agg: Max', + aggregate_min: 'Agg: Min', + aggregate_avg: 'Agg: Avg', + aggregate_remove: 'Agg: Remove' + }, + validate: { + error: 'Error:', + minLength: 'Value should be at least THRESHOLD characters long.', + maxLength: 'Value should be at most THRESHOLD characters long.', + required: 'A value is needed.' + } + }); + return $delegate; + }]); + }]); +})(); + +(function() { + +angular.module('ui.grid') +.factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent', + function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) { + + /** + * @ngdoc object + * @name ui.grid.api:PublicApi + * @description Public Api for the core grid features + * + */ + + /** + * @ngdoc function + * @name ui.grid.class:Grid + * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in + * this prototype. One instance of Grid is created per Grid directive instance. + * @param {object} options Object map of options to pass into the grid. An 'id' property is expected. + */ + var Grid = function Grid(options) { + var self = this; + // Get the id out of the options, then remove it + if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) { + if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) { + throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.'); + } + } + else { + throw new Error('No ID provided. An ID must be given when creating a grid.'); + } + + self.id = options.id; + delete options.id; + + // Get default options + self.options = GridOptions.initialize( options ); + + /** + * @ngdoc object + * @name appScope + * @propertyOf ui.grid.class:Grid + * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller + *
    + * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference + */ + self.appScope = self.options.appScopeProvider; + + self.headerHeight = self.options.headerRowHeight; + + + /** + * @ngdoc object + * @name footerHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total footer height gridFooter + columnFooter + */ + self.footerHeight = self.calcFooterHeight(); + + + /** + * @ngdoc object + * @name columnFooterHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total column footer height + */ + self.columnFooterHeight = self.calcColumnFooterHeight(); + + self.rtl = false; + self.gridHeight = 0; + self.gridWidth = 0; + self.columnBuilders = []; + self.rowBuilders = []; + self.rowsProcessors = []; + self.columnsProcessors = []; + self.styleComputations = []; + self.viewportAdjusters = []; + self.rowHeaderColumns = []; + self.dataChangeCallbacks = {}; + self.verticalScrollSyncCallBackFns = {}; + self.horizontalScrollSyncCallBackFns = {}; + + // self.visibleRowCache = []; + + // Set of 'render' containers for self grid, which can render sets of rows + self.renderContainers = {}; + + // Create a + self.renderContainers.body = new GridRenderContainer('body', self); + + self.cellValueGetterCache = {}; + + // Cached function to use with custom row templates + self.getRowTemplateFn = null; + + + // representation of the rows on the grid. + // these are wrapped references to the actual data rows (options.data) + self.rows = []; + + // represents the columns on the grid + self.columns = []; + + /** + * @ngdoc boolean + * @name isScrollingVertically + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling vertically. Set to false via debounced method + */ + self.isScrollingVertically = false; + + /** + * @ngdoc boolean + * @name isScrollingHorizontally + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling horizontally. Set to false via debounced method + */ + self.isScrollingHorizontally = false; + + /** + * @ngdoc property + * @name scrollDirection + * @propertyOf ui.grid.class:Grid + * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection} + * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling. + * Set to NONE via debounced method + */ + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + + // if true, grid will not respond to any scroll events + self.disableScrolling = false; + + + function vertical (scrollEvent) { + self.isScrollingVertically = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce); + var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0); + + function horizontal (scrollEvent) { + self.isScrollingHorizontally = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce); + var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0); + + + /** + * @ngdoc function + * @name flagScrollingVertically + * @methodOf ui.grid.class:Grid + * @description sets isScrollingVertically to true and sets it to false in a debounced function + */ + self.flagScrollingVertically = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingVertically = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedVerticalMinDelay(scrollEvent); + } + else { + debouncedVertical(scrollEvent); + } + }; + + /** + * @ngdoc function + * @name flagScrollingHorizontally + * @methodOf ui.grid.class:Grid + * @description sets isScrollingHorizontally to true and sets it to false in a debounced function + */ + self.flagScrollingHorizontally = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingHorizontally = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedHorizontalMinDelay(scrollEvent); + } + else { + debouncedHorizontal(scrollEvent); + } + }; + + self.scrollbarHeight = 0; + self.scrollbarWidth = 0; + if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarWidth = gridUtil.getScrollbarWidth(); + } + + self.api = new GridApi(self); + + /** + * @ngdoc function + * @name refresh + * @methodOf ui.grid.api:PublicApi + * @description Refresh the rendered grid on screen. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + * If you only want to resize the grid, not regenerate all the rows + * and columns, you should consider directly calling refreshCanvas instead. + * + * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed + */ + self.api.registerMethod( 'core', 'refresh', this.refresh ); + + /** + * @ngdoc function + * @name queueGridRefresh + * @methodOf ui.grid.api:PublicApi + * @description Request a refresh of the rendered grid on screen, if multiple + * calls to queueGridRefresh are made within a digest cycle only one will execute. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + */ + self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh ); + + /** + * @ngdoc function + * @name refreshRows + * @methodOf ui.grid.api:PublicApi + * @description Runs only the rowProcessors, columns remain as they were. + * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'refreshRows', this.refreshRows ); + + /** + * @ngdoc function + * @name queueRefresh + * @methodOf ui.grid.api:PublicApi + * @description Requests execution of refreshCanvas, if multiple requests are made + * during a digest cycle only one will run. RefreshCanvas updates the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh ); + + /** + * @ngdoc function + * @name handleWindowResize + * @methodOf ui.grid.api:PublicApi + * @description Trigger a grid resize, normally this would be picked + * up by a watch on window size, but in some circumstances it is necessary + * to call this manually + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize ); + + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.api:PublicApi + * @description adds a row header column to the grid + * @param {object} column def + * @param {number} order Determines order of header column on grid. Lower order means header + * is positioned to the left of higher order headers + * + */ + self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn ); + + /** + * @ngdoc function + * @name scrollToIfNecessary + * @methodOf ui.grid.api:PublicApi + * @description Scrolls the grid to make a certain row and column combo visible, + * in the case that it is not completely visible on the screen already. + * @param {GridRow} gridRow row to make visible + * @param {GridColumn} gridCol column to make visible + * @returns {promise} a promise that is resolved when scrolling is complete + * + */ + self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} ); + + /** + * @ngdoc function + * @name scrollTo + * @methodOf ui.grid.api:PublicApi + * @description Scroll the grid such that the specified + * row and column is in view + * @param {object} rowEntity gridOptions.data[] array instance to make visible + * @param {object} colDef to make visible + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} ); + + /** + * @ngdoc function + * @name registerRowsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "rows processor" function. When the rows are updated, + * the grid calls each registered "rows processor", which has a chance + * to alter the set of rows (sorting, etc) as long as the count is not + * modified. + * + * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated rows list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier. + * + * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100, + * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor ); + + /** + * @ngdoc function + * @name registerColumnsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "columns processor" function. When the columns are updated, + * the grid calls each registered "columns processor", which has a chance + * to alter the set of columns as long as the count is not + * modified. + * + * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated columns list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier. + * + * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor ); + + /** + * @ngdoc function + * @name sortHandleNulls + * @methodOf ui.grid.api:PublicApi + * @description A null handling method that can be used when building custom sort + * functions + * @example + *
    +     *   mySortFn = function(a, b) {
    +     *   var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
    +     *   if ( nulls !== null ) {
    +     *     return nulls;
    +     *   } else {
    +     *     // your code for sorting here
    +     *   };
    +     * 
    + * @param {object} a sort value a + * @param {object} b sort value b + * @returns {number} null if there were no nulls/undefineds, otherwise returns + * a sort value that should be passed back from the sort function + * + */ + self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls ); + + /** + * @ngdoc function + * @name sortChanged + * @methodOf ui.grid.api:PublicApi + * @description The sort criteria on one or more columns has + * changed. Provides as parameters the grid and the output of + * getColumnSorting, which is an array of gridColumns + * that have sorting on them, sorted in priority order. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of + * columns with sorts on them, in priority order. + * + * @example + *
    +     *      gridApi.core.on.sortChanged( $scope, function(grid, sortColumns) {
    +     *        // do something
    +     *      });
    +     * 
    + */ + self.api.registerEvent( 'core', 'sortChanged' ); + + /** + * @ngdoc function + * @name columnVisibilityChanged + * @methodOf ui.grid.api:PublicApi + * @description The visibility of a column has changed, + * the column itself is passed out as a parameter of the event. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed. + * + * @example + *
    +     *      gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
    +     *        // do something
    +     *      } );
    +     * 
    + */ + self.api.registerEvent( 'core', 'columnVisibilityChanged' ); + + /** + * @ngdoc method + * @name notifyDataChange + * @methodOf ui.grid.api:PublicApi + * @description Notify the grid that a data or config change has occurred, + * where that change isn't something the grid was otherwise noticing. This + * might be particularly relevant where you've changed values within the data + * and you'd like cell classes to be re-evaluated, or changed config within + * the columnDef and you'd like headerCellClasses to be re-evaluated. + * @param {string} type one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS), which tells us which refreshes to fire. + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange ); + + /** + * @ngdoc method + * @name clearAllFilters + * @methodOf ui.grid.api:PublicApi + * @description Clears all filters and optionally refreshes the visible rows. + * @param {object} refreshRows Defaults to true. + * @param {object} clearConditions Defaults to false. + * @param {object} clearFlags Defaults to false. + * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing. + */ + self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters); + + self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]); + self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]); + self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]); + + self.registerStyleComputation({ + priority: 10, + func: self.getFooterStyles + }); + }; + + Grid.prototype.calcFooterHeight = function () { + if (!this.hasFooter()) { + return 0; + } + + var height = 0; + if (this.options.showGridFooter) { + height += this.options.gridFooterHeight; + } + + height += this.calcColumnFooterHeight(); + + return height; + }; + + Grid.prototype.calcColumnFooterHeight = function () { + var height = 0; + + if (this.options.showColumnFooter) { + height += this.options.columnFooterHeight; + } + + return height; + }; + + Grid.prototype.getFooterStyles = function () { + var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }'; + style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }'; + return style; + }; + + Grid.prototype.hasFooter = function () { + return this.options.showGridFooter || this.options.showColumnFooter; + }; + + /** + * @ngdoc function + * @name isRTL + * @methodOf ui.grid.class:Grid + * @description Returns true if grid is RightToLeft + */ + Grid.prototype.isRTL = function () { + return this.rtl; + }; + + + /** + * @ngdoc function + * @name registerColumnBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates columns from column definitions, the columnbuilders will be called to add + * additional properties to the column. + * @param {function(colDef, col, gridOptions)} columnBuilder function to be called + */ + Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) { + this.columnBuilders.push(columnBuilder); + }; + + /** + * @ngdoc function + * @name buildColumnDefsFromData + * @methodOf ui.grid.class:Grid + * @description Populates columnDefs from the provided data + * @param {function(colDef, col, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.buildColumnDefsFromData = function (dataRows) { + this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties); + }; + + /** + * @ngdoc function + * @name registerRowBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add + * additional properties to the row. + * @param {function(row, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) { + this.rowBuilders.push(rowBuilder); + }; + + /** + * @ngdoc function + * @name registerDataChangeCallback + * @methodOf ui.grid.class:Grid + * @description When a data change occurs, the data change callbacks of the specified type + * will be called. The rules are: + * + * - when the data watch fires, that is considered a ROW change (the data watch only notices + * added or removed rows) + * - when the api is called to inform us of a change, the declared type of that change is used + * - when a cell edit completes, the EDIT callbacks are triggered + * - when the columnDef watch fires, the COLUMN callbacks are triggered + * - when the options watch fires, the OPTIONS callbacks are triggered + * + * For a given event: + * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks + * - ROW calls ROW and ALL callbacks + * - EDIT calls EDIT and ALL callbacks + * - COLUMN calls COLUMN and ALL callbacks + * - OPTIONS calls OPTIONS and ALL callbacks + * + * @param {function(grid)} callback function to be called + * @param {array} types the types of data change you want to be informed of. Values from + * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL + * @returns {function} deregister function - a function that can be called to deregister this callback + */ + Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) { + var self = this, + uid = gridUtil.nextUid(); + + if ( !types ) { + types = [uiGridConstants.dataChange.ALL]; + } + if ( !Array.isArray(types)) { + gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types ); + } + this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this: _this }; + + return function() { + delete self.dataChangeCallbacks[uid]; + }; + }; + + /** + * @ngdoc function + * @name callDataChangeCallbacks + * @methodOf ui.grid.class:Grid + * @description Calls the callbacks based on the type of data change that + * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the + * event type is matching, or if the type is ALL. + * @param {string} type the type of event that occurred - one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS) + */ + Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) { + angular.forEach( this.dataChangeCallbacks, function( callback, uid ) { + if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 || + callback.types.indexOf( type ) !== -1 || + type === uiGridConstants.dataChange.ALL ) { + if (callback._this) { + callback.callback.apply(callback._this, this, options); + } + else { + callback.callback(this, options); + } + } + }, this); + }; + + /** + * @ngdoc function + * @name notifyDataChange + * @methodOf ui.grid.class:Grid + * @description Notifies us that a data change has occurred, used in the public + * api for users to tell us when they've changed data or some other event that + * our watches cannot pick up + * @param {string} type the type of event that occurred - one of the + * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS) + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + Grid.prototype.notifyDataChange = function notifyDataChange(type) { + var constants = uiGridConstants.dataChange; + + if ( type === constants.ALL || + type === constants.COLUMN || + type === constants.EDIT || + type === constants.ROW || + type === constants.OPTIONS ) { + this.callDataChangeCallbacks( type ); + } + else { + gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type); + } + }; + + /** + * @ngdoc function + * @name columnRefreshCallback + * @methodOf ui.grid.class:Grid + * @description refreshes the grid when a column refresh + * is notified, which triggers handling of the visible flag. + * This is called on uiGridConstants.dataChange.COLUMN, and is + * registered as a dataChangeCallback in grid.js + * @param {object} grid The grid object. + * @param {object} options Any options passed into the callback. + */ + Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options) { + grid.buildColumns(options); + grid.queueGridRefresh(); + }; + + /** + * @ngdoc function + * @name processRowsCallback + * @methodOf ui.grid.class:Grid + * @description calls the row processors, specifically + * intended to reset the sorting when an edit is called, + * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT + * @param {object} grid The grid object. + */ + Grid.prototype.processRowsCallback = function processRowsCallback( grid ) { + grid.queueGridRefresh(); + }; + + + /** + * @ngdoc function + * @name updateFooterHeightCallback + * @methodOf ui.grid.class:Grid + * @description recalculates the footer height, + * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS + * @param {object} grid The grid object. + */ + Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ) { + grid.footerHeight = grid.calcFooterHeight(); + grid.columnFooterHeight = grid.calcColumnFooterHeight(); + }; + + + /** + * @ngdoc function + * @name getColumn + * @methodOf ui.grid.class:Grid + * @description returns a grid column for the column name + * @param {string} name column name + */ + Grid.prototype.getColumn = function getColumn(name) { + var columns = this.columns.filter(function (column) { + return column.colDef.name === name; + }); + + return columns.length > 0 ? columns[0] : null; + }; + + /** + * @ngdoc function + * @name getColDef + * @methodOf ui.grid.class:Grid + * @description returns a grid colDef for the column name + * @param {string} name column.field + */ + Grid.prototype.getColDef = function getColDef(name) { + var colDefs = this.options.columnDefs.filter(function (colDef) { + return colDef.name === name; + }); + return colDefs.length > 0 ? colDefs[0] : null; + }; + + /** + * @ngdoc function + * @name assignTypes + * @methodOf ui.grid.class:Grid + * @description uses the first row of data to assign colDef.type for any types not defined. + */ + /** + * @ngdoc property + * @name type + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description the type of the column, used in sorting. If not provided then the + * grid will guess the type. Add this only if the grid guessing is not to your + * satisfaction. One of: + * - 'string' + * - 'boolean' + * - 'number' + * - 'date' + * - 'object' + * - 'numberStr' + * Note that if you choose date, your dates should be in a javascript date type + * + */ + Grid.prototype.assignTypes = function() { + var self = this; + + self.options.columnDefs.forEach(function (colDef, index) { + // Assign colDef type if not specified + if (!colDef.type) { + var col = new GridColumn(colDef, index, self); + var firstRow = self.rows.length > 0 ? self.rows[0] : null; + if (firstRow) { + colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col)); + } + else { + colDef.type = 'string'; + } + } + }); + }; + + + /** + * @ngdoc function + * @name isRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description returns true if the column is a row Header + * @param {object} column column + */ + Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) { + return this.rowHeaderColumns.indexOf(column) !== -1; + }; + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description adds a row header column to the grid + * @param {object} colDef Column definition object. + * @param {float} order Number that indicates where the column should be placed in the grid. + * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve + * performance of the grid during initial load. + */ + Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) { + var self = this; + + // default order + if (order === undefined) { + order = 0; + } + + var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self); + rowHeaderCol.isRowHeader = true; + if (self.isRTL()) { + self.createRightContainer(); + rowHeaderCol.renderContainer = 'right'; + } + else { + self.createLeftContainer(); + rowHeaderCol.renderContainer = 'left'; + } + + // relies on the default column builder being first in array, as it is instantiated + // as part of grid creation + self.columnBuilders[0](colDef,rowHeaderCol,self.options) + .then(function() { + rowHeaderCol.enableFiltering = false; + rowHeaderCol.enableSorting = false; + rowHeaderCol.enableHiding = false; + rowHeaderCol.headerPriority = order; + self.rowHeaderColumns.push(rowHeaderCol); + self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) { + return a.headerPriority - b.headerPriority; + }); + + if (!stopColumnBuild) { + self.buildColumns() + .then(function() { + self.preCompileCellTemplates(); + self.queueGridRefresh(); + }).catch(angular.noop); + } + }).catch(angular.noop); + }; + + /** + * @ngdoc function + * @name getOnlyDataColumns + * @methodOf ui.grid.class:Grid + * @description returns all columns except for rowHeader columns + */ + Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() { + var self = this, + cols = []; + + self.columns.forEach(function (col) { + if (self.rowHeaderColumns.indexOf(col) === -1) { + cols.push(col); + } + }); + return cols; + }; + + /** + * @ngdoc function + * @name buildColumns + * @methodOf ui.grid.class:Grid + * @description creates GridColumn objects from the columnDefinition. Calls each registered + * columnBuilder to further process the column + * @param {object} opts An object contains options to use when building columns + * + * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions. + * + * @returns {Promise} a promise to load any needed column resources + */ + Grid.prototype.buildColumns = function buildColumns(opts) { + var options = { + orderByColumnDefs: false + }; + + angular.extend(options, opts); + + // gridUtil.logDebug('buildColumns'); + var self = this; + var builderPromises = []; + var headerOffset = self.rowHeaderColumns.length; + var i; + + // Remove any columns for which a columnDef cannot be found + // Deliberately don't use forEach, as it doesn't like splice being called in the middle + // Also don't cache columns.length, as it will change during this operation + for (i = 0; i < self.columns.length; i++) { + if (!self.getColDef(self.columns[i].name)) { + self.columns.splice(i, 1); + i--; + } + } + + // add row header columns to the grid columns array _after_ columns without columnDefs have been removed + // rowHeaderColumns is ordered by priority so insert in reverse + for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) { + self.columns.unshift(self.rowHeaderColumns[j]); + } + + // look at each column def, and update column properties to match. If the column def + // doesn't have a column, then splice in a new gridCol + self.options.columnDefs.forEach(function (colDef, index) { + self.preprocessColDef(colDef); + var col = self.getColumn(colDef.name); + + if (!col) { + col = new GridColumn(colDef, gridUtil.nextUid(), self); + self.columns.splice(index + headerOffset, 0, col); + } + else { + // tell updateColumnDef that the column was pre-existing + col.updateColumnDef(colDef, false); + } + + self.columnBuilders.forEach(function (builder) { + builderPromises.push(builder.call(self, colDef, col, self.options)); + }); + }); + + /*** Reorder columns if necessary ***/ + if (!!options.orderByColumnDefs) { + // Create a shallow copy of the columns as a cache + var columnCache = self.columns.slice(0); + + // We need to allow for the "row headers" when mapping from the column defs array to the columns array + // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0] + + // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then + // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result + var len = Math.min(self.options.columnDefs.length, self.columns.length); + for (i = 0; i < len; i++) { + // If the column at this index has a different name than the column at the same index in the column defs... + if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) { + // Replace the one in the cache with the appropriate column + columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name); + } + else { + // Otherwise just copy over the one from the initial columns + columnCache[i + headerOffset] = self.columns[i + headerOffset]; + } + } + + // Empty out the columns array, non-destructively + self.columns.length = 0; + + // And splice in the updated, ordered columns from the cache + Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache)); + } + + return $q.all(builderPromises).then(function() { + if (self.rows.length > 0) { + self.assignTypes(); + } + if (options.preCompileCellTemplates) { + self.preCompileCellTemplates(); + } + }).catch(angular.noop); + }; + + Grid.prototype.preCompileCellTemplate = function(col) { + var self = this; + var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col)); + html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + col.compiledElementFn = $compile(html); + + if (col.compiledElementFnDefer) { + col.compiledElementFnDefer.resolve(col.compiledElementFn); + } + }; + +/** + * @ngdoc function + * @name preCompileCellTemplates + * @methodOf ui.grid.class:Grid + * @description precompiles all cell templates + */ + Grid.prototype.preCompileCellTemplates = function() { + var self = this; + self.columns.forEach(function (col) { + if ( col.cellTemplate ) { + self.preCompileCellTemplate( col ); + } else if ( col.cellTemplatePromise ) { + col.cellTemplatePromise.then( function() { + self.preCompileCellTemplate( col ); + }).catch(angular.noop); + } + }); + }; + + /** + * @ngdoc function + * @name getGridQualifiedColField + * @methodOf ui.grid.class:Grid + * @description Returns the $parse-able accessor for a column within its $scope + * @param {GridColumn} col col object + */ + Grid.prototype.getQualifiedColField = function (col) { + var base = 'row.entity'; + if ( col.field === uiGridConstants.ENTITY_BINDING ) { + return base; + } + return gridUtil.preEval(base + '.' + col.field); + }; + + /** + * @ngdoc function + * @name createLeftContainer + * @methodOf ui.grid.class:Grid + * @description creates the left render container if it doesn't already exist + */ + Grid.prototype.createLeftContainer = function() { + if (!this.hasLeftContainer()) { + this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name createRightContainer + * @methodOf ui.grid.class:Grid + * @description creates the right render container if it doesn't already exist + */ + Grid.prototype.createRightContainer = function() { + if (!this.hasRightContainer()) { + this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name hasLeftContainer + * @methodOf ui.grid.class:Grid + * @description returns true if leftContainer exists + */ + Grid.prototype.hasLeftContainer = function() { + return this.renderContainers.left !== undefined; + }; + + /** + * @ngdoc function + * @name hasRightContainer + * @methodOf ui.grid.class:Grid + * @description returns true if rightContainer exists + */ + Grid.prototype.hasRightContainer = function() { + return this.renderContainers.right !== undefined; + }; + + + /** + * undocumented function + * @name preprocessColDef + * @methodOf ui.grid.class:Grid + * @description defaults the name property from field to maintain backwards compatibility with 2.x + * validates that name or field is present + */ + Grid.prototype.preprocessColDef = function preprocessColDef(colDef) { + var self = this; + + if (!colDef.field && !colDef.name) { + throw new Error('colDef.name or colDef.field property is required'); + } + + // maintain backwards compatibility with 2.x + // field was required in 2.x. now name is required + if (colDef.name === undefined && colDef.field !== undefined) { + // See if the column name already exists: + var newName = colDef.field, + counter = 2; + while (self.getColumn(newName)) { + newName = colDef.field + counter.toString(); + counter++; + } + colDef.name = newName; + } + }; + + // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters + Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) { + var self = this; + + var t = []; + for (var i = 0; i < n.length; i++) { + var nV = nAccessor ? n[i][nAccessor] : n[i]; + + var found = false; + for (var j = 0; j < o.length; j++) { + var oV = oAccessor ? o[j][oAccessor] : o[j]; + if (self.options.rowEquality(nV, oV)) { + found = true; + break; + } + } + if (!found) { + t.push(nV); + } + } + + return t; + }; + + /** + * @ngdoc function + * @name getRow + * @methodOf ui.grid.class:Grid + * @description returns the GridRow that contains the rowEntity + * @param {object} rowEntity the gridOptions.data array element instance + * @param {array} lookInRows [optional] the rows to look in - if not provided then + * looks in grid.rows + */ + Grid.prototype.getRow = function getRow(rowEntity, lookInRows) { + var self = this; + + lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows; + + var rows = lookInRows.filter(function (row) { + return self.options.rowEquality(row.entity, rowEntity); + }); + return rows.length > 0 ? rows[0] : null; + }; + + + /** + * @ngdoc function + * @name modifyRows + * @methodOf ui.grid.class:Grid + * @description creates or removes GridRow objects from the newRawData array. Calls each registered + * rowBuilder to further process the row + * @param {array} newRawData Modified set of data + * + * This method aims to achieve three things: + * 1. the resulting rows array is in the same order as the newRawData, we'll call + * rowsProcessors immediately after to sort the data anyway + * 2. if we have row hashing available, we try to use the rowHash to find the row + * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected + * + * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates + * the newRows and newHash + * + * ``` + * newRawData.forEach newEntity + * if (hashing enabled) + * check oldHash for newEntity + * else + * look for old row directly in oldRows + * if !oldRowFound // must be a new row + * create newRow + * append to the newRows and add to newHash + * run the processors + * ``` + * + * Rows are identified using the hashKey if configured. If not configured, then rows + * are identified using the gridOptions.rowEquality function + * + * This method is useful when trying to select rows immediately after loading data without + * using a $timeout/$interval, e.g.: + * + * $scope.gridOptions.data = someData; + * $scope.gridApi.grid.modifyRows($scope.gridOptions.data); + * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); + * + * OR to persist row selection after data update (e.g. rows selected, new data loaded, want + * originally selected rows to be re-selected)) + */ + Grid.prototype.modifyRows = function modifyRows(newRawData) { + var self = this; + var oldRows = self.rows.slice(0); + var oldRowHash = self.rowHashMap || self.createRowHashMap(); + var allRowsSelected = true; + self.rowHashMap = self.createRowHashMap(); + self.rows.length = 0; + + newRawData.forEach( function( newEntity, i ) { + var newRow, oldRow; + + if ( self.options.enableRowHashing ) { + // if hashing is enabled, then this row will be in the hash if we already know about it + oldRow = oldRowHash.get( newEntity ); + } else { + // otherwise, manually search the oldRows to see if we can find this row + oldRow = self.getRow(newEntity, oldRows); + } + + // update newRow to have an entity + if ( oldRow ) { + newRow = oldRow; + newRow.entity = newEntity; + } + + // if we didn't find the row, it must be new, so create it + if ( !newRow ) { + newRow = self.processRowBuilders(new GridRow(newEntity, i, self)); + } + + self.rows.push( newRow ); + self.rowHashMap.put( newEntity, newRow ); + if (!newRow.isSelected) { + allRowsSelected = false; + } + }); + + if (self.selection && self.rows.length) { + self.selection.selectAll = allRowsSelected; + } + + self.assignTypes(); + + var p1 = $q.when(self.processRowsProcessors(self.rows)) + .then(function (renderableRows) { + return self.setVisibleRows(renderableRows); + }).catch(angular.noop); + + var p2 = $q.when(self.processColumnsProcessors(self.columns)) + .then(function (renderableColumns) { + return self.setVisibleColumns(renderableColumns); + }).catch(angular.noop); + + return $q.all([p1, p2]); + }; + + + /** + * Private Undocumented Method + * @name addRows + * @methodOf ui.grid.class:Grid + * @description adds the newRawData array of rows to the grid and calls all registered + * rowBuilders. this keyword will reference the grid + */ + Grid.prototype.addRows = function addRows(newRawData) { + var self = this, + existingRowCount = self.rows.length; + + for (var i = 0; i < newRawData.length; i++) { + var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self)); + + if (self.options.enableRowHashing) { + var found = self.rowHashMap.get(newRow.entity); + if (found) { + found.row = newRow; + } + } + + self.rows.push(newRow); + } + }; + + /** + * @ngdoc function + * @name processRowBuilders + * @methodOf ui.grid.class:Grid + * @description processes all RowBuilders for the gridRow + * @param {GridRow} gridRow reference to gridRow + * @returns {GridRow} the gridRow with all additional behavior added + */ + Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) { + var self = this; + + self.rowBuilders.forEach(function (builder) { + builder.call(self, gridRow, self.options); + }); + + return gridRow; + }; + + /** + * @ngdoc function + * @name registerStyleComputation + * @methodOf ui.grid.class:Grid + * @description registered a styleComputation function + * + * If the function returns a value it will be appended into the grid's `
    " + ); + + + $templateCache.put('ui-grid/uiGridCell', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/uiGridColumnMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridFooterCell', + "
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    " + ); + + + $templateCache.put('ui-grid/uiGridHeaderCell', + "
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
     
    " + ); + + + $templateCache.put('ui-grid/uiGridMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridMenuItem', + "" + ); + + + $templateCache.put('ui-grid/uiGridRenderContainer', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridViewport', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.core.min.js b/src/i18n/ui-grid.core.min.js new file mode 100644 index 0000000000..66b22f2720 --- /dev/null +++ b/src/i18n/ui-grid.core.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";angular.module("ui.grid.i18n",[]),angular.module("ui.grid",["ui.grid.i18n"])}(),function(){"use strict";angular.module("ui.grid").constant("uiGridConstants",{LOG_DEBUG_MESSAGES:!0,LOG_WARN_MESSAGES:!0,LOG_ERROR_MESSAGES:!0,CUSTOM_FILTERS:/CUSTOM_FILTERS/g,COL_FIELD:/COL_FIELD/g,MODEL_COL_FIELD:/MODEL_COL_FIELD/g,TOOLTIP:/title=\"TOOLTIP\"/g,DISPLAY_CELL_TEMPLATE:/DISPLAY_CELL_TEMPLATE/g,TEMPLATE_REGEXP:/<.+>/,FUNC_REGEXP:/(\([^)]*\))?$/,DOT_REGEXP:/\./g,APOS_REGEXP:/'/g,BRACKET_REGEXP:/^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,COL_CLASS_PREFIX:"ui-grid-col",ENTITY_BINDING:"$$this",events:{GRID_SCROLL:"uiGridScroll",COLUMN_MENU_SHOWN:"uiGridColMenuShown",ITEM_DRAGGING:"uiGridItemDragStart",COLUMN_HEADER_CLICK:"uiGridColumnHeaderClick"},keymap:{TAB:9,STRG:17,CAPSLOCK:20,CTRL:17,CTRLRIGHT:18,CTRLR:18,SHIFT:16,RETURN:13,ENTER:13,BACKSPACE:8,BCKSP:8,ALT:18,ALTR:17,ALTRIGHT:17,SPACE:32,WIN:91,MAC:91,FN:null,PG_UP:33,PG_DOWN:34,UP:38,DOWN:40,LEFT:37,RIGHT:39,ESC:27,DEL:46,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123},ASC:"asc",DESC:"desc",filter:{STARTS_WITH:2,ENDS_WITH:4,EXACT:8,CONTAINS:16,GREATER_THAN:32,GREATER_THAN_OR_EQUAL:64,LESS_THAN:128,LESS_THAN_OR_EQUAL:256,NOT_EQUAL:512,SELECT:"select",INPUT:"input"},aggregationTypes:{sum:2,count:4,avg:8,min:16,max:32},CURRENCY_SYMBOLS:["¤","؋","Ar","Ƀ","฿","B/.","Br","Bs.","Bs.F.","GH₵","¢","c","Ch.","₡","C$","D","ден","دج",".د.ب","د.ع","JD","د.ك","ل.د","дин","د.ت","د.م.","د.إ","Db","$","₫","Esc","€","ƒ","Ft","FBu","FCFA","CFA","Fr","FRw","G","gr","₲","h","₴","₭","Kč","kr","kn","MK","ZK","Kz","K","L","Le","лв","E","lp","M","KM","MT","₥","Nfk","₦","Nu.","UM","T$","MOP$","₱","Pt.","£","ج.م.","LL","LS","P","Q","q","R","R$","ر.ع.","ر.ق","ر.س","៛","RM","p","Rf.","₹","₨","SRe","Rp","₪","Ksh","Sh.So.","USh","S/","SDR","сом","৳\t","WS$","₮","VT","₩","¥","zł"],scrollDirection:{UP:"up",DOWN:"down",LEFT:"left",RIGHT:"right",NONE:"none"},dataChange:{ALL:"all",EDIT:"edit",ROW:"row",COLUMN:"column",OPTIONS:"options"},scrollbars:{NEVER:0,ALWAYS:1,WHEN_NEEDED:2}})}(),angular.module("ui.grid").directive("uiGridCell",["$compile","$parse","gridUtil","uiGridConstants",function(l,e,a,s){return{priority:0,scope:!1,require:"?^uiGrid",compile:function(){return{pre:function(t,r,e,i){if(i&&t.col.compiledElementFn)(0,t.col.compiledElementFn)(t,function(e,t){r.append(e)});else if(i&&!t.col.compiledElementFn)t.col.getCompiledElementFn().then(function(e){e(t,function(e,t){r.append(e)})}).catch(angular.noop);else{var n=t.col.cellTemplate.replace(s.MODEL_COL_FIELD,"row.entity."+a.preEval(t.col.field)).replace(s.COL_FIELD,"grid.getCellValue(row, col)"),o=l(n)(t);r.append(o)}},post:function(i,n){var o,l=i.col.getColClass(!1);function a(e){var t=n;o&&(t.removeClass(o),o=null),o=angular.isFunction(i.col.cellClass)?i.col.cellClass(i.grid,i.row,i.col,i.rowRenderIndex,i.colRenderIndex):i.col.cellClass,t.addClass(o)}n.addClass(l),i.col.cellClass&&a();var e=i.grid.registerDataChangeCallback(a,[s.dataChange.COLUMN,s.dataChange.EDIT]);var t=i.$watch("row",function(e,t){if(e!==t){(o||i.col.cellClass)&&a();var r=i.col.getColClass(!1);r!==l&&(n.removeClass(l),n.addClass(r),l=r)}});function r(){e(),t()}i.$on("$destroy",r),n.on("$destroy",r)}}}}}]),angular.module("ui.grid").service("uiGridColumnMenuService",["i18nService","uiGridConstants","gridUtil",function(e,r,g){var i={initialize:function(e,t){e.grid=t.grid,(t.columnMenuScope=e).menuShown=!1},setColMenuItemWatch:function(t){var e=t.$watch("col.menuItems",function(e){void 0!==e&&e&&angular.isArray(e)?(e.forEach(function(e){void 0!==e.context&&e.context||(e.context={}),e.context.col=t.col}),t.menuItems=t.defaultMenuItems.concat(e)):t.menuItems=t.defaultMenuItems});t.$on("$destroy",e)},getGridOption:function(e,t){return void 0!==e.grid&&e.grid&&e.grid.options&&e.grid.options[t]},sortable:function(e){return Boolean(this.getGridOption(e,"enableSorting")&&void 0!==e.col&&e.col&&e.col.enableSorting)},isActiveSort:function(e,t){return Boolean(void 0!==e.col&&void 0!==e.col.sort&&void 0!==e.col.sort.direction&&e.col.sort.direction===t)},suppressRemoveSort:function(e){return Boolean(e.col&&e.col.suppressRemoveSort)},hideable:function(e){return Boolean(this.getGridOption(e,"enableHiding")&&void 0!==e.col&&e.col&&(e.col.colDef&&!1!==e.col.colDef.enableHiding||!e.col.colDef)||!this.getGridOption(e,"enableHiding")&&e.col&&e.col.colDef&&e.col.colDef.enableHiding)},getDefaultMenuItems:function(t){return[{title:function(){return e.getSafeText("sort.ascending")},icon:"ui-grid-icon-sort-alt-up",action:function(e){e.stopPropagation(),t.sortColumn(e,r.ASC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.ASC)}},{title:function(){return e.getSafeText("sort.descending")},icon:"ui-grid-icon-sort-alt-down",action:function(e){e.stopPropagation(),t.sortColumn(e,r.DESC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.DESC)}},{title:function(){return e.getSafeText("sort.remove")},icon:"ui-grid-icon-cancel",action:function(e){e.stopPropagation(),t.unsortColumn()},shown:function(){return i.sortable(t)&&void 0!==t.col&&void 0!==t.col.sort&&void 0!==t.col.sort.direction&&null!==t.col.sort.direction&&!i.suppressRemoveSort(t)}},{title:function(){return e.getSafeText("column.hide")},icon:"ui-grid-icon-cancel",shown:function(){return i.hideable(t)},action:function(e){e.stopPropagation(),t.hideColumn()}}]},getColumnElementPosition:function(e,t,r){var i={};return i.left=r[0].offsetLeft,i.top=r[0].offsetTop,i.parentLeft=r[0].offsetParent.offsetLeft,i.offset=0,t.grid.options.offsetLeft&&(i.offset=t.grid.options.offsetLeft),i.height=g.elementHeight(r,!0),i.width=g.elementWidth(r,!0),i},repositionMenu:function(e,t,r,i,n){var o=i[0].querySelectorAll(".ui-grid-menu"),l=g.closestElm(n,".ui-grid-render-container"),a=l.getBoundingClientRect().left-e.grid.element[0].getBoundingClientRect().left,s=l.querySelectorAll(".ui-grid-viewport")[0].scrollLeft,c=g.elementWidth(o,!0),u=t.lastMenuPaddingRight?t.lastMenuPaddingRight:e.lastMenuPaddingRight?e.lastMenuPaddingRight:10;0!==o.length&&0!==o[0].querySelectorAll(".ui-grid-menu-mid").length&&(u=parseInt(g.getStyles(angular.element(o)[0]).paddingRight,10),e.lastMenuPaddingRight=u,t.lastMenuPaddingRight=u);var d=r.left+a-s+r.parentLeft+r.width+u;d(u.grid.rowHeaderColumns?u.grid.rowHeaderColumns.length:0);!r&&!n.uiGridColumns&&0===u.grid.options.columnDefs.length&&0
    ',scope:{side:"=uiGridPinnedContainer"},require:"^uiGrid",compile:function(){return{post:function(n,t,e,r){var o=r.grid,i=0;function l(){if("left"===n.side||"right"===n.side){for(var e=o.renderContainers[n.side].visibleColumnCache,t=0,r=0;r=t&&(t=e.sort.priority+1)}),t},e.prototype.resetColumnSorting=function(t){this.columns.forEach(function(e){e===t||e.suppressRemoveSort||(e.sort={})})},e.prototype.getColumnSorting=function(){var t=[];return this.columns.slice(0).sort(h.prioritySort).forEach(function(e){e.sort&&void 0!==e.sort.direction&&e.sort.direction&&(e.sort.direction===s.ASC||e.sort.direction===s.DESC)&&t.push(e)}),t},e.prototype.sortColumn=function(e,t,r){var i=this,n=null;if(void 0===e||!e)throw new Error("No column parameter provided");if("boolean"==typeof t?r=t:n=t,!r||i.options&&i.options.suppressMultiSort?(i.resetColumnSorting(e),e.sort.priority=void 0,e.sort.priority=i.getNextColumnSortPriority()):void 0===e.sort.priority&&(e.sort.priority=i.getNextColumnSortPriority()),n)e.sort.direction=n;else{var o=e.sortDirectionCycle.indexOf(e.sort&&e.sort.direction?e.sort.direction:null);o=(o+1)%e.sortDirectionCycle.length,e.colDef&&e.suppressRemoveSort&&!e.sortDirectionCycle[o]&&(o=(o+1)%e.sortDirectionCycle.length),e.sortDirectionCycle[o]?e.sort.direction=e.sortDirectionCycle[o]:l(e,i)}return i.api.core.raise.sortChanged(i,i.getColumnSorting()),S.when(e)};var l=function(t,e){e.columns.forEach(function(e){e.sort&&void 0!==e.sort.priority&&e.sort.priority>t.sort.priority&&(e.sort.priority-=1)}),t.sort={}};function a(e,t){return e||0Math.ceil(s)&&(u=h-s+r.renderContainers.body.prevScrollTop,i.y=T(u+r.options.rowHeight,g,r.renderContainers.body.prevScrolltopPercentage))}if(null!==t){for(var p=o.indexOf(t),f=r.renderContainers.body.getCanvasWidth()-r.renderContainers.body.getViewportWidth(),m=0,v=0;vt&&(e.sort.priority-=1)}),this.sort={},this.grid.api.core.raise.sortChanged(this.grid,this.grid.getColumnSorting())},t.prototype.getColClass=function(e){var t=u.COL_CLASS_PREFIX+this.uid;return e?"."+t:t},t.prototype.isPinnedLeft=function(){return"left"===this.renderContainer},t.prototype.isPinnedRight=function(){return"right"===this.renderContainer},t.prototype.getColClassDefinition=function(){return" .grid"+this.grid.id+" "+this.getColClass(!0)+" { min-width: "+this.drawnWidth+"px; max-width: "+this.drawnWidth+"px; }"},t.prototype.getRenderContainer=function(){var e=this.renderContainer;return null!==e&&""!==e&&void 0!==e||(e="body"),this.grid.renderContainers[e]},t.prototype.showColumn=function(){this.colDef.visible=!0},t.prototype.getAggregationText=function(){if(this.colDef.aggregationHideLabel)return"";if(this.colDef.aggregationLabel)return this.colDef.aggregationLabel;switch(this.colDef.aggregationType){case u.aggregationTypes.count:return e.getSafeText("aggregation.count");case u.aggregationTypes.sum:return e.getSafeText("aggregation.sum");case u.aggregationTypes.avg:return e.getSafeText("aggregation.avg");case u.aggregationTypes.min:return e.getSafeText("aggregation.min");case u.aggregationTypes.max:return e.getSafeText("aggregation.max");default:return""}},t.prototype.getCellTemplate=function(){return this.cellTemplatePromise},t.prototype.getCompiledElementFn=function(){return this.compiledElementFnDefer.promise},t}]),angular.module("ui.grid").factory("GridOptions",["gridUtil","uiGridConstants",function(t,r){return{initialize:function(e){return e.onRegisterApi=e.onRegisterApi||angular.noop(),e.data=e.data||[],e.columnDefs=e.columnDefs||[],e.excludeProperties=e.excludeProperties||["$$hashKey"],e.enableRowHashing=!1!==e.enableRowHashing,e.rowIdentity=e.rowIdentity||function(e){return t.hashKey(e)},e.getRowIdentity=e.getRowIdentity||function(e){return e.$$hashKey},e.flatEntityAccess=!0===e.flatEntityAccess,e.showHeader=void 0===e.showHeader||e.showHeader,e.showHeader?e.headerRowHeight=void 0!==e.headerRowHeight?e.headerRowHeight:30:e.headerRowHeight=0,"string"==typeof e.rowHeight?e.rowHeight=parseInt(e.rowHeight)||30:e.rowHeight=e.rowHeight||30,e.minRowsToShow=void 0!==e.minRowsToShow?e.minRowsToShow:10,e.showGridFooter=!0===e.showGridFooter,e.showColumnFooter=!0===e.showColumnFooter,e.columnFooterHeight=void 0!==e.columnFooterHeight?e.columnFooterHeight:30,e.gridFooterHeight=void 0!==e.gridFooterHeight?e.gridFooterHeight:30,e.columnWidth=void 0!==e.columnWidth?e.columnWidth:50,e.maxVisibleColumnCount=void 0!==e.maxVisibleColumnCount?e.maxVisibleColumnCount:200,e.virtualizationThreshold=void 0!==e.virtualizationThreshold?e.virtualizationThreshold:20,e.columnVirtualizationThreshold=void 0!==e.columnVirtualizationThreshold?e.columnVirtualizationThreshold:10,e.excessRows=void 0!==e.excessRows?e.excessRows:4,e.scrollThreshold=void 0!==e.scrollThreshold?e.scrollThreshold:4,e.excessColumns=void 0!==e.excessColumns?e.excessColumns:4,e.aggregationCalcThrottle=void 0!==e.aggregationCalcThrottle?e.aggregationCalcThrottle:500,e.wheelScrollThrottle=void 0!==e.wheelScrollThrottle?e.wheelScrollThrottle:70,e.scrollDebounce=void 0!==e.scrollDebounce?e.scrollDebounce:300,e.enableHiding=!1!==e.enableHiding,e.enableSorting=!1!==e.enableSorting,e.suppressMultiSort=!0===e.suppressMultiSort,e.enableFiltering=!0===e.enableFiltering,e.filterContainer=void 0!==e.filterContainer?e.filterContainer:"headerCell",e.enableColumnMenus=!1!==e.enableColumnMenus,e.enableVerticalScrollbar=void 0!==e.enableVerticalScrollbar?e.enableVerticalScrollbar:r.scrollbars.ALWAYS,e.enableHorizontalScrollbar=void 0!==e.enableHorizontalScrollbar?e.enableHorizontalScrollbar:r.scrollbars.ALWAYS,e.enableMinHeightCheck=!1!==e.enableMinHeightCheck,e.minimumColumnSize=void 0!==e.minimumColumnSize?e.minimumColumnSize:30,e.rowEquality=e.rowEquality||function(e,t){return e===t},e.headerTemplate=e.headerTemplate||null,e.footerTemplate=e.footerTemplate||"ui-grid/ui-grid-footer",e.gridFooterTemplate=e.gridFooterTemplate||"ui-grid/ui-grid-grid-footer",e.rowTemplate=e.rowTemplate||"ui-grid/ui-grid-row",e.gridMenuTemplate=e.gridMenuTemplate||"ui-grid/uiGridMenu",e.menuButtonTemplate=e.menuButtonTemplate||"ui-grid/ui-grid-menu-button",e.menuItemTemplate=e.menuItemTemplate||"ui-grid/uiGridMenuItem",e.appScopeProvider=e.appScopeProvider||null,e}}}]),angular.module("ui.grid").factory("GridRenderContainer",["gridUtil","uiGridConstants",function(y,n){function e(e,t,r){var i=this;i.name=e,i.grid=t,i.visibleRowCache=[],i.visibleColumnCache=[],i.renderedRows=[],i.renderedColumns=[],i.prevScrollTop=0,i.prevScrolltopPercentage=0,i.prevRowScrollIndex=0,i.prevScrollLeft=0,i.prevScrollleftPercentage=0,i.prevColumnScrollIndex=0,i.columnStyles="",i.viewportAdjusters=[],i.hasHScrollbar=!1,i.hasVScrollbar=!1,i.canvasHeightShouldUpdate=!0,i.$$canvasHeight=0,r&&angular.isObject(r)&&angular.extend(i,r),t.registerStyleComputation({priority:5,func:function(){return i.updateColumnWidths(),i.columnStyles}})}return e.prototype.reset=function(){this.visibleColumnCache.length=0,this.visibleRowCache.length=0,this.renderedRows.length=0,this.renderedColumns.length=0},e.prototype.containsColumn=function(e){return-1!==this.visibleColumnCache.indexOf(e)},e.prototype.minRowsToRender=function(){for(var e=0,t=0,r=this.getViewportHeight(),i=this.visibleRowCache.length-1;ti.grid.options.virtualizationThreshold){if(null!=e){if(!i.grid.suppressParentScrollDown&&i.prevScrollTope&&a>i.prevRowScrollIndex-i.grid.options.scrollThreshold&&at.grid.options.columnVirtualizationThreshold&&t.getCanvasWidth()>t.getViewportWidth())l=[Math.max(0,o-t.grid.options.excessColumns),Math.min(i.length,o+r+t.grid.options.excessColumns)];else{var a=t.visibleColumnCache.length;l=[0,Math.max(a,r+t.grid.options.excessColumns)]}t.updateViewableColumnRange(l),t.prevColumnScrollIndex=o},e.prototype.getLeftIndex=function(e){for(var t=0,r=0;re.maxWidth&&(t=e.maxWidth),te.maxWidth&&(t=e.maxWidth),te.minWidth&&0e.offsetWidth)},e.prototype.getViewportStyle=function(){var e=this,t={},r={};return r[n.scrollbars.ALWAYS]="scroll",r[n.scrollbars.WHEN_NEEDED]="auto",e.hasHScrollbar=!1,e.hasVScrollbar=!1,e.grid.disableScrolling?(t["overflow-x"]="hidden",t["overflow-y"]="hidden"):("body"===e.name?(e.hasHScrollbar=e.grid.options.enableHorizontalScrollbar!==n.scrollbars.NEVER,e.grid.isRTL()?e.grid.hasLeftContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER):e.grid.hasRightContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER)):"left"===e.name?e.hasVScrollbar=!!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER:e.hasVScrollbar=!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER,t["overflow-x"]=e.hasHScrollbar?r[e.grid.options.enableHorizontalScrollbar]:"hidden",t["overflow-y"]=e.hasVScrollbar?r[e.grid.options.enableVerticalScrollbar]:"hidden"),t},e}]),angular.module("ui.grid").factory("GridRow",["gridUtil","uiGridConstants",function(i,t){function e(e,t,r){this.grid=r,this.entity=e,this.index=t,this.uid=i.nextUid(),this.visible=!0,this.isSelected=!1,this.$$height=r.options.rowHeight}return Object.defineProperty(e.prototype,"height",{get:function(){return this.$$height},set:function(e){e!==this.$$height&&(this.grid.updateCanvasHeight(),this.$$height=e)}}),e.prototype.getQualifiedColField=function(e){return"row."+this.getEntityQualifiedColField(e)},e.prototype.getEntityQualifiedColField=function(e){return e.field===t.ENTITY_BINDING?"entity":i.preEval("entity."+e.field)},e.prototype.setRowInvisible=function(e){e&&e.setThisRowInvisible&&e.setThisRowInvisible("user")},e.prototype.clearRowInvisible=function(e){e&&e.clearThisRowInvisible&&e.clearThisRowInvisible("user")},e.prototype.setThisRowInvisible=function(e,t){this.invisibleReason||(this.invisibleReason={}),this.invisibleReason[e]=!0,this.evaluateRowVisibility(t)},e.prototype.clearThisRowInvisible=function(e,t){void 0!==this.invisibleReason&&delete this.invisibleReason[e],this.evaluateRowVisibility(t)},e.prototype.evaluateRowVisibility=function(e){var r=!0;void 0!==this.invisibleReason&&angular.forEach(this.invisibleReason,function(e,t){e&&(r=!1)}),void 0!==this.visible&&this.visible===r||(this.visible=r,e||(this.grid.queueGridRefresh(),this.grid.api.core.raise.rowsVisibleChanged(this)))},e}]),function(){"use strict";angular.module("ui.grid").factory("GridRowColumn",["$parse","$filter",function(e,t){var r=function e(t,r){if(!(this instanceof e))throw"Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";this.row=t,this.col=r};return r.prototype.getIntersectionValueRaw=function(){return e(this.row.getEntityQualifiedColField(this.col))(this.row)},r}])}(),angular.module("ui.grid").factory("ScrollEvent",["gridUtil",function(l){function e(e,t,r,i){var n=this;if(!e)throw new Error("grid argument is required");n.grid=e,n.source=i,n.withDelay=!0,n.sourceRowContainer=t,n.sourceColContainer=r,n.newScrollLeft=null,n.newScrollTop=null,n.x=null,n.y=null,n.verticalScrollLength=-9999999,n.horizontalScrollLength=-999999,n.fireThrottledScrollingEvent=l.throttle(function(e){n.grid.scrollContainers(e,n)},n.grid.options.wheelScrollThrottle,{trailing:!0})}return e.prototype.getNewScrollLeft=function(e,t){var r=this;if(r.newScrollLeft)return r.newScrollLeft;var i,n=e.getCanvasWidth()-e.getViewportWidth(),o=l.normalizeScrollLeft(t,r.grid);if(void 0!==r.x.percentage&&void 0!==r.x.percentage)i=r.x.percentage;else{if(void 0===r.x.pixels||void 0===r.x.pixels)throw new Error("No percentage or pixel value provided for scroll event X axis");i=r.x.percentage=(o+r.x.pixels)/n}return Math.max(0,i*n)},e.prototype.getNewScrollTop=function(e,t){var r=this;if(r.newScrollTop)return r.newScrollTop;var i,n=e.getVerticalScrollLength(),o=t[0].scrollTop;if(void 0!==r.y.percentage&&void 0!==r.y.percentage)i=r.y.percentage;else{if(void 0===r.y.pixels||void 0===r.y.pixels)throw new Error("No percentage or pixel value provided for scroll event Y axis");i=r.y.percentage=(o+r.y.pixels)/n}return Math.max(0,i*n)},e.prototype.atTop=function(e){return this.y&&(0===this.y.percentage||this.verticalScrollLength<0)&&0===e},e.prototype.atBottom=function(e){return this.y&&(1===this.y.percentage||0===this.verticalScrollLength)&&0
    ')[0],r="reverse";return document.body.appendChild(t),0
     
     
    '),e.put("ui-grid/ui-grid-footer",''),e.put("ui-grid/ui-grid-grid-footer",''),e.put("ui-grid/ui-grid-header",'
    \x3c!-- theader --\x3e
    '),e.put("ui-grid/ui-grid-menu-button",'
     
    '),e.put("ui-grid/ui-grid-menu-header-item",'
  • '),e.put("ui-grid/ui-grid-no-header",'
    '),e.put("ui-grid/ui-grid-row","
    "),e.put("ui-grid/ui-grid",'
    \x3c!-- TODO (c0bra): add "scoped" attr here, eventually? --\x3e
    '),e.put("ui-grid/uiGridCell",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),e.put("ui-grid/uiGridColumnMenu",'
    \x3c!--
    \n
    \n
      \n
      \n
    • Sort Ascending
    • \n
    • Sort Descending
    • \n
    • Remove Sort
    • \n
      \n
    \n
    \n
    --\x3e
    '),e.put("ui-grid/uiGridFooterCell",'
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    '),e.put("ui-grid/uiGridHeaderCell",'
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
    '),e.put("ui-grid/uiGridMenu",'
    '),e.put("ui-grid/uiGridMenuItem",''),e.put("ui-grid/uiGridRenderContainer","
    \x3c!-- All of these dom elements are replaced in place --\x3e
    "),e.put("ui-grid/uiGridViewport",'
    \x3c!-- tbody --\x3e
    ')}]); \ No newline at end of file diff --git a/src/features/edit/js/gridEdit.js b/src/i18n/ui-grid.edit.js similarity index 91% rename from src/features/edit/js/gridEdit.js rename to src/i18n/ui-grid.edit.js index 1a84b4eacc..ed7c1c394b 100644 --- a/src/features/edit/js/gridEdit.js +++ b/src/i18n/ui-grid.edit.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -30,7 +35,7 @@ */ module.constant('uiGridEditConstants', { EDITABLE_CELL_TEMPLATE: /EDITABLE_CELL_TEMPLATE/g, - //must be lowercase because template bulder converts to lower + // must be lowercase because template bulder converts to lower EDITABLE_CELL_DIRECTIVE: /editable_cell_directive/g, events: { BEGIN_CELL_EDIT: 'uiGridEventBeginCellEdit', @@ -72,7 +77,7 @@ * @eventOf ui.grid.edit.api:PublicApi * @description raised when cell editing is complete *
    -                 *      gridApi.edit.on.afterCellEdit(scope,function(rowEntity, colDef){})
    +                 *      gridApi.edit.on.afterCellEdit(scope,function(rowEntity, colDef) {})
                      * 
    * @param {object} rowEntity the options.data element that was edited * @param {object} colDef the column that was edited @@ -87,7 +92,7 @@ * @eventOf ui.grid.edit.api:PublicApi * @description raised when cell editing starts on a cell *
    -                 *      gridApi.edit.on.beginCellEdit(scope,function(rowEntity, colDef){})
    +                 *      gridApi.edit.on.beginCellEdit(scope,function(rowEntity, colDef) {})
                      * 
    * @param {object} rowEntity the options.data element that was edited * @param {object} colDef the column that was edited @@ -102,7 +107,7 @@ * @eventOf ui.grid.edit.api:PublicApi * @description raised when cell editing is cancelled on a cell *
    -                 *      gridApi.edit.on.cancelCellEdit(scope,function(rowEntity, colDef){})
    +                 *      gridApi.edit.on.cancelCellEdit(scope,function(rowEntity, colDef) {})
                      * 
    * @param {object} rowEntity the options.data element that was edited * @param {object} colDef the column that was edited @@ -117,8 +122,7 @@ }; grid.api.registerEventsFromObject(publicApi.events); - //grid.api.registerMethodsFromObject(publicApi.methods); - + // grid.api.registerMethodsFromObject(publicApi.methods); }, defaultGridOptions: function (gridOptions) { @@ -147,7 +151,7 @@ * If false, then editing of cell is not allowed. * @example *
    -           *  function($scope, triggerEvent){
    +           *  function($scope, triggerEvent) {
                *    //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
                *    return true;
                *  }
    @@ -170,7 +174,7 @@
                *  @description If true, then editor is invoked as soon as cell receives focus. Default false.
                *  
    _requires cellNav feature and the edit feature to be enabled_ */ - //enableCellEditOnFocus can only be used if cellnav module is used + // enableCellEditOnFocus can only be used if cellnav module is used gridOptions.enableCellEditOnFocus = gridOptions.enableCellEditOnFocus === undefined ? false : gridOptions.enableCellEditOnFocus; }, @@ -209,7 +213,7 @@ * @description If specified, either a value or function evaluated before editing cell. If falsy, then editing of cell is not allowed. * @example *
    -           *  function($scope, triggerEvent){
    +           *  function($scope, triggerEvent) {
                *    //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
                *    return true;
                *  }
    @@ -246,7 +250,7 @@
                *  @description If true, then editor is invoked as soon as cell receives focus. Default false.
                *  
    _requires both the cellNav feature and the edit feature to be enabled_ */ - //enableCellEditOnFocus can only be used if cellnav module is used + // enableCellEditOnFocus can only be used if cellnav module is used colDef.enableCellEditOnFocus = colDef.enableCellEditOnFocus === undefined ? gridOptions.enableCellEditOnFocus : colDef.enableCellEditOnFocus; @@ -255,13 +259,13 @@ * @name editModelField * @propertyOf ui.grid.edit.api:ColumnDef * @description a bindable string value that is used when binding to edit controls instead of colDef.field - *
    example: You have a complex property on and object like state:{abbrev:'MS',name:'Mississippi'}. The + *
    example: You have a complex property on and object like state:{abbrev: 'MS',name: 'Mississippi'}. The * grid should display state.name in the cell and sort/filter based on the state.name property but the editor * requires the full state object. *
    colDef.field = 'state.name' *
    colDef.editModelField = 'state' */ - //colDef.editModelField + // colDef.editModelField return $q.all(promises); }, @@ -276,7 +280,7 @@ * @returns {boolean} true if an edit should start */ isStartEditKey: function (evt) { - if (evt.metaKey || + return !(evt.metaKey || evt.keyCode === uiGridConstants.keymap.ESC || evt.keyCode === uiGridConstants.keymap.SHIFT || evt.keyCode === uiGridConstants.keymap.CTRL || @@ -294,14 +298,8 @@ (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) || evt.keyCode === uiGridConstants.keymap.DOWN || - evt.keyCode === uiGridConstants.keymap.ENTER) { - return false; - - } - return true; + evt.keyCode === uiGridConstants.keymap.ENTER); } - - }; return service; @@ -371,7 +369,7 @@ function ( uiGridEditConstants) { return { replace: true, - priority: -99998, //run before cellNav + priority: -99998, // run before cellNav require: ['^uiGrid', '^uiGridRenderContainer'], scope: false, compile: function () { @@ -383,19 +381,18 @@ if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; } var containerId = controllers[1].containerId; - //no need to process for other containers + // no need to process for other containers if (containerId !== 'body') { return; } - //refocus on the grid + // refocus on the grid $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () { uiGridCtrl.focus(); }); $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () { uiGridCtrl.focus(); }); - } }; } @@ -470,11 +467,11 @@ scope: false, require: '?^uiGrid', link: function ($scope, $elm, $attrs, uiGridCtrl) { - var html; - var origCellValue; - var inEdit = false; - var cellModel; - var cancelTouchstartTimeout; + var html, + origCellValue, + cellModel, + cancelTouchstartTimeout, + inEdit = false; var editCellScope; @@ -488,7 +485,7 @@ var setEditable = function() { if ($scope.col.colDef.enableCellEdit && $scope.row.enableCellEdit !== false) { - if (!$scope.beginEditEventsWired) { //prevent multiple attachments + if (!$scope.beginEditEventsWired) { // prevent multiple attachments registerBeginEditEvents(); } } else { @@ -527,7 +524,7 @@ } if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) { - //important to do this before scrollToIfNecessary + // important to do this before scrollToIfNecessary beginEditKeyDown(evt); } }); @@ -535,9 +532,9 @@ cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol, evt) { if ($scope.col.colDef.enableCellEditOnFocus) { // Don't begin edit if the cell hasn't changed - if ((!oldRowCol || newRowCol.row !== oldRowCol.row || newRowCol.col !== oldRowCol.col) && - newRowCol.row === $scope.row && newRowCol.col === $scope.col) { - $timeout(function () { + if (newRowCol.row === $scope.row && newRowCol.col === $scope.col && + (evt === null || (evt && (evt.type === 'click' || evt.type === 'keydown')))) { + $timeout(function() { beginEdit(evt); }); } @@ -546,7 +543,6 @@ } $scope.beginEditEventsWired = true; - } function touchStart(event) { @@ -568,11 +564,11 @@ // Undbind the touchend handler, we don't need it anymore $elm.off('touchend', touchEnd); - }); + }).catch(angular.noop); } // Cancel any touchstart timeout - function touchEnd(event) { + function touchEnd() { $timeout.cancel(cancelTouchstartTimeout); $elm.off('touchend', touchEnd); } @@ -601,7 +597,7 @@ function beginEdit(triggerEvent) { - //we need to scroll the cell into focus before invoking the editor + // we need to scroll the cell into focus before invoking the editor $scope.grid.api.core.scrollToIfNecessary($scope.row, $scope.col) .then(function () { beginEditAfterScroll(triggerEvent); @@ -743,7 +739,7 @@ cellModel = $parse(modelField); - //get original value from the cell + // get original value from the cell origCellValue = cellModel($scope); html = $scope.col.editableCellTemplate; @@ -754,7 +750,7 @@ html = html.replace(uiGridConstants.CUSTOM_FILTERS, optionFilter); var inputType = 'text'; - switch ($scope.col.colDef.type){ + switch ($scope.col.colDef.type) { case 'boolean': inputType = 'checkbox'; break; @@ -789,8 +785,7 @@ $scope.editDropdownIdLabel = $scope.col.colDef.editDropdownIdLabel ? $scope.col.colDef.editDropdownIdLabel : 'id'; $scope.editDropdownValueLabel = $scope.col.colDef.editDropdownValueLabel ? $scope.col.colDef.editDropdownValueLabel : 'value'; - var cellElement; - var createEditor = function(){ + var createEditor = function() { inEdit = true; cancelBeginEditEvents(); var cellElement = angular.element(html); @@ -806,7 +801,7 @@ createEditor(); } - //stop editing when grid is scrolled + // stop editing when grid is scrolled var deregOnGridScroll = $scope.col.grid.api.core.on.scrollBegin($scope, function () { if ($scope.grid.disableScrolling) { return; @@ -818,7 +813,7 @@ deregOnCancelCellEdit(); }); - //end editing + // end editing var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () { endEdit(); $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue); @@ -827,7 +822,7 @@ deregOnCancelCellEdit(); }); - //cancel editing + // cancel editing var deregOnCancelCellEdit = $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () { cancelEdit(); deregOnCancelCellEdit(); @@ -837,7 +832,7 @@ $scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent); $timeout(function () { - //execute in a timeout to give any complex editor templates a cycle to completely render + // execute in a timeout to give any complex editor templates a cycle to completely render $scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent); }); } @@ -848,15 +843,15 @@ return; } - //sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus - //back to grid here. The focus call needs to be before the $destroy and removal of the control, - //otherwise ng-model-options of UpdateOn: 'blur' will not work. + // sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus + // back to grid here. The focus call needs to be before the $destroy and removal of the control, + // otherwise ng-model-options of UpdateOn: 'blur' will not work. if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { uiGridCtrl.focus(); } var gridCellContentsEl = angular.element($elm.children()[0]); - //remove edit element + // remove edit element editCellScope.$destroy(); var children = $elm.children(); for (var i = 1; i < children.length; i++) { @@ -897,7 +892,6 @@ } return object; } - } }; }]); @@ -935,31 +929,32 @@ if (controllers[1]) { renderContainerCtrl = controllers[1]; } if (controllers[2]) { ngModel = controllers[2]; } - //set focus at start of edit - $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) { + // set focus at start of edit + $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { + // must be in a timeout since it requires a new digest cycle $timeout(function () { $elm[0].focus(); - //only select text if it is not being replaced below in the cellNav viewPortKeyPress + // only select text if it is not being replaced below in the cellNav viewPortKeyPress if ($elm[0].select && ($scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav))) { $elm[0].select(); } else { - //some browsers (Chrome) stupidly, imo, support the w3 standard that number, email, ... - //fields should not allow setSelectionRange. We ignore the error for those browsers - //https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796 + // some browsers (Chrome) stupidly, imo, support the w3 standard that number, email, ... + // fields should not allow setSelectionRange. We ignore the error for those browsers + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796 try { $elm[0].setSelectionRange($elm[0].value.length, $elm[0].value.length); } catch (ex) { - //ignore + // ignore } } }); - //set the keystroke that started the edit event - //we must do this because the BeginEdit is done in a different event loop than the intitial - //keydown event - //fire this event for the keypress that is received + // set the keystroke that started the edit event + // we must do this because the BeginEdit is done in a different event loop than the intitial + // keydown event + // fire this event for the keypress that is received if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { var viewPortKeyDownUnregister = uiGridCtrl.grid.api.cellNav.on.viewPortKeyPress($scope, function (evt, rowCol) { if (uiGridEditService.isStartEditKey(evt)) { @@ -986,6 +981,9 @@ } }); + if ($elm[0]) { + $elm[0].focus(); + } $elm.on('blur', $scope.stopEdit); }); @@ -1007,7 +1005,7 @@ $elm.on('click', function (evt) { if ($elm[0].type !== 'checkbox') { $scope.deepEdit = true; - $timeout(function () { + $scope.$applyAsync(function () { $scope.grid.disableScrolling = true; }); } @@ -1036,7 +1034,7 @@ } } else { - //handle enter and tab for editing not using cellNav + // handle enter and tab for editing not using cellNav switch (evt.keyCode) { case uiGridConstants.keymap.ENTER: // Enter (Leave Field) case uiGridConstants.keymap.TAB: @@ -1096,9 +1094,7 @@ priority: -100, // run after default uiGridEditor directive require: '?ngModel', link: function (scope, element, attrs, ngModel) { - if (angular.version.minor === 2 && attrs.type && attrs.type === 'date' && ngModel) { - ngModel.$formatters.push(function (modelValue) { ngModel.$setValidity(null,(!modelValue || !isNaN(modelValue.getTime()))); return $filter('date')(modelValue, 'yyyy-MM-dd'); @@ -1152,9 +1148,9 @@ var uiGridCtrl = controllers[0]; var renderContainerCtrl = controllers[1]; - //set focus at start of edit + // set focus at start of edit $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { - $timeout(function(){ + $timeout(function() { $elm[0].focus(); }); @@ -1185,7 +1181,7 @@ } } else { - //handle enter and tab for editing not using cellNav + // handle enter and tab for editing not using cellNav switch (evt.keyCode) { case uiGridConstants.keymap.ENTER: // Enter (Leave Field) case uiGridConstants.keymap.TAB: @@ -1225,8 +1221,8 @@ * */ module.directive('uiGridEditFileChooser', - ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', - function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout) { + ['gridUtil', 'uiGridConstants', 'uiGridEditConstants', + function (gridUtil, uiGridConstants, uiGridEditConstants) { return { scope: true, require: ['?^uiGrid', '?^uiGridRenderContainer'], @@ -1235,13 +1231,8 @@ pre: function ($scope, $elm, $attrs) { }, - post: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl, renderContainerCtrl; - if (controllers[0]) { uiGridCtrl = controllers[0]; } - if (controllers[1]) { renderContainerCtrl = controllers[1]; } - var grid = uiGridCtrl.grid; - - var handleFileSelect = function( event ){ + post: function ($scope, $elm) { + function handleFileSelect(event) { var target = event.srcElement || event.target; if (target && target.files && target.files.length > 0) { @@ -1266,13 +1257,13 @@ * * @example *
    -                     *  editFileChooserCallBack: function(gridRow, gridCol, files ){
    +                     *  editFileChooserCallBack: function(gridRow, gridCol, files ) {
                          *    // ignore all but the first file, it can only choose one anyway
                          *    // set the filename into this column
                          *    gridRow.entity.filename = file[0].name;
                          *
                          *    // read the file and set it into a hidden column, which we may do stuff with later
    -                     *    var setFile = function(fileContent){
    +                     *    var setFile = function(fileContent) {
                          *      gridRow.entity.file = fileContent.currentTarget.result;
                          *    };
                          *    var reader = new FileReader();
    @@ -1292,7 +1283,8 @@
                       } else {
                         $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
                       }
    -                };
    +                  $elm[0].removeEventListener('change', handleFileSelect, false);
    +                }
     
                     $elm[0].addEventListener('change', handleFileSelect, false);
     
    @@ -1300,19 +1292,33 @@
                       $elm[0].focus();
                       $elm[0].select();
     
    -                  $elm.on('blur', function (evt) {
    +                  $elm.on('blur', function () {
                         $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
    +                    $elm.off();
                       });
                     });
    -
    -                $scope.$on('$destroy', function unbindEvents() {
    -                  // unbind jquery events to prevent memory leaks
    -                  $elm.off();
    -                  $elm[0].removeEventListener('change', handleFileSelect, false);
    -                });
                   }
                 };
               }
             };
           }]);
     })();
    +
    +angular.module('ui.grid.edit').run(['$templateCache', function($templateCache) {
    +  'use strict';
    +
    +  $templateCache.put('ui-grid/cellEditor',
    +    "
    " + ); + + + $templateCache.put('ui-grid/dropdownEditor', + "
    " + ); + + + $templateCache.put('ui-grid/fileChooserEditor', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.edit.min.js b/src/i18n/ui-grid.edit.min.js new file mode 100644 index 0000000000..d79212a7c3 --- /dev/null +++ b/src/i18n/ui-grid.edit.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.edit",["ui.grid"]);e.constant("uiGridEditConstants",{EDITABLE_CELL_TEMPLATE:/EDITABLE_CELL_TEMPLATE/g,EDITABLE_CELL_DIRECTIVE:/editable_cell_directive/g,events:{BEGIN_CELL_EDIT:"uiGridEventBeginCellEdit",END_CELL_EDIT:"uiGridEventEndCellEdit",CANCEL_CELL_EDIT:"uiGridEventCancelCellEdit"}}),e.service("uiGridEditService",["$q","uiGridConstants","gridUtil",function(o,i,l){var t={initializeGrid:function(e){t.defaultGridOptions(e.options),e.registerColumnBuilder(t.editColumnBuilder),e.edit={};e.api.registerEventsFromObject({edit:{afterCellEdit:function(e,i,t,n){},beginCellEdit:function(e,i,t){},cancelCellEdit:function(e,i){}}})},defaultGridOptions:function(e){e.cellEditableCondition=void 0===e.cellEditableCondition||e.cellEditableCondition,e.enableCellEditOnFocus=void 0!==e.enableCellEditOnFocus&&e.enableCellEditOnFocus},editColumnBuilder:function(i,t,e){var n=[];return i.enableCellEdit=void 0===i.enableCellEdit?void 0===e.enableCellEdit?"object"!==i.type:e.enableCellEdit:i.enableCellEdit,i.cellEditableCondition=void 0===i.cellEditableCondition?e.cellEditableCondition:i.cellEditableCondition,i.enableCellEdit&&(i.editableCellTemplate=i.editableCellTemplate||e.editableCellTemplate||"ui-grid/cellEditor",n.push(l.getTemplate(i.editableCellTemplate).then(function(e){t.editableCellTemplate=e},function(e){throw new Error("Couldn't fetch/use colDef.editableCellTemplate '"+i.editableCellTemplate+"'")}))),i.enableCellEditOnFocus=void 0===i.enableCellEditOnFocus?e.enableCellEditOnFocus:i.enableCellEditOnFocus,o.all(n)},isStartEditKey:function(e){return!(e.metaKey||e.keyCode===i.keymap.ESC||e.keyCode===i.keymap.SHIFT||e.keyCode===i.keymap.CTRL||e.keyCode===i.keymap.ALT||e.keyCode===i.keymap.WIN||e.keyCode===i.keymap.CAPSLOCK||e.keyCode===i.keymap.LEFT||e.keyCode===i.keymap.TAB&&e.shiftKey||e.keyCode===i.keymap.RIGHT||e.keyCode===i.keymap.TAB||e.keyCode===i.keymap.UP||e.keyCode===i.keymap.ENTER&&e.shiftKey||e.keyCode===i.keymap.DOWN||e.keyCode===i.keymap.ENTER)}};return t}]),e.directive("uiGridEdit",["gridUtil","uiGridEditService",function(e,o){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,t,n){o.initializeGrid(n.grid)},post:function(e,i,t,n){}}}}}]),e.directive("uiGridViewport",["uiGridEditConstants",function(l){return{replace:!0,priority:-99998,require:["^uiGrid","^uiGridRenderContainer"],scope:!1,compile:function(){return{post:function(e,i,t,n){var o=n[0];o.grid.api.edit&&o.grid.api.cellNav&&("body"===n[1].containerId&&(e.$on(l.events.CANCEL_CELL_EDIT,function(){o.focus()}),e.$on(l.events.END_CELL_EDIT,function(){o.focus()})))}}}}}]),e.directive("uiGridCell",["$compile","$injector","$timeout","uiGridConstants","uiGridEditConstants","gridUtil","$parse","uiGridEditService","$rootScope","$q",function(b,e,h,T,k,w,_,f,I,G){if(e.has("uiGridCellNavService"))e.get("uiGridCellNavService");return{priority:-100,restrict:"A",scope:!1,require:"?^uiGrid",link:function(E,p,e,n){var C,v,g,i,y,m=!1;if(E.col.colDef.enableCellEdit){var t=function(){},o=function(){},l=function(){E.col.colDef.enableCellEdit&&!1!==E.row.enableCellEdit?E.beginEditEventsWired||d():E.beginEditEventsWired&&D()};l();var r=E.$watch("row",function(e,i){e!==i&&l()});E.$on("$destroy",function(){r(),p.off()})}function d(){p.on("dblclick",s),p.on("touchstart",c),n&&n.grid.api.cellNav&&(o=n.grid.api.cellNav.on.viewPortKeyDown(E,function(e,i){null!==i&&(i.row!==E.row||i.col!==E.col||E.col.colDef.enableCellEditOnFocus||u(e))}),t=n.grid.api.cellNav.on.navigate(E,function(e,i,t){E.col.colDef.enableCellEditOnFocus&&(e.row!==E.row||e.col!==E.col||null!==t&&(!t||"click"!==t.type&&"keydown"!==t.type)||h(function(){s(t)}))})),E.beginEditEventsWired=!0}function c(e){void 0!==e.originalEvent&&void 0!==e.originalEvent&&(e=e.originalEvent),p.on("touchend",a),(i=h(function(){},500)).then(function(){setTimeout(s,0),p.off("touchend",a)}).catch(angular.noop)}function a(){h.cancel(i),p.off("touchend",a)}function D(){p.off("dblclick",s),p.off("keydown",u),p.off("touchstart",c),t(),o(),E.beginEditEventsWired=!1}function u(e){f.isStartEditKey(e)&&s(e)}function s(e){E.grid.api.core.scrollToIfNecessary(E.row,E.col).then(function(){!function(e){if(m)return;if(i=E.col,t=E.row,n=e,t.isSaving||(angular.isFunction(i.colDef.cellEditableCondition)?!i.colDef.cellEditableCondition(E,n):!i.colDef.cellEditableCondition))return;var i,t,n;var o=E.row.getQualifiedColField(E.col);E.col.colDef.editModelField&&(o=w.preEval("row.entity."+E.col.colDef.editModelField));g=_(o),v=g(E),C=(C=(C=E.col.editableCellTemplate).replace(T.MODEL_COL_FIELD,o)).replace(T.COL_FIELD,"grid.getCellValue(row, col)");var l=E.col.colDef.editDropdownFilter?"|"+E.col.colDef.editDropdownFilter:"";C=C.replace(T.CUSTOM_FILTERS,l);var r="text";switch(E.col.colDef.type){case"boolean":r="checkbox";break;case"number":r="number";break;case"date":r="date"}C=C.replace("INPUT_TYPE",r);var d=E.col.colDef.editDropdownOptionsFunction;if(d)G.when(d(E.row.entity,E.col.colDef)).then(function(e){E.editDropdownOptionsArray=e});else{var c=E.col.colDef.editDropdownRowEntityOptionsArrayPath;E.editDropdownOptionsArray=c?function(e,i){var t=(i=(i=i.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");for(;t.length;){var n=t.shift();if(!(n in e))return;e=e[n]}return e}(E.row.entity,c):E.col.colDef.editDropdownOptionsArray}E.editDropdownIdLabel=E.col.colDef.editDropdownIdLabel?E.col.colDef.editDropdownIdLabel:"id",E.editDropdownValueLabel=E.col.colDef.editDropdownValueLabel?E.col.colDef.editDropdownValueLabel:"value";var a=function(){m=!0,D();var e=angular.element(C);p.append(e),y=E.$new(),b(e)(y);var i=angular.element(p.children()[0]);i.addClass("ui-grid-cell-contents-hidden")};I.$$phase?a():E.$apply(a);var u=E.col.grid.api.core.on.scrollBegin(E,function(){E.grid.disableScrolling||(L(),E.grid.api.edit.raise.afterCellEdit(E.row.entity,E.col.colDef,g(E),v),u(),s(),f())}),s=E.$on(k.events.END_CELL_EDIT,function(){L(),E.grid.api.edit.raise.afterCellEdit(E.row.entity,E.col.colDef,g(E),v),s(),u(),f()}),f=E.$on(k.events.CANCEL_CELL_EDIT,function(){!function(){if(E.grid.disableScrolling=!1,!m)return;g.assign(E,v),E.$apply(),E.grid.api.edit.raise.cancelCellEdit(E.row.entity,E.col.colDef),L()}(),f(),u(),s()});E.$broadcast(k.events.BEGIN_CELL_EDIT,e),h(function(){E.grid.api.edit.raise.beginCellEdit(E.row.entity,E.col.colDef,e)})}(e)})}function L(){if(E.grid.disableScrolling=!1,m){n&&n.grid.api.cellNav&&n.focus();var e=angular.element(p.children()[0]);y.$destroy();for(var i=p.children(),t=1;t
    '),e.put("ui-grid/dropdownEditor",'
    '),e.put("ui-grid/fileChooserEditor",'
    ')}]); \ No newline at end of file diff --git a/src/features/empty-base-layer/js/emptyBaseLayer.js b/src/i18n/ui-grid.empty-base-layer.js similarity index 87% rename from src/features/empty-base-layer/js/emptyBaseLayer.js rename to src/i18n/ui-grid.empty-base-layer.js index 6dffaebe10..9497f359c0 100644 --- a/src/features/empty-base-layer/js/emptyBaseLayer.js +++ b/src/i18n/ui-grid.empty-base-layer.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -25,7 +30,7 @@ * @description Services for the empty base layer grid */ module.service('uiGridBaseLayerService', ['gridUtil', '$compile', function (gridUtil, $compile) { - var service = { + return { initializeGrid: function (grid, disableEmptyBaseLayer) { /** @@ -47,7 +52,7 @@ *
    Defaults to true, if the directive is used. *
    Set to false either by setting this attribute or passing false to the directive. */ - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false if (grid.options.enableEmptyGridBaseLayer !== false) { grid.options.enableEmptyGridBaseLayer = !disableEmptyBaseLayer; } @@ -56,6 +61,7 @@ setNumberOfEmptyRows: function(viewportHeight, grid) { var rowHeight = grid.options.rowHeight, rows = Math.ceil(viewportHeight / rowHeight); + if (rows > 0) { grid.baseLayer.emptyRows = []; for (var i = 0; i < rows; i++) { @@ -64,7 +70,6 @@ } } }; - return service; }]); /** @@ -88,10 +93,11 @@ return { require: '^uiGrid', scope: false, - compile: function ($elm, $attrs) { + compile: function () { return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { var disableEmptyBaseLayer = $parse($attrs.uiGridEmptyBaseLayer)($scope) === false; + uiGridBaseLayerService.initializeGrid(uiGridCtrl.grid, disableEmptyBaseLayer); }, post: function ($scope, $elm, $attrs, uiGridCtrl) { @@ -146,7 +152,7 @@ return { priority: -200, scope: false, - compile: function ($elm, $attrs) { + compile: function ($elm) { var emptyBaseLayerContainer = $templateCache.get('ui-grid/emptyBaseLayerContainer'); $elm.prepend(emptyBaseLayerContainer); return { @@ -160,3 +166,12 @@ }]); })(); + +angular.module('ui.grid.emptyBaseLayer').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/emptyBaseLayerContainer', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.empty-base-layer.min.js b/src/i18n/ui-grid.empty-base-layer.min.js new file mode 100644 index 0000000000..b121fb0bf0 --- /dev/null +++ b/src/i18n/ui-grid.empty-base-layer.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.emptyBaseLayer",["ui.grid"]);e.service("uiGridBaseLayerService",["gridUtil","$compile",function(e,i){return{initializeGrid:function(e,i){!(e.baseLayer={emptyRows:[]})!==e.options.enableEmptyGridBaseLayer&&(e.options.enableEmptyGridBaseLayer=!i)},setNumberOfEmptyRows:function(e,i){var r=i.options.rowHeight,t=Math.ceil(e/r);if(0
    ')}]); \ No newline at end of file diff --git a/src/features/expandable/js/expandable.js b/src/i18n/ui-grid.expandable.js similarity index 67% rename from src/features/expandable/js/expandable.js rename to src/i18n/ui-grid.expandable.js index c02b4ee53e..a57ec20933 100644 --- a/src/features/expandable/js/expandable.js +++ b/src/i18n/ui-grid.expandable.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -23,7 +28,7 @@ * * @description Services for the expandable grid */ - module.service('uiGridExpandableService', ['gridUtil', '$compile', function (gridUtil, $compile) { + module.service('uiGridExpandableService', ['gridUtil', function (gridUtil) { var service = { initializeGrid: function (grid) { @@ -31,7 +36,20 @@ grid.expandable.expandedAll = false; /** - * @ngdoc object + * @ngdoc boolean + * @name enableOnDblClickExpand + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Defaults to true. + * @example + *
    +         *    $scope.gridOptions = {
    +         *      onDblClickExpand: false
    +         *    }
    +         *  
    + */ + grid.options.enableOnDblClickExpand = grid.options.enableOnDblClickExpand !== false; + /** + * @ngdoc boolean * @name enableExpandable * @propertyOf ui.grid.expandable.api:GridOptions * @description Whether or not to use expandable feature, allows you to turn off expandable on specific grids @@ -45,6 +63,21 @@ */ grid.options.enableExpandable = grid.options.enableExpandable !== false; + /** + * @ngdoc object + * @name showExpandAllButton + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Whether or not to display the expand all button, allows you to hide expand all button on specific grids + * within your application, or in specific modes on _this_ grid. Defaults to true. + * @example + *
    +         *    $scope.gridOptions = {
    +         *      showExpandAllButton: false
    +         *    }
    +         *  
    + */ + grid.options.showExpandAllButton = grid.options.showExpandAllButton !== false; + /** * @ngdoc object * @name expandableRowHeight @@ -62,7 +95,7 @@ /** * @ngdoc object - * @name + * @name expandableRowHeaderWidth * @propertyOf ui.grid.expandable.api:GridOptions * @description Width in pixels of the expandable column. Defaults to 40 * @example @@ -86,7 +119,7 @@ * } * */ - if ( grid.options.enableExpandable && !grid.options.expandableRowTemplate ){ + if ( grid.options.enableExpandable && !grid.options.expandableRowTemplate ) { gridUtil.logError( 'You have not set the expandableRowTemplate, disabling expandable module' ); grid.options.enableExpandable = false; } @@ -113,20 +146,47 @@ var publicApi = { events: { expandable: { + /** + * @ngdoc event + * @name rowExpandedBeforeStateChanged + * @eventOf ui.grid.expandable.api:PublicApi + * @description raised when row is expanding or collapsing + *
    +               *      gridApi.expandable.on.rowExpandedBeforeStateChanged(scope,function(row, event) {})
    +               * 
    + * @param {scope} scope the application scope + * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event + */ + rowExpandedBeforeStateChanged: function(scope, row, evt) {}, + /** * @ngdoc event * @name rowExpandedStateChanged * @eventOf ui.grid.expandable.api:PublicApi * @description raised when row expanded or collapsed *
    -               *      gridApi.expandable.on.rowExpandedStateChanged(scope,function(row){})
    +               *      gridApi.expandable.on.rowExpandedStateChanged(scope,function(row, event) {})
                    * 
    + * @param {scope} scope the application scope * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event */ - rowExpandedBeforeStateChanged: function(scope,row){ - }, - rowExpandedStateChanged: function (scope, row) { - } + rowExpandedStateChanged: function (scope, row, evt) {}, + + /** + * @ngdoc event + * @name rowExpandedRendered + * @eventOf ui.grid.expandable.api:PublicApi + * @description raised when expanded row is rendered + *
    +               *      gridApi.expandable.on.rowExpandedRendered(scope,function(row, event) {})
    +               * 
    + * @param {scope} scope the application scope + * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event + */ + rowExpandedRendered: function (scope, row, evt) {} } }, @@ -138,14 +198,16 @@ * @methodOf ui.grid.expandable.api:PublicApi * @description Toggle a specific row *
    -               *      gridApi.expandable.toggleRowExpansion(rowEntity);
    +               *      gridApi.expandable.toggleRowExpansion(rowEntity, event);
                    * 
    * @param {object} rowEntity the data entity for the row you want to expand + * @param {Event} [e] event (if exist) */ - toggleRowExpansion: function (rowEntity) { + toggleRowExpansion: function (rowEntity, e) { var row = grid.getRow(rowEntity); + if (row !== null) { - service.toggleRowExpansion(grid, row); + service.toggleRowExpansion(grid, row, e); } }, @@ -196,6 +258,7 @@ */ expandRow: function (rowEntity) { var row = grid.getRow(rowEntity); + if (row !== null && !row.isExpanded) { service.toggleRowExpansion(grid, row); } @@ -209,6 +272,7 @@ */ collapseRow: function (rowEntity) { var row = grid.getRow(rowEntity); + if (row !== null && row.isExpanded) { service.toggleRowExpansion(grid, row); } @@ -231,7 +295,13 @@ grid.api.registerMethodsFromObject(publicApi.methods); }, - toggleRowExpansion: function (grid, row) { + /** + * + * @param grid + * @param row + * @param {Event} [e] event (if exist) + */ + toggleRowExpansion: function (grid, row, e) { // trigger the "before change" event. Can change row height dynamically this way. grid.api.expandable.raise.rowExpandedBeforeStateChanged(row); /** @@ -249,23 +319,35 @@ * */ row.isExpanded = !row.isExpanded; - if (angular.isUndefined(row.expandedRowHeight)){ + if (angular.isUndefined(row.expandedRowHeight)) { row.expandedRowHeight = grid.options.expandableRowHeight; } if (row.isExpanded) { row.height = row.grid.options.rowHeight + row.expandedRowHeight; + grid.expandable.expandedAll = service.getExpandedRows(grid).length === grid.rows.length; } else { row.height = row.grid.options.rowHeight; grid.expandable.expandedAll = false; } - grid.api.expandable.raise.rowExpandedStateChanged(row); + grid.api.expandable.raise.rowExpandedStateChanged(row, e); + + // fire event on render complete + function _tWatcher() { + if (row.expandedRendered) { + grid.api.expandable.raise.rowExpandedRendered(row, e); + } + else { + window.setTimeout(_tWatcher, 1e2); + } + } + _tWatcher(); }, - expandAllRows: function(grid, $scope) { + expandAllRows: function(grid) { grid.renderContainers.body.visibleRowCache.forEach( function(row) { - if (!row.isExpanded) { + if (!row.isExpanded && !(row.entity.subGridOptions && row.entity.subGridOptions.disableRowExpandable)) { service.toggleRowExpansion(grid, row); } }); @@ -314,6 +396,7 @@ * } * */ + module.directive('uiGridExpandable', ['uiGridExpandableService', '$templateCache', function (uiGridExpandableService, $templateCache) { return { @@ -337,16 +420,15 @@ exporterSuppressExport: true, enableColumnResizing: false, enableColumnMenu: false, - width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 40 + width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 30 }; + expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader'); expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader'); uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90); } - }, - post: function ($scope, $elm, $attrs, uiGridCtrl) { - } + post: function ($scope, $elm, $attrs, uiGridCtrl) {} }; } }; @@ -357,8 +439,8 @@ * @name ui.grid.expandable.directive:uiGrid * @description stacks on the uiGrid directive to register child grid with parent row when child is created */ - module.directive('uiGrid', ['uiGridExpandableService', '$templateCache', - function (uiGridExpandableService, $templateCache) { + module.directive('uiGrid', + function () { return { replace: true, priority: 599, @@ -369,8 +451,9 @@ pre: function ($scope, $elm, $attrs, uiGridCtrl) { uiGridCtrl.grid.api.core.on.renderingComplete($scope, function() { - //if a parent grid row is on the scope, then add the parentRow property to this childGrid - if ($scope.row && $scope.row.grid && $scope.row.grid.options && $scope.row.grid.options.enableExpandable) { + // if a parent grid row is on the scope, then add the parentRow property to this childGrid + if ($scope.row && $scope.row.grid && $scope.row.grid.options + && $scope.row.grid.options.enableExpandable) { /** * @ngdoc directive @@ -386,39 +469,35 @@ */ uiGridCtrl.grid.parentRow = $scope.row; - //todo: adjust height on parent row when child grid height changes. we need some sort of gridHeightChanged event + // todo: adjust height on parent row when child grid height changes. we need some sort of gridHeightChanged event // uiGridCtrl.grid.core.on.canvasHeightChanged($scope, function(oldHeight, newHeight) { // uiGridCtrl.grid.parentRow = newHeight; // }); } - }); }, - post: function ($scope, $elm, $attrs, uiGridCtrl) { - - } + post: function ($scope, $elm, $attrs, uiGridCtrl) {} }; } }; - }]); + }); /** * @ngdoc directive * @name ui.grid.expandable.directive:uiGridExpandableRow - * @description directive to render the expandable row template + * @description directive to render the Row template on Expand */ module.directive('uiGridExpandableRow', - ['uiGridExpandableService', '$timeout', '$compile', 'uiGridConstants','gridUtil','$interval', '$log', - function (uiGridExpandableService, $timeout, $compile, uiGridConstants, gridUtil, $interval, $log) { + ['uiGridExpandableService', '$compile', 'uiGridConstants','gridUtil', + function (uiGridExpandableService, $compile, uiGridConstants, gridUtil) { return { replace: false, priority: 0, scope: false, - compile: function () { return { - pre: function ($scope, $elm, $attrs, uiGridCtrl) { + pre: function ($scope, $elm) { gridUtil.getTemplate($scope.grid.options.expandableRowTemplate).then( function (template) { if ($scope.grid.options.expandableRowScope) { @@ -435,6 +514,7 @@ * */ var expandableRowScope = $scope.grid.options.expandableRowScope; + for (var property in expandableRowScope) { if (expandableRowScope.hasOwnProperty(property)) { $scope[property] = expandableRowScope[property]; @@ -442,13 +522,16 @@ } } var expandedRowElement = angular.element(template); - $elm.append(expandedRowElement); + expandedRowElement = $compile(expandedRowElement)($scope); + $elm.append(expandedRowElement); + $scope.row.element = $elm; $scope.row.expandedRendered = true; }); }, - post: function ($scope, $elm, $attrs, uiGridCtrl) { + post: function ($scope, $elm) { + $scope.row.element = $elm; $scope.$on('$destroy', function() { $scope.row.expandedRendered = false; }); @@ -464,15 +547,13 @@ * @description stacks on the uiGridRow directive to add support for expandable rows */ module.directive('uiGridRow', - ['$compile', 'gridUtil', '$templateCache', - function ($compile, gridUtil, $templateCache) { + function () { return { priority: -200, scope: false, - compile: function ($elm, $attrs) { + compile: function () { return { - pre: function ($scope, $elm, $attrs, controllers) { - + pre: function ($scope, $elm) { if (!$scope.grid.options.enableExpandable) { return; } @@ -480,47 +561,33 @@ $scope.expandableRow = {}; $scope.expandableRow.shouldRenderExpand = function () { - var ret = $scope.colContainer.name === 'body' && $scope.grid.options.enableExpandable !== false && $scope.row.isExpanded && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered); - return ret; + return $scope.colContainer.name === 'body' + && $scope.grid.options.enableExpandable !== false + && $scope.row.isExpanded + && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered); }; $scope.expandableRow.shouldRenderFiller = function () { - var ret = $scope.row.isExpanded && ( $scope.colContainer.name !== 'body' || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered)); - return ret; + return $scope.row.isExpanded + && ( + $scope.colContainer.name !== 'body' + || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered)); }; - /* - * Commented out @PaulL1. This has no purpose that I can see, and causes #2964. If this code needs to be reinstated for some - * reason it needs to use drawnWidth, not width, and needs to check column visibility. It should really use render container - * visible column cache also instead of checking column.renderContainer. - function updateRowContainerWidth() { - var grid = $scope.grid; - var colWidth = 0; - grid.columns.forEach( function (column) { - if (column.renderContainer === 'left') { - colWidth += column.width; - } - }); - colWidth = Math.floor(colWidth); - return '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.colContainer.name + ', .grid' + grid.id + - ' .ui-grid-pinned-container-' + $scope.colContainer.name + ' .ui-grid-render-container-' + $scope.colContainer.name + - ' .ui-grid-viewport .ui-grid-canvas .ui-grid-row { width: ' + colWidth + 'px; }'; - } - - if ($scope.colContainer.name === 'left') { - $scope.grid.registerStyleComputation({ - priority: 15, - func: updateRowContainerWidth - }); - }*/ - + if ($scope.grid.options.enableOnDblClickExpand) { + $elm.on('dblclick', function (event) { + // if necessary, it is possible for everyone to stop the processing of a single click OR + // Inside the Config in the output agent to enter a line: + // event.stopPropagation() + $scope.grid.api.expandable.toggleRowExpansion($scope.row.entity, event); + }); + } }, - post: function ($scope, $elm, $attrs, controllers) { - } + post: function ($scope, $elm, $attrs, controllers) {} }; } }; - }]); + }); /** * @ngdoc directive @@ -534,15 +601,16 @@ return { priority: -200, scope: false, - compile: function ($elm, $attrs) { + compile: function ($elm) { - //todo: this adds ng-if watchers to each row even if the grid is not using expandable directive + // todo: this adds ng-if watchers to each row even if the grid is not using expandable directive // or options.enableExpandable == false // The alternative is to compile the template and append to each row in a uiGridRow directive - var rowRepeatDiv = angular.element($elm.children().children()[0]); - var expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller'); - var expandedRowElement = $templateCache.get('ui-grid/expandableRow'); + var rowRepeatDiv = angular.element($elm.children().children()[0]), + expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller'), + expandedRowElement = $templateCache.get('ui-grid/expandableRow'); + rowRepeatDiv.append(expandedRowElement); rowRepeatDiv.append(expandedRowFillerElement); return { @@ -556,3 +624,27 @@ }]); })(); + +angular.module('ui.grid.expandable').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/expandableRow', + "
    " + ); + + + $templateCache.put('ui-grid/expandableRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/expandableScrollFiller', + "
     
    " + ); + + + $templateCache.put('ui-grid/expandableTopRowHeader', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.expandable.min.js b/src/i18n/ui-grid.expandable.min.js new file mode 100644 index 0000000000..29545ddc02 --- /dev/null +++ b/src/i18n/ui-grid.expandable.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.expandable",["ui.grid"]);e.service("uiGridExpandableService",["gridUtil",function(n){var a={initializeGrid:function(o){o.expandable={},o.expandable.expandedAll=!1,o.options.enableOnDblClickExpand=!1!==o.options.enableOnDblClickExpand,o.options.enableExpandable=!1!==o.options.enableExpandable,o.options.showExpandAllButton=!1!==o.options.showExpandAllButton,o.options.expandableRowHeight=o.options.expandableRowHeight||150,o.options.expandableRowHeaderWidth=o.options.expandableRowHeaderWidth||40,o.options.enableExpandable&&!o.options.expandableRowTemplate&&(n.logError("You have not set the expandableRowTemplate, disabling expandable module"),o.options.enableExpandable=!1);var e={events:{expandable:{rowExpandedBeforeStateChanged:function(e,n,i){},rowExpandedStateChanged:function(e,n,i){},rowExpandedRendered:function(e,n,i){}}},methods:{expandable:{toggleRowExpansion:function(e,n){var i=o.getRow(e);null!==i&&a.toggleRowExpansion(o,i,n)},expandAllRows:function(){a.expandAllRows(o)},collapseAllRows:function(){a.collapseAllRows(o)},toggleAllRows:function(){a.toggleAllRows(o)},expandRow:function(e){var n=o.getRow(e);null===n||n.isExpanded||a.toggleRowExpansion(o,n)},collapseRow:function(e){var n=o.getRow(e);null!==n&&n.isExpanded&&a.toggleRowExpansion(o,n)},getExpandedRows:function(){return a.getExpandedRows(o).map(function(e){return e.entity})}}}};o.api.registerEventsFromObject(e.events),o.api.registerMethodsFromObject(e.methods)},toggleRowExpansion:function(n,i,o){n.api.expandable.raise.rowExpandedBeforeStateChanged(i),i.isExpanded=!i.isExpanded,angular.isUndefined(i.expandedRowHeight)&&(i.expandedRowHeight=n.options.expandableRowHeight),i.isExpanded?(i.height=i.grid.options.rowHeight+i.expandedRowHeight,n.expandable.expandedAll=a.getExpandedRows(n).length===n.rows.length):(i.height=i.grid.options.rowHeight,n.expandable.expandedAll=!1),n.api.expandable.raise.rowExpandedStateChanged(i,o),function e(){i.expandedRendered?n.api.expandable.raise.rowExpandedRendered(i,o):window.setTimeout(e,100)}()},expandAllRows:function(n){n.renderContainers.body.visibleRowCache.forEach(function(e){e.isExpanded||e.entity.subGridOptions&&e.entity.subGridOptions.disableRowExpandable||a.toggleRowExpansion(n,e)}),n.expandable.expandedAll=!0,n.queueGridRefresh()},collapseAllRows:function(n){n.renderContainers.body.visibleRowCache.forEach(function(e){e.isExpanded&&a.toggleRowExpansion(n,e)}),n.expandable.expandedAll=!1,n.queueGridRefresh()},toggleAllRows:function(e){e.expandable.expandedAll?a.collapseAllRows(e):a.expandAllRows(e)},getExpandedRows:function(e){return e.rows.filter(function(e){return e.isExpanded})}};return a}]),e.directive("uiGridExpandable",["uiGridExpandableService","$templateCache",function(d,l){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,n,i,o){if(d.initializeGrid(o.grid),o.grid.options.enableExpandable&&!1!==o.grid.options.enableExpandableRowHeader){var a={name:"expandableButtons",displayName:"",exporterSuppressExport:!0,enableColumnResizing:!1,enableColumnMenu:!1,width:o.grid.options.expandableRowHeaderWidth||30};a.cellTemplate=l.get("ui-grid/expandableRowHeader"),a.headerCellTemplate=l.get("ui-grid/expandableTopRowHeader"),o.grid.addRowHeaderColumn(a,-90)}},post:function(e,n,i,o){}}}}}]),e.directive("uiGrid",function(){return{replace:!0,priority:599,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,n,i,o){o.grid.api.core.on.renderingComplete(e,function(){e.row&&e.row.grid&&e.row.grid.options&&e.row.grid.options.enableExpandable&&(o.grid.parentRow=e.row)})},post:function(e,n,i,o){}}}}}),e.directive("uiGridExpandableRow",["uiGridExpandableService","$compile","uiGridConstants","gridUtil",function(e,l,n,i){return{replace:!1,priority:0,scope:!1,compile:function(){return{pre:function(a,d){i.getTemplate(a.grid.options.expandableRowTemplate).then(function(e){if(a.grid.options.expandableRowScope){var n=a.grid.options.expandableRowScope;for(var i in n)n.hasOwnProperty(i)&&(a[i]=n[i])}var o=angular.element(e);o=l(o)(a),d.append(o),a.row.element=d,a.row.expandedRendered=!0})},post:function(e,n){e.row.element=n,e.$on("$destroy",function(){e.row.expandedRendered=!1})}}}}}]),e.directive("uiGridRow",function(){return{priority:-200,scope:!1,compile:function(){return{pre:function(n,e){n.grid.options.enableExpandable&&(n.expandableRow={},n.expandableRow.shouldRenderExpand=function(){return"body"===n.colContainer.name&&!1!==n.grid.options.enableExpandable&&n.row.isExpanded&&(!n.grid.isScrollingVertically||n.row.expandedRendered)},n.expandableRow.shouldRenderFiller=function(){return n.row.isExpanded&&("body"!==n.colContainer.name||n.grid.isScrollingVertically&&!n.row.expandedRendered)},n.grid.options.enableOnDblClickExpand&&e.on("dblclick",function(e){n.grid.api.expandable.toggleRowExpansion(n.row.entity,e)}))},post:function(e,n,i,o){}}}}}),e.directive("uiGridViewport",["$compile","gridUtil","$templateCache",function(e,n,a){return{priority:-200,scope:!1,compile:function(e){var n=angular.element(e.children().children()[0]),i=a.get("ui-grid/expandableScrollFiller"),o=a.get("ui-grid/expandableRow");return n.append(o),n.append(i),{pre:function(e,n,i,o){},post:function(e,n,i,o){}}}}}])}(),angular.module("ui.grid.expandable").run(["$templateCache",function(e){"use strict";e.put("ui-grid/expandableRow",'
    '),e.put("ui-grid/expandableRowHeader",'
    '),e.put("ui-grid/expandableScrollFiller","
     
    "),e.put("ui-grid/expandableTopRowHeader",'
    ')}]); \ No newline at end of file diff --git a/src/features/exporter/js/exporter.js b/src/i18n/ui-grid.exporter.js old mode 100755 new mode 100644 similarity index 66% rename from src/features/exporter/js/exporter.js rename to src/i18n/ui-grid.exporter.js index f5281edaa4..070ca7b693 --- a/src/features/exporter/js/exporter.js +++ b/src/i18n/ui-grid.exporter.js @@ -1,4 +1,9 @@ -/* global pdfMake */ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +/* global ExcelBuilder */ /* global console */ (function () { @@ -60,6 +65,8 @@ */ module.constant('uiGridExporterConstants', { featureName: 'exporter', + rowHeaderColName: 'treeBaseRowHeaderCol', + selectionRowHeaderColName: 'selectionRowHeaderCol', ALL: 'all', VISIBLE: 'visible', SELECTED: 'selected', @@ -74,16 +81,15 @@ * * @description Services for exporter feature */ - module.service('uiGridExporterService', ['$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', - function ($q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) { - + module.service('uiGridExporterService', ['$filter', '$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', + function ($filter, $q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) { var service = { delay: 100, initializeGrid: function (grid) { - //add feature namespace and any properties to grid for needed state + // add feature namespace and any properties to grid for needed state grid.exporter = {}; this.defaultGridOptions(grid.options); @@ -132,6 +138,21 @@ */ pdfExport: function (rowTypes, colTypes) { service.pdfExport(grid, rowTypes, colTypes); + }, + /** + * @ngdoc function + * @name excelExport + * @methodOf ui.grid.exporter.api:PublicApi + * @description Exports rows from the grid in excel format, + * the data exported is selected based on the provided options + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE + */ + excelExport: function (rowTypes, colTypes) { + service.excelExport(grid, rowTypes, colTypes); } } } @@ -141,12 +162,12 @@ grid.api.registerMethodsFromObject(publicApi.methods); - if (grid.api.core.addToGridMenu){ + if (grid.api.core.addToGridMenu) { service.addToMenu( grid ); } else { // order of registration is not guaranteed, register in a little while $interval( function() { - if (grid.api.core.addToGridMenu){ + if (grid.api.core.addToGridMenu) { service.addToMenu( grid ); } }, this.delay, 1); @@ -155,7 +176,7 @@ }, defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.exporter.api:GridOptions @@ -225,6 +246,24 @@ *
    Defaults to 'download.pdf' */ gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf'; + /** + * @ngdoc object + * @name exporterExcelFilename + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window) + *
    Defaults to 'download.xlsx' + */ + gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx'; + + /** + * @ngdoc object + * @name exporterExcelSheetName + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default sheetname to use when saving the downloaded to excel + *
    Defaults to 'Sheet1' + */ + gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1'; + /** * @ngdoc object * @name exporterOlderExcelCompatibility @@ -383,7 +422,7 @@ /** * @ngdoc object * @name exporterMenuAllData - * @porpertyOf ui.grid.exporter.api:GridOptions + * @propertyOf ui.grid.exporter.api:GridOptions * @description Add export all data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. */ gridOptions.exporterMenuAllData = gridOptions.exporterMenuAllData !== undefined ? gridOptions.exporterMenuAllData : true; @@ -391,7 +430,7 @@ /** * @ngdoc object * @name exporterMenuVisibleData - * @porpertyOf ui.grid.exporter.api:GridOptions + * @propertyOf ui.grid.exporter.api:GridOptions * @description Add export visible data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. */ gridOptions.exporterMenuVisibleData = gridOptions.exporterMenuVisibleData !== undefined ? gridOptions.exporterMenuVisibleData : true; @@ -399,7 +438,7 @@ /** * @ngdoc object * @name exporterMenuSelectedData - * @porpertyOf ui.grid.exporter.api:GridOptions + * @propertyOf ui.grid.exporter.api:GridOptions * @description Add export selected data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. */ gridOptions.exporterMenuSelectedData = gridOptions.exporterMenuSelectedData !== undefined ? gridOptions.exporterMenuSelectedData : true; @@ -407,7 +446,7 @@ /** * @ngdoc object * @name exporterMenuCsv - * @propertyOf ui.grid.exporter.api:GridOptions + * @propertyOf ui.grid.exporter.api:GridOptions * @description Add csv export menu items to the ui-grid grid menu, if it's present. Defaults to true. */ gridOptions.exporterMenuCsv = gridOptions.exporterMenuCsv !== undefined ? gridOptions.exporterMenuCsv : true; @@ -420,6 +459,14 @@ */ gridOptions.exporterMenuPdf = gridOptions.exporterMenuPdf !== undefined ? gridOptions.exporterMenuPdf : true; + /** + * @ngdoc object + * @name exporterMenuExcel + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add excel export menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuExcel = gridOptions.exporterMenuExcel !== undefined ? gridOptions.exporterMenuExcel : true; + /** * @ngdoc object * @name exporterPdfCustomFormatter @@ -468,7 +515,7 @@ * * @example *
    -           *   gridOptions.exporterHeaderFilter = function( displayName ){ return 'col: ' + name; };
    +           *   gridOptions.exporterHeaderFilter = function( displayName ) { return 'col: ' + name; };
                * 
    * OR *
    @@ -490,21 +537,135 @@
                *
                * @param {Grid} grid provides the grid in case you have need of it
                * @param {GridRow} row the row from which the data comes
    -           * @param {GridCol} col the column from which the data comes
    +           * @param {GridColumn} col the column from which the data comes
    +           * @param {object} value the value for your massaging
    +           * @returns {object} you must return the massaged value ready for exporting
    +           *
    +           * @example
    +           * 
    +           *   gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
    +           *     if ( col.name === 'status' ) {
    +           *       value = decodeStatus( value );
    +           *     }
    +           *     return value;
    +           *   }
    +           * 
    + */ + gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : defaultExporterFieldCallback; + + /** + * @ngdoc function + * @name exporterFieldFormatCallback + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to call for each field before exporting it. Allows + * general object to be return to modify the format of a cell in the case of + * excel exports + * + * The method is called once for each field exported, and provides the grid, the + * gridCol and the GridRow for you to use as context in massaging the data. + * + * @param {Grid} grid provides the grid in case you have need of it + * @param {GridRow} row the row from which the data comes + * @param {GridColumn} col the column from which the data comes * @param {object} value the value for your massaging * @returns {object} you must return the massaged value ready for exporting * * @example *
    -           *   gridOptions.exporterFieldCallback = function ( grid, row, col, value ){
    -           *     if ( col.name === 'status' ){
    +           *   gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
    +           *     if ( col.name === 'status' ) {
                *       value = decodeStatus( value );
                *     }
                *     return value;
                *   }
                * 
    */ - gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : function( grid, row, col, value ) { return value; }; + gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; }; + + /** + * @ngdoc function + * @name exporterExcelCustomFormatters + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to call to setup formatters and store on docDefinition. + * + * The method is called at the start and can setup all the formatters to export to excel + * + * @param {Grid} grid provides the grid in case you have need of it + * @param {Workbook} row the row from which the data comes + * @param {docDefinition} The docDefinition that will have styles as a object to store formatters + * @returns {docDefinition} Updated docDefinition with formatter styles + * + * @example + *
    +           *   gridOptions.exporterExcelCustomFormatters = function(grid, workbook, docDefinition) {
    +           *     const formatters = {};
    +           *     const stylesheet = workbook.getStyleSheet();
    +           *     const headerFormatDefn = {
    +           *       'font': { 'size': 11, 'fontName': 'Calibri', 'bold': true },
    +           *       'alignment': { 'wrapText': false }
    +           *     };
    +           *
    +           *     formatters['header'] = headerFormatter;
    +           *     Object.assign(docDefinition.styles , formatters);
    +           *     grid.docDefinition = docDefinition;
    +           *     return docDefinition;
    +           *   }
    +           * 
    + */ + gridOptions.exporterExcelCustomFormatters = gridOptions.exporterExcelCustomFormatters ? gridOptions.exporterExcelCustomFormatters : function( grid, workbook, docDefinition ) { return docDefinition; }; + + /** + * @ngdoc function + * @name exporterExcelHeader + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to write formatted header data to sheet. + * + * The method is called to provide custom header building for Excel. This data comes before the grid header + * + * @param {grid} grid provides the grid in case you have need of it + * @param {Workbook} row the row from which the data comes + * @param {Sheet} the sheet to insert data + * @param {docDefinition} The docDefinition that will have styles as a object to store formatters + * @returns {docDefinition} Updated docDefinition with formatter styles + * + * @example + *
    +           *   gridOptions.exporterExcelCustomFormatters = function (grid, workbook, sheet, docDefinition) {
    +           *      const headerFormatter = docDefinition.styles['header'];
    +           *      let cols = [];
    +           *      // push data in A1 cell with metadata formatter
    +           *      cols.push({ value: 'Summary Report', metadata: {style: headerFormatter.id} });
    +           *      sheet.data.push(cols);
    +           *   }
    +           * 
    + */ + gridOptions.exporterExcelHeader = gridOptions.exporterExcelHeader ? gridOptions.exporterExcelHeader : function( grid, workbook, sheet, docDefinition ) { return null; }; + + + /** + * @ngdoc object + * @name exporterColumnScaleFactor + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A scaling factor to divide the drawnwidth of a column to convert to target excel column + * format size + * @example + * In this example we add a number to divide the drawnwidth of a column to get the excel width. + *
    Defaults to 3.5 + */ + gridOptions.exporterColumnScaleFactor = gridOptions.exporterColumnScaleFactor ? gridOptions.exporterColumnScaleFactor : 3.5; + + /** + * @ngdoc object + * @name exporterFieldApplyFilters + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Defaults to false, which leads to filters being evaluated on export * + * + * @example + *
    +           *   gridOptions.exporterFieldApplyFilters = true;
    +           * 
    + */ + gridOptions.exporterFieldApplyFilters = gridOptions.exporterFieldApplyFilters === true; /** * @ngdoc function @@ -540,7 +701,7 @@ * } *
    */ - if ( gridOptions.exporterAllDataFn == null && gridOptions.exporterAllDataPromise ) { + if ( gridOptions.exporterAllDataFn === null && gridOptions.exporterAllDataPromise ) { gridOptions.exporterAllDataFn = gridOptions.exporterAllDataPromise; } }, @@ -558,7 +719,7 @@ grid.api.core.addToGridMenu( grid, [ { title: i18nService.getSafeText('gridMenu.exporterAllAsCsv'), - action: function ($event) { + action: function () { grid.api.exporter.csvExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); }, shown: function() { @@ -568,7 +729,7 @@ }, { title: i18nService.getSafeText('gridMenu.exporterVisibleAsCsv'), - action: function ($event) { + action: function () { grid.api.exporter.csvExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); }, shown: function() { @@ -578,7 +739,7 @@ }, { title: i18nService.getSafeText('gridMenu.exporterSelectedAsCsv'), - action: function ($event) { + action: function () { grid.api.exporter.csvExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); }, shown: function() { @@ -589,7 +750,7 @@ }, { title: i18nService.getSafeText('gridMenu.exporterAllAsPdf'), - action: function ($event) { + action: function () { grid.api.exporter.pdfExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); }, shown: function() { @@ -599,7 +760,7 @@ }, { title: i18nService.getSafeText('gridMenu.exporterVisibleAsPdf'), - action: function ($event) { + action: function () { grid.api.exporter.pdfExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); }, shown: function() { @@ -609,7 +770,7 @@ }, { title: i18nService.getSafeText('gridMenu.exporterSelectedAsPdf'), - action: function ($event) { + action: function () { grid.api.exporter.pdfExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); }, shown: function() { @@ -617,6 +778,37 @@ ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 ); }, order: grid.options.exporterMenuItemOrder + 5 + }, + { + title: i18nService.getSafeText('gridMenu.exporterAllAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuAllData; + }, + order: grid.options.exporterMenuItemOrder + 6 + }, + { + title: i18nService.getSafeText('gridMenu.exporterVisibleAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuVisibleData; + }, + order: grid.options.exporterMenuItemOrder + 7 + }, + { + title: i18nService.getSafeText('gridMenu.exporterSelectedAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuSelectedData && + ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 ); + }, + order: grid.options.exporterMenuItemOrder + 8 } ]); }, @@ -666,8 +858,8 @@ loadAllDataIfNeeded: function (grid, rowTypes, colTypes) { if ( rowTypes === uiGridExporterConstants.ALL && grid.rows.length !== grid.options.totalItems && grid.options.exporterAllDataFn) { return grid.options.exporterAllDataFn() - .then(function() { - grid.modifyRows(grid.options.data); + .then(function(allData) { + grid.modifyRows(allData); }); } else { var deferred = $q.defer(); @@ -701,35 +893,37 @@ * uiGridExporterConstants.SELECTED */ getColumnHeaders: function (grid, colTypes) { - var headers = []; - var columns; + var headers = [], + columns; - if ( colTypes === uiGridExporterConstants.ALL ){ + if ( colTypes === uiGridExporterConstants.ALL ) { columns = grid.columns; } else { - var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : []; - var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : []; - var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : []; + var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [], + bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [], + rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ) { return column.visible; } ) : []; - columns = leftColumns.concat(bodyColumns,rightColumns); + columns = leftColumns.concat(bodyColumns, rightColumns); } - columns.forEach( function( gridCol, index ) { - if ( gridCol.colDef.exporterSuppressExport !== true && - grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){ - headers.push({ + columns.forEach( function( gridCol ) { + // $$hashKey check since when grouping and sorting pragmatically this ends up in export. Filtering it out + if ( gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' && + grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ) { + var headerEntry = { name: gridCol.field, - displayName: grid.options.exporterHeaderFilter ? ( grid.options.exporterHeaderFilterUseName ? grid.options.exporterHeaderFilter(gridCol.name) : grid.options.exporterHeaderFilter(gridCol.displayName) ) : gridCol.displayName, + displayName: getDisplayName(grid, gridCol), width: gridCol.drawnWidth ? gridCol.drawnWidth : gridCol.width, - align: gridCol.colDef.type === 'number' ? 'right' : 'left' - }); + align: gridCol.colDef.align ? gridCol.colDef.align : (gridCol.colDef.type === 'number' ? 'right' : 'left') + }; + + headers.push(headerEntry); } }); return headers; }, - /** * @ngdoc property * @propertyOf ui.grid.exporter.api:ColumnDef @@ -739,12 +933,12 @@ * valid pdfMake alignment option. */ - /** * @ngdoc object * @name ui.grid.exporter.api:GridRow * @description GridRow settings for exporter */ + /** * @ngdoc object * @name exporterEnableExporting @@ -754,6 +948,59 @@ *
    Defaults to true */ + /** + * @ngdoc function + * @name getRowsFromNode + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Gets rows from a node. If the node is grouped it will + * recurse down into the children to get to the raw data element + * which is a row without children (a leaf). + * @param {Node} aNode the tree node on the grid + * @returns {Array} an array with all child nodes from aNode + */ + getRowsFromNode: function(aNode) { + var rows = []; + + // Push parent node if it is not undefined and has values other than 'children' + var nodeKeys = aNode ? Object.keys(aNode) : ['children']; + if (nodeKeys.length > 1 || nodeKeys[0] != 'children') { + rows.push(aNode); + } + + if (aNode && aNode.children && aNode.children.length > 0) { + for (var i = 0; i < aNode.children.length; i++) { + rows = rows.concat(this.getRowsFromNode(aNode.children[i])); + } + } + return rows; + }, + /** + * @ngdoc function + * @name getDataSorted + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Gets rows from a node. If the node is grouped it will + * recurse down into the children to get to the raw data element + * which is a row without children (a leaf). If the grid is not + * grouped this will return just the raw rows + * @param {Grid} grid the grid from which data should be exported + * @returns {Array} an array of leaf nodes + */ + getDataSorted: function (grid) { + if (!grid.treeBase || grid.treeBase.numberLevels === 0) { + return grid.rows; + } + var rows = []; + + for (var i = 0; i< grid.treeBase.tree.length; i++) { + var nodeRows = this.getRowsFromNode(grid.treeBase.tree[i]); + + for (var j = 0; j 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : ''; + var self = this, + bareHeaders = exportColumnHeaders.map(function(header) { return { value: header.displayName };}), + csv = bareHeaders.length > 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : ''; csv += exportData.map(this.formatRowAsCsv(this, separator)).join('\n'); @@ -860,8 +1109,8 @@ * @description Renders a single field as a csv field, including * quotes around the value * @param {exporterService} exporter pass in exporter - * @param {array} row the row to be turned into a csv string - * @returns {string} a csv-ified version of the row + * @param {string} separator the string to be used to join the row data + * @returns {function} A function that returns a csv-ified version of the row */ formatRowAsCsv: function (exporter, separator) { return function (row) { @@ -892,15 +1141,17 @@ if (typeof(field.value) === 'string') { return '"' + field.value.replace(/"/g,'""') + '"'; } - + if (typeof(field.value) === 'object' && !(field.value instanceof Date)) { + return '"' + JSON.stringify(field.value).replace(/"/g,'""') + '"'; + } + // if field type is date, numberStr return JSON.stringify(field.value); }, - /** * @ngdoc function * @name isIE - * @methodOf ui.grid.exporter.service:uiGridExporterService + * @methodOf ui.grid.exporter.service:uiGridExporterService * @description Checks whether current browser is IE and returns it's version if it is */ isIE: function () { @@ -918,22 +1169,23 @@ /** * @ngdoc function * @name downloadFile - * @methodOf ui.grid.exporter.service:uiGridExporterService + * @methodOf ui.grid.exporter.service:uiGridExporterService * @description Triggers download of a csv file. Logic provided * by @cssensei (from his colleagues at https://github.com/ifeelgoods) in issue #2391 * @param {string} fileName the filename we'd like our file to be * given * @param {string} csvContent the csv content that we'd like to * download as a file + * @param {string} columnSeparator The separator to be used by the columns * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF) * @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X') */ downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) { - var D = document; - var a = D.createElement('a'); - var strMimeType = 'application/octet-stream;charset=utf-8'; - var rawFile; - var ieVersion = this.isIE(); + var D = document, + a = D.createElement('a'), + strMimeType = 'application/octet-stream;charset=utf-8', + rawFile, + ieVersion = this.isIE(); if (exporterIsExcelCompatible) { csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent; @@ -951,6 +1203,7 @@ if (ieVersion) { var frame = D.createElement('iframe'); + document.body.appendChild(frame); frame.contentWindow.document.open('text/html', 'replace'); @@ -963,7 +1216,7 @@ return true; } - //html5 A[download] + // html5 A[download] if ('download' in a) { var blob = new Blob( [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent], @@ -972,7 +1225,7 @@ rawFile = URL.createObjectURL(blob); a.setAttribute('download', fileName); } else { - rawFile = 'data:' + strMimeType + ',' + encodeURIComponent(csvContent); + rawFile = 'data: ' + strMimeType + ',' + encodeURIComponent(csvContent); a.setAttribute('target', '_blank'); } @@ -1012,12 +1265,13 @@ */ pdfExport: function (grid, rowTypes, colTypes) { var self = this; + this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function () { - var exportColumnHeaders = self.getColumnHeaders(grid, colTypes); - var exportData = self.getData(grid, rowTypes, colTypes); - var docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData); + var exportColumnHeaders = self.getColumnHeaders(grid, colTypes), + exportData = self.getData(grid, rowTypes, colTypes), + docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData); - if (self.isIE() || navigator.appVersion.indexOf("Edge") !== -1) { + if (self.isIE() || navigator.appVersion.indexOf('Edge') !== -1) { self.downloadPDF(grid.options.exporterPdfFilename, docDefinition); } else { pdfMake.createPdf(docDefinition).open(); @@ -1039,11 +1293,9 @@ * and get a blob from */ downloadPDF: function (fileName, docDefinition) { - var D = document; - var a = D.createElement('a'); - var strMimeType = 'application/octet-stream;charset=utf-8'; - var rawFile; - var ieVersion; + var D = document, + a = D.createElement('a'), + ieVersion; ieVersion = this.isIE(); // This is now a boolean value var doc = pdfMake.createPdf(docDefinition); @@ -1066,7 +1318,7 @@ var frame = D.createElement('iframe'); document.body.appendChild(frame); - frame.contentWindow.document.open("text/html", "replace"); + frame.contentWindow.document.open('text/html', 'replace'); frame.contentWindow.document.write(blob); frame.contentWindow.document.close(); frame.contentWindow.focus(); @@ -1122,19 +1374,19 @@ defaultStyle: grid.options.exporterPdfDefaultStyle }; - if ( grid.options.exporterPdfLayout ){ + if ( grid.options.exporterPdfLayout ) { docDefinition.layout = grid.options.exporterPdfLayout; } - if ( grid.options.exporterPdfHeader ){ + if ( grid.options.exporterPdfHeader ) { docDefinition.header = grid.options.exporterPdfHeader; } - if ( grid.options.exporterPdfFooter ){ + if ( grid.options.exporterPdfFooter ) { docDefinition.footer = grid.options.exporterPdfFooter; } - if ( grid.options.exporterPdfCustomFormatter ){ + if ( grid.options.exporterPdfCustomFormatter ) { docDefinition = grid.options.exporterPdfCustomFormatter( docDefinition ); } return docDefinition; @@ -1165,15 +1417,17 @@ */ calculatePdfHeaderWidths: function ( grid, exportHeaders ) { var baseGridWidth = 0; - exportHeaders.forEach( function(value){ - if (typeof(value.width) === 'number'){ + + exportHeaders.forEach(function(value) { + if (typeof(value.width) === 'number') { baseGridWidth += value.width; } }); var extraColumns = 0; - exportHeaders.forEach( function(value){ - if (value.width === '*'){ + + exportHeaders.forEach(function(value) { + if (value.width === '*') { extraColumns += 100; } if (typeof(value.width) === 'string' && value.width.match(/(\d)*%/)) { @@ -1189,7 +1443,6 @@ return exportHeaders.map(function( header ) { return header.width === '*' ? header.width : header.width * grid.options.exporterPdfMaxGridWidth / gridWidth; }); - }, /** @@ -1222,6 +1475,7 @@ */ formatFieldAsPdfString: function (field) { var returnVal; + if (field.value == null) { // we want to catch anything null-ish, hence just == not === returnVal = ''; } else if (typeof(field.value) === 'number') { @@ -1230,20 +1484,195 @@ returnVal = (field.value ? 'TRUE' : 'FALSE') ; } else if (typeof(field.value) === 'string') { returnVal = field.value.replace(/"/g,'""'); + } else if (field.value instanceof Date) { + returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,''); + } else if (typeof(field.value) === 'object') { + returnVal = field.value; } else { returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,''); } - if (field.alignment && typeof(field.alignment) === 'string' ){ + if (field.alignment && typeof(field.alignment) === 'string' ) { returnVal = { text: returnVal, alignment: field.alignment }; } return returnVal; + }, + + /** + * @ngdoc function + * @name formatAsExcel + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Formats the column headers and data as a excel, + * and sends that data to the user + * @param {array} exportColumnHeaders an array of column headers, + * where each header is an object with name, width and maybe alignment + * @param {array} exportData an array of rows, where each row is + * an array of column data + * @param {string} separator a string that represents the separator to be used in the csv file + * @returns {string} csv the formatted excel as a string + */ + formatAsExcel: function (exportColumnHeaders, exportData, workbook, sheet, docDefinition) { + var bareHeaders = exportColumnHeaders.map(function(header) {return { value: header.displayName };}); + + var sheetData = []; + var headerData = []; + for (var i = 0; i < bareHeaders.length; i++) { + // TODO - probably need callback to determine header value and header styling + var exportStyle = 'header'; + switch (exportColumnHeaders[i].align) { + case 'center': + exportStyle = 'headerCenter'; + break; + case 'right': + exportStyle = 'headerRight'; + break; + } + var metadata = (docDefinition.styles && docDefinition.styles[exportStyle]) ? {style: docDefinition.styles[exportStyle].id} : null; + headerData.push({value: bareHeaders[i].value, metadata: metadata}); + } + sheetData.push(headerData); + + var result = exportData.map(this.formatRowAsExcel(this, workbook, sheet)); + for (var j = 0; jLINK_LABEL" + ); + +}]); diff --git a/src/i18n/ui-grid.exporter.min.js b/src/i18n/ui-grid.exporter.min.js new file mode 100644 index 0000000000..4561d7fe7c --- /dev/null +++ b/src/i18n/ui-grid.exporter.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.exporter",["ui.grid"]);e.constant("uiGridExporterConstants",{featureName:"exporter",rowHeaderColName:"treeBaseRowHeaderCol",selectionRowHeaderColName:"selectionRowHeaderCol",ALL:"all",VISIBLE:"visible",SELECTED:"selected",CSV_CONTENT:"CSV_CONTENT",BUTTON_LABEL:"BUTTON_LABEL",FILE_NAME:"FILE_NAME"}),e.service("uiGridExporterService",["$filter","$q","uiGridExporterConstants","gridUtil","$compile","$interval","i18nService",function(p,n,x,d,e,t,r){var o={delay:100,initializeGrid:function(r){r.exporter={},this.defaultGridOptions(r.options);var e={events:{exporter:{}},methods:{exporter:{csvExport:function(e,t){o.csvExport(r,e,t)},pdfExport:function(e,t){o.pdfExport(r,e,t)},excelExport:function(e,t){o.excelExport(r,e,t)}}}};r.api.registerEventsFromObject(e.events),r.api.registerMethodsFromObject(e.methods),r.api.core.addToGridMenu?o.addToMenu(r):t(function(){r.api.core.addToGridMenu&&o.addToMenu(r)},this.delay,1)},defaultGridOptions:function(e){e.exporterSuppressMenu=!0===e.exporterSuppressMenu,e.exporterMenuLabel=e.exporterMenuLabel?e.exporterMenuLabel:"Export",e.exporterSuppressColumns=e.exporterSuppressColumns?e.exporterSuppressColumns:[],e.exporterCsvColumnSeparator=e.exporterCsvColumnSeparator?e.exporterCsvColumnSeparator:",",e.exporterCsvFilename=e.exporterCsvFilename?e.exporterCsvFilename:"download.csv",e.exporterPdfFilename=e.exporterPdfFilename?e.exporterPdfFilename:"download.pdf",e.exporterExcelFilename=e.exporterExcelFilename?e.exporterExcelFilename:"download.xlsx",e.exporterExcelSheetName=e.exporterExcelSheetName?e.exporterExcelSheetName:"Sheet1",e.exporterOlderExcelCompatibility=!0===e.exporterOlderExcelCompatibility,e.exporterIsExcelCompatible=!0===e.exporterIsExcelCompatible,e.exporterMenuItemOrder=e.exporterMenuItemOrder?e.exporterMenuItemOrder:200,e.exporterPdfDefaultStyle=e.exporterPdfDefaultStyle?e.exporterPdfDefaultStyle:{fontSize:11},e.exporterPdfTableStyle=e.exporterPdfTableStyle?e.exporterPdfTableStyle:{margin:[0,5,0,15]},e.exporterPdfTableHeaderStyle=e.exporterPdfTableHeaderStyle?e.exporterPdfTableHeaderStyle:{bold:!0,fontSize:12,color:"black"},e.exporterPdfHeader=e.exporterPdfHeader?e.exporterPdfHeader:null,e.exporterPdfFooter=e.exporterPdfFooter?e.exporterPdfFooter:null,e.exporterPdfOrientation=e.exporterPdfOrientation?e.exporterPdfOrientation:"landscape",e.exporterPdfPageSize=e.exporterPdfPageSize?e.exporterPdfPageSize:"A4",e.exporterPdfMaxGridWidth=e.exporterPdfMaxGridWidth?e.exporterPdfMaxGridWidth:720,e.exporterMenuAllData=void 0===e.exporterMenuAllData||e.exporterMenuAllData,e.exporterMenuVisibleData=void 0===e.exporterMenuVisibleData||e.exporterMenuVisibleData,e.exporterMenuSelectedData=void 0===e.exporterMenuSelectedData||e.exporterMenuSelectedData,e.exporterMenuCsv=void 0===e.exporterMenuCsv||e.exporterMenuCsv,e.exporterMenuPdf=void 0===e.exporterMenuPdf||e.exporterMenuPdf,e.exporterMenuExcel=void 0===e.exporterMenuExcel||e.exporterMenuExcel,e.exporterPdfCustomFormatter=e.exporterPdfCustomFormatter&&"function"==typeof e.exporterPdfCustomFormatter?e.exporterPdfCustomFormatter:function(e){return e},e.exporterHeaderFilterUseName=!0===e.exporterHeaderFilterUseName,e.exporterFieldCallback=e.exporterFieldCallback?e.exporterFieldCallback:i,e.exporterFieldFormatCallback=e.exporterFieldFormatCallback?e.exporterFieldFormatCallback:function(e,t,r,o){return null},e.exporterExcelCustomFormatters=e.exporterExcelCustomFormatters?e.exporterExcelCustomFormatters:function(e,t,r){return r},e.exporterExcelHeader=e.exporterExcelHeader?e.exporterExcelHeader:function(e,t,r,o){return null},e.exporterColumnScaleFactor=e.exporterColumnScaleFactor?e.exporterColumnScaleFactor:3.5,e.exporterFieldApplyFilters=!0===e.exporterFieldApplyFilters,e.exporterAllDataFn=e.exporterAllDataFn?e.exporterAllDataFn:null,null===e.exporterAllDataFn&&e.exporterAllDataPromise&&(e.exporterAllDataFn=e.exporterAllDataPromise)},addToMenu:function(e){e.api.core.addToGridMenu(e,[{title:r.getSafeText("gridMenu.exporterAllAsCsv"),action:function(){e.api.exporter.csvExport(x.ALL,x.ALL)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuAllData},order:e.options.exporterMenuItemOrder},{title:r.getSafeText("gridMenu.exporterVisibleAsCsv"),action:function(){e.api.exporter.csvExport(x.VISIBLE,x.VISIBLE)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuVisibleData},order:e.options.exporterMenuItemOrder+1},{title:r.getSafeText("gridMenu.exporterSelectedAsCsv"),action:function(){e.api.exporter.csvExport(x.SELECTED,x.VISIBLE)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuSelectedData&&e.api.selection&&0LINK_LABEL')}]); \ No newline at end of file diff --git a/src/features/grouping/js/grouping.js b/src/i18n/ui-grid.grouping.js similarity index 88% rename from src/features/grouping/js/grouping.js rename to src/i18n/ui-grid.grouping.js index f9fef98fbd..cddd600d6b 100644 --- a/src/features/grouping/js/grouping.js +++ b/src/i18n/ui-grid.grouping.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -92,13 +97,11 @@ */ module.service('uiGridGroupingService', ['$q', 'uiGridGroupingConstants', 'gridUtil', 'rowSorter', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'uiGridTreeBaseService', function ($q, uiGridGroupingConstants, gridUtil, rowSorter, GridRow, gridClassFactory, i18nService, uiGridConstants, uiGridTreeBaseService) { - var service = { - initializeGrid: function (grid, $scope) { uiGridTreeBaseService.initializeGrid( grid, $scope ); - //add feature namespace and any properties to grid for needed + // add feature namespace and any properties to grid for needed /** * @ngdoc object * @name ui.grid.grouping.grid:grouping @@ -167,9 +170,9 @@ * @description raised whenever aggregation is changed, added or removed from a column * *
    -               *      gridApi.grouping.on.aggregationChanged(scope,function(col){})
    +               *      gridApi.grouping.on.aggregationChanged(scope,function(col) {})
                    * 
    - * @param {gridCol} col the column which on which aggregation changed. The aggregation + * @param {GridColumn} col the column on which aggregation changed. The aggregation * type is available as `col.treeAggregation.type` */ aggregationChanged: {}, @@ -180,9 +183,9 @@ * @description raised whenever the grouped columns changes * *
    -               *      gridApi.grouping.on.groupingChanged(scope,function(col){})
    +               *      gridApi.grouping.on.groupingChanged(scope,function(col) {})
                    * 
    - * @param {gridCol} col the column which on which grouping changed. The new grouping is + * @param {GridColumn} col the column on which grouping changed. The new grouping is * available as `col.grouping` */ groupingChanged: {} @@ -224,11 +227,11 @@ delete aggregation.col; }); - grouping.aggregations = grouping.aggregations.filter( function( aggregation ){ + grouping.aggregations = grouping.aggregations.filter( function( aggregation ) { return !aggregation.aggregation.source || aggregation.aggregation.source !== 'grouping'; }); - if ( getExpanded ){ + if ( getExpanded ) { grouping.rowExpandedStates = service.getRowExpandedStates( grid.grouping.groupingHeaderCache ); } @@ -261,8 +264,9 @@ * * @param {string} columnName the name of the column we want to group */ - groupColumn: function( columnName ) { + groupColumn: function(columnName) { var column = grid.getColumn(columnName); + service.groupColumn(grid, column); }, @@ -279,8 +283,9 @@ * * @param {string} columnName the name of the column we want to ungroup */ - ungroupColumn: function( columnName ) { + ungroupColumn: function(columnName) { var column = grid.getColumn(columnName); + service.ungroupColumn(grid, column); }, @@ -306,15 +311,15 @@ * being removed * * @param {string} columnName the column we want to aggregate - * @param {string} or {function} aggregationDef one of the recognised types + * @param {string|function} aggregationDef one of the recognised types * from uiGridGroupingConstants or a custom aggregation function. * @param {string} aggregationLabel (optional) The label to use for this aggregation. */ - aggregateColumn: function( columnName, aggregationDef, aggregationLabel){ + aggregateColumn: function(columnName, aggregationDef, aggregationLabel) { var column = grid.getColumn(columnName); - service.aggregateColumn( grid, column, aggregationDef, aggregationLabel); - } + service.aggregateColumn(grid, column, aggregationDef, aggregationLabel); + } } } }; @@ -323,12 +328,11 @@ grid.api.registerMethodsFromObject(publicApi.methods); - grid.api.core.on.sortChanged( $scope, service.tidyPriorities); - + grid.api.core.on.sortChanged($scope, service.tidyPriorities); }, defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.grouping.api:GridOptions @@ -384,7 +388,7 @@ * @description Sets the grouping defaults based on the columnDefs * * @param {object} colDef columnDef we're basing on - * @param {GridCol} col the column we're to update + * @param {GridColumn} col the column we're to update * @param {object} gridOptions the options we should use * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved */ @@ -404,7 +408,7 @@ * @description Enable grouping on this column *
    Defaults to true. */ - if (colDef.enableGrouping === false){ + if (colDef.enableGrouping === false) { return; } @@ -437,15 +441,15 @@ if ( typeof(col.grouping) === 'undefined' && typeof(colDef.grouping) !== 'undefined') { col.grouping = angular.copy(colDef.grouping); - if ( typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority > -1 ){ + if ( typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority > -1 ) { col.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn; col.treeAggregationFinalizerFn = service.groupedFinalizerFn; } - } else if (typeof(col.grouping) === 'undefined'){ + } else if (typeof(col.grouping) === 'undefined') { col.grouping = {}; } - if (typeof(col.grouping) !== 'undefined' && typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority >= 0){ + if (typeof(col.grouping) !== 'undefined' && typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority >= 0) { col.suppressRemoveSort = true; } @@ -489,7 +493,7 @@ }; // generic adder for the aggregation menus, which follow a pattern - var addAggregationMenu = function(type, title){ + var addAggregationMenu = function(type, title) { title = title || i18nService.get().grouping['aggregate_' + type] || type; var menuItem = { name: 'ui.grid.grouping.aggregate' + type, @@ -516,7 +520,7 @@ * @description Show the grouping (group and ungroup items) menu on this column *
    Defaults to true. */ - if ( col.colDef.groupingShowGroupingMenu !== false ){ + if ( col.colDef.groupingShowGroupingMenu !== false ) { if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.group')) { col.menuItems.push(groupColumn); } @@ -534,11 +538,11 @@ * @description Show the aggregation menu on this column *
    Defaults to true. */ - if ( col.colDef.groupingShowAggregationMenu !== false ){ - angular.forEach(uiGridTreeBaseService.nativeAggregations(), function(aggregationDef, name){ + if ( col.colDef.groupingShowAggregationMenu !== false ) { + angular.forEach(uiGridTreeBaseService.nativeAggregations(), function(aggregationDef, name) { addAggregationMenu(name); }); - angular.forEach(gridOptions.treeCustomAggregations, function(aggregationDef, name){ + angular.forEach(gridOptions.treeCustomAggregations, function(aggregationDef, name) { addAggregationMenu(name, aggregationDef.menuTitle); }); @@ -562,8 +566,6 @@ * @returns {array} updated columns array */ groupingColumnProcessor: function( columns, rows ) { - var grid = this; - columns = service.moveGroupColumns(this, columns, rows); return columns; }, @@ -575,14 +577,14 @@ * @description Used on group columns to display the rendered value and optionally * display the count of rows. * - * @param {aggregation} the aggregation entity for a grouped column + * @param {aggregation} aggregation The aggregation entity for a grouped column */ - groupedFinalizerFn: function( aggregation ){ + groupedFinalizerFn: function( aggregation ) { var col = this; if ( typeof(aggregation.groupVal) !== 'undefined') { aggregation.rendered = aggregation.groupVal; - if ( col.grid.options.groupingShowCounts && col.colDef.type !== 'date' && col.colDef.type !== 'object' ){ + if ( col.grid.options.groupingShowCounts && col.colDef.type !== 'date' && col.colDef.type !== 'object' ) { aggregation.rendered += (' (' + aggregation.value + ')'); } } else { @@ -603,36 +605,38 @@ * * @param {Grid} grid grid object * @param {array} columns the columns that we should process/move - * @param {array} rows the grid rows * @returns {array} updated columns */ - moveGroupColumns: function( grid, columns, rows ){ - if ( grid.options.moveGroupColumns === false){ + moveGroupColumns: function( grid, columns ) { + if ( grid.options.moveGroupColumns === false) { return columns; } - columns.forEach( function(column, index){ + columns.forEach(function(column, index) { // position used to make stable sort in moveGroupColumns column.groupingPosition = index; }); - columns.sort(function(a, b){ + columns.sort(function(a, b) { var a_group, b_group; - if (a.isRowHeader){ + + if (a.isRowHeader) { a_group = a.headerPriority; } - else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0){ + else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0) { a_group = null; - } else { + } + else { a_group = a.grouping.groupPriority; } - if (b.isRowHeader){ + if (b.isRowHeader) { b_group = b.headerPriority; } - else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0){ + else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0) { b_group = null; - } else { + } + else { b_group = b.grouping.groupPriority; } @@ -644,7 +648,7 @@ return a.groupingPosition - b.groupingPosition; }); - columns.forEach( function(column, index) { + columns.forEach( function(column) { delete column.groupingPosition; }); @@ -663,10 +667,10 @@ * move is handled in a columnProcessor, so gets called as part of refresh * * @param {Grid} grid grid object - * @param {GridCol} column the column we want to group + * @param {GridColumn} column the column we want to group */ - groupColumn: function( grid, column){ - if ( typeof(column.grouping) === 'undefined' ){ + groupColumn: function( grid, column) { + if ( typeof(column.grouping) === 'undefined' ) { column.grouping = {}; } @@ -678,14 +682,20 @@ column.previousSort = angular.copy(column.sort); // add sort if not present - if ( !column.sort ){ + if ( !column.sort ) { column.sort = { direction: uiGridConstants.ASC }; - } else if ( typeof(column.sort.direction) === 'undefined' || column.sort.direction === null ){ + } else if ( typeof(column.sort.direction) === 'undefined' || column.sort.direction === null ) { column.sort.direction = uiGridConstants.ASC; } column.treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT, source: 'grouping' }; - column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn; + + if ( column.colDef && angular.isFunction(column.colDef.customTreeAggregationFn) ) { + column.treeAggregationFn = column.colDef.customTreeAggregationFn; + } else { + column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn; + } + column.treeAggregationFinalizerFn = service.groupedFinalizerFn; grid.api.grouping.raise.groupingChanged(column); @@ -708,10 +718,10 @@ * move is handled in a columnProcessor, so gets called as part of refresh * * @param {Grid} grid grid object - * @param {GridCol} column the column we want to ungroup + * @param {GridColumn} column the column we want to ungroup */ - ungroupColumn: function( grid, column){ - if ( typeof(column.grouping) === 'undefined' ){ + ungroupColumn: function( grid, column) { + if ( typeof(column.grouping) === 'undefined' ) { return; } @@ -740,23 +750,29 @@ * column is currently grouped then it removes the grouping first. * * @param {Grid} grid grid object - * @param {GridCol} column the column we want to aggregate - * @param {string} one of the recognised types from uiGridGroupingConstants or one of the custom aggregations from gridOptions + * @param {GridColumn} column the column we want to aggregate + * @param {string} aggregationType of the recognised types from uiGridGroupingConstants or one of the custom aggregations from gridOptions + * @param {string} aggregationLabel to be used instead of the default label. If empty string is passed, label is omitted */ - aggregateColumn: function( grid, column, aggregationType){ - - if (typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){ + aggregateColumn: function( grid, column, aggregationType, aggregationLabel ) { + if (typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { service.ungroupColumn( grid, column ); } var aggregationDef = {}; - if ( typeof(grid.options.treeCustomAggregations[aggregationType]) !== 'undefined' ){ + + if ( typeof(grid.options.treeCustomAggregations[aggregationType]) !== 'undefined' ) { aggregationDef = grid.options.treeCustomAggregations[aggregationType]; - } else if ( typeof(uiGridTreeBaseService.nativeAggregations()[aggregationType]) !== 'undefined' ){ + } else if ( typeof(uiGridTreeBaseService.nativeAggregations()[aggregationType]) !== 'undefined' ) { aggregationDef = uiGridTreeBaseService.nativeAggregations()[aggregationType]; } - column.treeAggregation = { type: aggregationType, label: i18nService.get().aggregation[aggregationDef.label] || aggregationDef.label }; + column.treeAggregation = { + type: aggregationType, + label: ( typeof aggregationLabel === 'string') ? + aggregationLabel : + i18nService.get().aggregation[aggregationDef.label] || aggregationDef.label + }; column.treeAggregationFn = aggregationDef.aggregationFn; column.treeAggregationFinalizerFn = aggregationDef.finalizerFn; @@ -776,15 +792,15 @@ * @param {Grid} grid grid object * @param {object} config the config we want to set, same format as that returned by getGrouping */ - setGrouping: function ( grid, config ){ - if ( typeof(config) === 'undefined' ){ + setGrouping: function ( grid, config ) { + if ( typeof(config) === 'undefined' ) { return; } // first remove any existing grouping service.clearGrouping(grid); - if ( config.grouping && config.grouping.length && config.grouping.length > 0 ){ + if ( config.grouping && config.grouping.length && config.grouping.length > 0 ) { config.grouping.forEach( function( group ) { var col = grid.getColumn(group.colName); @@ -794,7 +810,7 @@ }); } - if ( config.aggregations && config.aggregations.length ){ + if ( config.aggregations && config.aggregations.length ) { config.aggregations.forEach( function( aggregation ) { var col = grid.getColumn(aggregation.colName); @@ -804,7 +820,7 @@ }); } - if ( config.rowExpandedStates ){ + if ( config.rowExpandedStates ) { service.applyRowExpandedStates( grid.grouping.groupingHeaderCache, config.rowExpandedStates ); } }, @@ -822,9 +838,9 @@ clearGrouping: function( grid ) { var currentGrouping = service.getGrouping(grid); - if ( currentGrouping.grouping.length > 0 ){ + if ( currentGrouping.grouping.length > 0 ) { currentGrouping.grouping.forEach( function( group ) { - if (!group.col){ + if (!group.col) { // should have a group.colName if there's no col group.col = grid.getColumn(group.colName); } @@ -832,9 +848,9 @@ }); } - if ( currentGrouping.aggregations.length > 0 ){ - currentGrouping.aggregations.forEach( function( aggregation ){ - if (!aggregation.col){ + if ( currentGrouping.aggregations.length > 0 ) { + currentGrouping.aggregations.forEach( function( aggregation ) { + if (!aggregation.col) { // should have a group.colName if there's no col aggregation.col = grid.getColumn(aggregation.colName); } @@ -855,43 +871,44 @@ * * @param {Grid} grid grid object */ - tidyPriorities: function( grid ){ + tidyPriorities: function( grid ) { // if we're called from sortChanged, grid is in this, not passed as param, the param can be a column or undefined if ( ( typeof(grid) === 'undefined' || typeof(grid.grid) !== 'undefined' ) && typeof(this.grid) !== 'undefined' ) { grid = this.grid; } - var groupArray = []; - var sortArray = []; + var groupArray = [], + sortArray = []; - grid.columns.forEach( function(column, index){ - if ( typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){ + grid.columns.forEach( function(column, index) { + if ( typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { groupArray.push(column); - } else if ( typeof(column.sort) !== 'undefined' && typeof(column.sort.priority) !== 'undefined' && column.sort.priority >= 0){ + } + else if ( typeof(column.sort) !== 'undefined' && typeof(column.sort.priority) !== 'undefined' && column.sort.priority >= 0) { sortArray.push(column); } }); - groupArray.sort(function(a, b){ return a.grouping.groupPriority - b.grouping.groupPriority; }); - groupArray.forEach( function(column, index){ + groupArray.sort(function(a, b) { return a.grouping.groupPriority - b.grouping.groupPriority; }); + groupArray.forEach( function(column, index) { column.grouping.groupPriority = index; column.suppressRemoveSort = true; - if ( typeof(column.sort) === 'undefined'){ + if ( typeof(column.sort) === 'undefined') { column.sort = {}; } column.sort.priority = index; }); var i = groupArray.length; - sortArray.sort(function(a, b){ return a.sort.priority - b.sort.priority; }); - sortArray.forEach( function(column, index){ + + sortArray.sort(function(a, b) { return a.sort.priority - b.sort.priority; }); + sortArray.forEach(function(column) { column.sort.priority = i; column.suppressRemoveSort = column.colDef.suppressRemoveSort; i++; }); }, - /** * @ngdoc function * @name groupRows @@ -925,7 +942,7 @@ * @returns {array} the updated rows, including our new group rows */ groupRows: function( renderableRows ) { - if (renderableRows.length === 0){ + if (renderableRows.length === 0) { return renderableRows; } @@ -941,7 +958,7 @@ var fieldValue = grid.getCellValue(row, groupFieldState.col); // look for change of value - and insert a header - if ( !groupFieldState.initialised || rowSorter.getSortFn(grid, groupFieldState.col, renderableRows)(fieldValue, groupFieldState.currentValue) !== 0 ){ + if ( !groupFieldState.initialised || rowSorter.getSortFn(grid, groupFieldState.col, renderableRows)(fieldValue, groupFieldState.currentValue) !== 0 ) { service.insertGroupHeader( grid, renderableRows, i, processingState, stateIndex ); i++; } @@ -949,10 +966,10 @@ // use a for loop because it's tolerant of the array length changing whilst we go - we can // manipulate the iterator when we insert groupHeader rows - for (var i = 0; i < renderableRows.length; i++ ){ + for (var i = 0; i < renderableRows.length; i++ ) { var row = renderableRows[i]; - if ( row.visible ){ + if ( row.visible ) { processingState.forEach( updateProcessingState ); } } @@ -973,11 +990,11 @@ * @returns {array} an array in the format described in the groupRows method, * initialised with blank values */ - initialiseProcessingState: function( grid ){ + initialiseProcessingState: function( grid ) { var processingState = []; var columnSettings = service.getGrouping( grid ); - columnSettings.grouping.forEach( function( groupItem, index){ + columnSettings.grouping.forEach( function( groupItem, index) { processingState.push({ fieldName: groupItem.field, col: groupItem.col, @@ -1000,24 +1017,24 @@ * @param {Grid} grid grid object * @returns {array} an array of the group fields, in order of priority */ - getGrouping: function( grid ){ - var groupArray = []; - var aggregateArray = []; + getGrouping: function( grid ) { + var groupArray = [], + aggregateArray = []; // get all the grouping - grid.columns.forEach( function(column, columnIndex){ - if ( column.grouping ){ - if ( typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0){ + grid.columns.forEach(function(column) { + if ( column.grouping ) { + if ( typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { groupArray.push({ field: column.field, col: column, groupPriority: column.grouping.groupPriority, grouping: column.grouping }); } } - if ( column.treeAggregation && column.treeAggregation.type ){ + if ( column.treeAggregation && column.treeAggregation.type ) { aggregateArray.push({ field: column.field, col: column, aggregation: column.treeAggregation }); } }); // sort grouping into priority order - groupArray.sort( function(a, b){ + groupArray.sort( function(a, b) { return a.groupPriority - b.groupPriority; }); @@ -1050,32 +1067,29 @@ */ insertGroupHeader: function( grid, renderableRows, rowIndex, processingState, stateIndex ) { // set the value that caused the end of a group into the header row and the processing state - var fieldName = processingState[stateIndex].fieldName; - var col = processingState[stateIndex].col; + var col = processingState[stateIndex].col, + newValue = grid.getCellValue(renderableRows[rowIndex], col), + newDisplayValue = newValue; - var newValue = grid.getCellValue(renderableRows[rowIndex], col); - var newDisplayValue = newValue; if ( typeof(newValue) === 'undefined' || newValue === null ) { newDisplayValue = grid.options.groupingNullLabel; } - var getKeyAsValueForCacheMap = function(key) { - if (angular.isObject(key)) { - return JSON.stringify(key); - } else { - return key; - } - }; + function getKeyAsValueForCacheMap(key) { + return angular.isObject(key) ? JSON.stringify(key) : key; + } var cacheItem = grid.grouping.oldGroupingHeaderCache; - for ( var i = 0; i < stateIndex; i++ ){ - if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ){ + + for ( var i = 0; i < stateIndex; i++ ) { + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ) { cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; } } var headerRow; - if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]){ + + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]) { headerRow = cacheItem[getKeyAsValueForCacheMap(newValue)].row; headerRow.entity = {}; } else { @@ -1102,7 +1116,7 @@ // add our new header row to the cache cacheItem = grid.grouping.groupingHeaderCache; - for ( i = 0; i < stateIndex; i++ ){ + for ( i = 0; i < stateIndex; i++ ) { cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; } cacheItem[getKeyAsValueForCacheMap(newValue)] = { row: headerRow, children: {} }; @@ -1116,13 +1130,12 @@ * @description Set all processing states lower than the one that had a break in value to * no longer be initialised. Render the counts into the entity ready for display. * - * @param {Grid} grid grid object * @param {array} processingState the current processing state * @param {number} stateIndex the processing state item that we were on when we triggered a new group header, all * processing states after this need to be finalised */ - finaliseProcessingState: function( processingState, stateIndex ){ - for ( var i = stateIndex; i < processingState.length; i++){ + finaliseProcessingState: function( processingState, stateIndex ) { + for ( var i = stateIndex; i < processingState.length; i++) { processingState[i].initialised = false; processingState[i].currentRow = null; processingState[i].currentValue = null; @@ -1157,19 +1170,19 @@ * } * * - * @param {Grid} grid grid object - * @returns {hash} the expanded states as a hash + * @param {object} treeChildren The tree children elements object + * @returns {object} the expanded states as an object */ - getRowExpandedStates: function(treeChildren){ - if ( typeof(treeChildren) === 'undefined' ){ + getRowExpandedStates: function(treeChildren) { + if ( typeof(treeChildren) === 'undefined' ) { return {}; } var newChildren = {}; - angular.forEach( treeChildren, function( value, key ){ + angular.forEach( treeChildren, function( value, key ) { newChildren[key] = { state: value.row.treeNode.state }; - if ( value.children ){ + if ( value.children ) { newChildren[key].children = service.getRowExpandedStates( value.children ); } else { newChildren[key].children = {}; @@ -1192,19 +1205,19 @@ * * @param {object} currentNode can be grid.grouping.groupHeaderCache, or any of * the children of that hash - * @returns {hash} expandedStates can be the full expanded states, or children + * @param {object} expandedStates can be the full expanded states, or children * of that expanded states (which hopefully matches the subset of the groupHeaderCache) */ - applyRowExpandedStates: function( currentNode, expandedStates ){ - if ( typeof(expandedStates) === 'undefined' ){ + applyRowExpandedStates: function( currentNode, expandedStates ) { + if ( typeof(expandedStates) === 'undefined' ) { return; } angular.forEach(expandedStates, function( value, key ) { - if ( currentNode[key] ){ + if ( currentNode[key] ) { currentNode[key].row.treeNode.state = value.state; - if (value.children && currentNode[key].children){ + if (value.children && currentNode[key].children) { service.applyRowExpandedStates( currentNode[key].children, value.children ); } } @@ -1253,8 +1266,8 @@ */ - module.directive('uiGridGrouping', ['uiGridGroupingConstants', 'uiGridGroupingService', '$templateCache', - function (uiGridGroupingConstants, uiGridGroupingService, $templateCache) { + module.directive('uiGridGrouping', ['uiGridGroupingConstants', 'uiGridGroupingService', + function (uiGridGroupingConstants, uiGridGroupingService) { return { replace: true, priority: 0, @@ -1263,7 +1276,7 @@ compile: function () { return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { - if (uiGridCtrl.grid.options.enableGrouping !== false){ + if (uiGridCtrl.grid.options.enableGrouping !== false) { uiGridGroupingService.initializeGrid(uiGridCtrl.grid, $scope); } }, diff --git a/src/i18n/ui-grid.grouping.min.js b/src/i18n/ui-grid.grouping.min.js new file mode 100644 index 0000000000..9f4c30aecd --- /dev/null +++ b/src/i18n/ui-grid.grouping.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var r=angular.module("ui.grid.grouping",["ui.grid","ui.grid.treeBase"]);r.constant("uiGridGroupingConstants",{featureName:"grouping",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),r.service("uiGridGroupingService",["$q","uiGridGroupingConstants","gridUtil","rowSorter","GridRow","gridClassFactory","i18nService","uiGridConstants","uiGridTreeBaseService",function(r,u,a,p,s,d,l,e,c){var f={initializeGrid:function(n,r){c.initializeGrid(n,r),n.grouping={},n.grouping.groupHeaderCache={},f.defaultGridOptions(n.options),n.registerRowsProcessor(f.groupRows,400),n.registerColumnBuilder(f.groupingColumnBuilder),n.registerColumnsProcessor(f.groupingColumnProcessor,400);var o={events:{grouping:{aggregationChanged:{},groupingChanged:{}}},methods:{grouping:{getGrouping:function(r){var o=f.getGrouping(n);return o.grouping.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations=o.aggregations.filter(function(r){return!r.aggregation.source||"grouping"!==r.aggregation.source}),r&&(o.rowExpandedStates=f.getRowExpandedStates(n.grouping.groupingHeaderCache)),o},setGrouping:function(r){f.setGrouping(n,r)},groupColumn:function(r){var o=n.getColumn(r);f.groupColumn(n,o)},ungroupColumn:function(r){var o=n.getColumn(r);f.ungroupColumn(n,o)},clearGrouping:function(){f.clearGrouping(n)},aggregateColumn:function(r,o,i){var e=n.getColumn(r);f.aggregateColumn(n,e,o,i)}}}};n.api.registerEventsFromObject(o.events),n.api.registerMethodsFromObject(o.methods),n.api.core.on.sortChanged(r,f.tidyPriorities)},defaultGridOptions:function(r){r.enableGrouping=!1!==r.enableGrouping,r.groupingShowCounts=!1!==r.groupingShowCounts,r.groupingNullLabel=void 0===r.groupingNullLabel?"Null":r.groupingNullLabel,r.enableGroupHeaderSelection=!0===r.enableGroupHeaderSelection},groupingColumnBuilder:function(r,e,o){if(!1!==r.enableGrouping){void 0===e.grouping&&void 0!==r.grouping?(e.grouping=angular.copy(r.grouping),void 0!==e.grouping.groupPriority&&-1 - * gridOptions.importerProcessHeaders: function( headerArray ) { + * gridOptions.importerProcessHeaders: function( grid, headerArray ) { * var myHeaderColumns = []; * var thisCol; * headerArray.forEach( function( value, index ) { @@ -235,7 +238,7 @@ * often the file content itself or the element that is in error * */ - if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ){ + if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ) { delete gridOptions.importerErrorCallback; } @@ -333,7 +336,7 @@ }, { templateUrl: 'ui-grid/importerMenuItemContainer', - action: function ($event) { + action: function () { this.grid.api.importer.importAFile( grid ); }, order: 151 @@ -353,14 +356,14 @@ * javascript object */ importThisFile: function ( grid, fileObject ) { - if (!fileObject){ + if (!fileObject) { gridUtil.logError( 'No file object provided to importThisFile, should be impossible, aborting'); return; } var reader = new FileReader(); - switch ( fileObject.type ){ + switch ( fileObject.type ) { case 'application/json': reader.onload = service.importJsonClosure( grid ); break; @@ -381,19 +384,19 @@ * The json data is imported into new objects of type `gridOptions.importerNewObject`, * and if the rowEdit feature is enabled the rows are marked as dirty * @param {Grid} grid the grid we want to import into - * @param {FileObject} importFile the file that we want to import, as - * a FileObject + * @return {function} Function that receives the file that we want to import, as + * a FileObject as an argument */ importJsonClosure: function( grid ) { - return function( importFile ){ - var newObjects = []; - var newObject; + return function( importFile ) { + var newObjects = [], + newObject, + importArray = service.parseJson( grid, importFile ); - var importArray = service.parseJson( grid, importFile ); - if (importArray === null){ + if (importArray === null) { return; } - importArray.forEach( function( value, index ) { + importArray.forEach( function( value ) { newObject = service.newObject( grid ); angular.extend( newObject, value ); newObject = grid.options.importerObjectCallback( grid, newObject ); @@ -401,7 +404,6 @@ }); service.addObjects( grid, newObjects ); - }; }, @@ -417,8 +419,9 @@ * a FileObject * @returns {array} array of objects from the imported json */ - parseJson: function( grid, importFile ){ + parseJson: function( grid, importFile ) { var loadedObjects; + try { loadedObjects = JSON.parse( importFile.target.result ); } catch (e) { @@ -426,7 +429,7 @@ return; } - if ( !Array.isArray( loadedObjects ) ){ + if ( !Array.isArray( loadedObjects ) ) { service.alertError( grid, 'importer.jsonNotarray', 'Import failed, file is not an array, file was: ', importFile.target.result ); return []; } else { @@ -443,19 +446,21 @@ * @description Creates a function that imports a csv file into the grid * (allowing it to be used in the reader.onload event) * @param {Grid} grid the grid that we want to import into - * @param {FileObject} importFile the file that we want to import, as + * @return {function} Function that receives the file that we want to import, as * a file object */ importCsvClosure: function( grid ) { - return function( importFile ){ + return function( importFile ) { var importArray = service.parseCsv( importFile ); - if ( !importArray || importArray.length < 1 ){ + + if ( !importArray || importArray.length < 1 ) { service.alertError( grid, 'importer.invalidCsv', 'File could not be processed, is it valid csv? Content was: ', importFile.target.result ); return; } var newObjects = service.createCsvObjects( grid, importArray ); - if ( !newObjects || newObjects.length === 0 ){ + + if ( !newObjects || newObjects.length === 0 ) { service.alertError( grid, 'importer.noObjects', 'Objects were not able to be derived, content was: ', importFile.target.result ); return; } @@ -499,21 +504,23 @@ * @param {Grid} grid the grid that we want to import into * @param {Array} importArray the data that we want to import, as an array */ - createCsvObjects: function( grid, importArray ){ + createCsvObjects: function( grid, importArray ) { // pull off header row and turn into headers var headerMapping = grid.options.importerProcessHeaders( grid, importArray.shift() ); - if ( !headerMapping || headerMapping.length === 0 ){ + + if ( !headerMapping || headerMapping.length === 0 ) { service.alertError( grid, 'importer.noHeaders', 'Column names could not be derived, content was: ', importArray ); return []; } - var newObjects = []; - var newObject; - importArray.forEach( function( row, index ) { + var newObjects = [], + newObject; + + importArray.forEach( function( row ) { newObject = service.newObject( grid ); - if ( row !== null ){ - row.forEach( function( field, index ){ - if ( headerMapping[index] !== null ){ + if ( row !== null ) { + row.forEach( function( field, index ) { + if ( headerMapping[index] !== null ) { newObject[ headerMapping[index] ] = field; } }); @@ -541,21 +548,25 @@ */ processHeaders: function( grid, headerRow ) { var headers = []; - if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ){ + + if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ) { // we are going to create new columnDefs for all these columns, so just remove // spaces from the names to create fields - headerRow.forEach( function( value, index ) { + headerRow.forEach( function( value ) { headers.push( value.replace( /[^0-9a-zA-Z\-_]/g, '_' ) ); }); return headers; - } else { + } + else { var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs ); - headerRow.forEach( function( value, index ) { + headerRow.forEach( function( value ) { if ( lookupHash[value] ) { headers.push( lookupHash[value] ); - } else if ( lookupHash[ value.toLowerCase() ] ) { + } + else if ( lookupHash[ value.toLowerCase() ] ) { headers.push( lookupHash[ value.toLowerCase() ] ); - } else { + } + else { headers.push( null ); } }); @@ -577,25 +588,26 @@ * @returns {hash} the flattened version of the column def information, allowing * us to look up a value by `flattenedHash[ headerValue ]` */ - flattenColumnDefs: function( grid, columnDefs ){ + flattenColumnDefs: function( grid, columnDefs ) { var flattenedHash = {}; - columnDefs.forEach( function( columnDef, index) { - if ( columnDef.name ){ + + columnDefs.forEach( function( columnDef) { + if ( columnDef.name ) { flattenedHash[ columnDef.name ] = columnDef.field || columnDef.name; flattenedHash[ columnDef.name.toLowerCase() ] = columnDef.field || columnDef.name; } - if ( columnDef.field ){ + if ( columnDef.field ) { flattenedHash[ columnDef.field ] = columnDef.field || columnDef.name; flattenedHash[ columnDef.field.toLowerCase() ] = columnDef.field || columnDef.name; } - if ( columnDef.displayName ){ + if ( columnDef.displayName ) { flattenedHash[ columnDef.displayName ] = columnDef.field || columnDef.name; flattenedHash[ columnDef.displayName.toLowerCase() ] = columnDef.field || columnDef.name; } - if ( columnDef.displayName && grid.options.importerHeaderFilter ){ + if ( columnDef.displayName && grid.options.importerHeaderFilter ) { flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName) ] = columnDef.field || columnDef.name; flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName).toLowerCase() ] = columnDef.field || columnDef.name; } @@ -624,8 +636,8 @@ * @param {array} newObjects the objects we want to insert into the grid data * @returns {object} the new object */ - addObjects: function( grid, newObjects, $scope ){ - if ( grid.api.rowEdit ){ + addObjects: function( grid, newObjects ) { + if ( grid.api.rowEdit ) { var dataChangeDereg = grid.registerDataChangeCallback( function() { grid.api.rowEdit.setRowsDirty( newObjects ); dataChangeDereg(); @@ -648,10 +660,11 @@ * @param {Grid} grid the grid we're importing into * @returns {object} the new object */ - newObject: function( grid ){ - if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ){ + newObject: function( grid ) { + if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ) { return new grid.options.importerNewObject(); - } else { + } + else { return {}; } }, @@ -669,10 +682,11 @@ * @param {array} headerRow the header row that we wish to match against * the column definitions */ - alertError: function( grid, alertI18nToken, consoleMessage, context ){ - if ( grid.options.importerErrorCallback ){ + alertError: function( grid, alertI18nToken, consoleMessage, context ) { + if ( grid.options.importerErrorCallback ) { grid.options.importerErrorCallback( grid, alertI18nToken, consoleMessage, context ); - } else { + } + else { $window.alert(i18nService.getSafeText( alertI18nToken )); gridUtil.logError(consoleMessage + context ); } @@ -722,30 +736,55 @@ return { replace: true, priority: 0, - require: '^uiGrid', + require: '?^uiGrid', scope: false, templateUrl: 'ui-grid/importerMenuItem', link: function ($scope, $elm, $attrs, uiGridCtrl) { - var handleFileSelect = function( event ){ + var grid; + + function handleFileSelect(event) { var target = event.srcElement || event.target; if (target && target.files && target.files.length === 1) { var fileObject = target.files[0]; - uiGridImporterService.importThisFile( grid, fileObject ); - target.form.reset(); + + // Define grid if the uiGrid controller is present + if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) { + grid = uiGridCtrl.grid; + + uiGridImporterService.importThisFile( grid, fileObject ); + target.form.reset(); + } + else { + gridUtil.logError('Could not import file because UI Grid was not found.'); + } } - }; + } var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser'); - var grid = uiGridCtrl.grid; - if ( fileChooser.length !== 1 ){ + if ( fileChooser.length !== 1 ) { gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue'); - } else { - fileChooser[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google + } + else { + fileChooser[0].addEventListener('change', handleFileSelect, false); } } }; } ]); })(); + +angular.module('ui.grid.importer').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/importerMenuItem', + "
  • " + ); + + + $templateCache.put('ui-grid/importerMenuItemContainer', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.importer.min.js b/src/i18n/ui-grid.importer.min.js new file mode 100644 index 0000000000..c21292dac5 --- /dev/null +++ b/src/i18n/ui-grid.importer.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.importer",["ui.grid"]);e.constant("uiGridImporterConstants",{featureName:"importer"}),e.service("uiGridImporterService",["$q","uiGridConstants","uiGridImporterConstants","gridUtil","$compile","$interval","i18nService","$window",function(e,i,r,o,t,n,a,s){var l={initializeGrid:function(e,r){r.importer={$scope:e},this.defaultGridOptions(r.options);var t={events:{importer:{}},methods:{importer:{importFile:function(e){l.importThisFile(r,e)}}}};r.api.registerEventsFromObject(t.events),r.api.registerMethodsFromObject(t.methods),r.options.enableImporter&&r.options.importerShowMenu&&(r.api.core.addToGridMenu?l.addToMenu(r):n(function(){r.api.core.addToGridMenu&&l.addToMenu(r)},100,1))},defaultGridOptions:function(e){e.enableImporter||void 0===e.enableImporter?s.hasOwnProperty("File")&&s.hasOwnProperty("FileReader")&&s.hasOwnProperty("FileList")&&s.hasOwnProperty("Blob")?e.enableImporter=!0:(o.logError("The File APIs are not fully supported in this browser, grid importer cannot be used."),e.enableImporter=!1):e.enableImporter=!1,e.importerProcessHeaders=e.importerProcessHeaders||l.processHeaders,e.importerHeaderFilter=e.importerHeaderFilter||function(e){return e},e.importerErrorCallback&&"function"==typeof e.importerErrorCallback||delete e.importerErrorCallback,!0!==e.enableImporter||e.importerDataAddCallback||(o.logError("You have not set an importerDataAddCallback, importer is disabled"),e.enableImporter=!1),e.importerShowMenu=!1!==e.importerShowMenu,e.importerObjectCallback=e.importerObjectCallback||function(e,r){return r}},addToMenu:function(e){e.api.core.addToGridMenu(e,[{title:a.getSafeText("gridMenu.importerTitle"),order:150},{templateUrl:"ui-grid/importerMenuItemContainer",action:function(){this.grid.api.importer.importAFile(e)},order:151}])},importThisFile:function(e,r){if(r){var t=new FileReader;switch(r.type){case"application/json":t.onload=l.importJsonClosure(e);break;default:t.onload=l.importCsvClosure(e)}t.readAsText(r)}else o.logError("No file object provided to importThisFile, should be impossible, aborting")},importJsonClosure:function(o){return function(e){var r,t=[],i=l.parseJson(o,e);null!==i&&(i.forEach(function(e){r=l.newObject(o),angular.extend(r,e),r=o.options.importerObjectCallback(o,r),t.push(r)}),l.addObjects(o,t))}},parseJson:function(r,t){var e;try{e=JSON.parse(t.target.result)}catch(e){return void l.alertError(r,"importer.invalidJson","File could not be processed, is it valid json? Content was: ",t.target.result)}return Array.isArray(e)?e:(l.alertError(r,"importer.jsonNotarray","Import failed, file is not an array, file was: ",t.target.result),[])},importCsvClosure:function(i){return function(e){var r=l.parseCsv(e);if(!r||r.length<1)l.alertError(i,"importer.invalidCsv","File could not be processed, is it valid csv? Content was: ",e.target.result);else{var t=l.createCsvObjects(i,r);t&&0!==t.length?l.addObjects(i,t):l.alertError(i,"importer.noObjects","Objects were not able to be derived, content was: ",e.target.result)}}},parseCsv:function(e){var r=e.target.result;return CSV.parse(r)},createCsvObjects:function(r,e){var t=r.options.importerProcessHeaders(r,e.shift());if(!t||0===t.length)return l.alertError(r,"importer.noHeaders","Column names could not be derived, content was: ",e),[];var i,o=[];return e.forEach(function(e){i=l.newObject(r),null!==e&&e.forEach(function(e,r){null!==t[r]&&(i[t[r]]=e)}),i=r.options.importerObjectCallback(r,i),o.push(i)}),o},processHeaders:function(e,r){var t=[];if(e.options.columnDefs&&0!==e.options.columnDefs.length){var i=l.flattenColumnDefs(e,e.options.columnDefs);return r.forEach(function(e){i[e]?t.push(i[e]):i[e.toLowerCase()]?t.push(i[e.toLowerCase()]):t.push(null)}),t}return r.forEach(function(e){t.push(e.replace(/[^0-9a-zA-Z\-_]/g,"_"))}),t},flattenColumnDefs:function(r,e){var t={};return e.forEach(function(e){e.name&&(t[e.name]=e.field||e.name,t[e.name.toLowerCase()]=e.field||e.name),e.field&&(t[e.field]=e.field||e.name,t[e.field.toLowerCase()]=e.field||e.name),e.displayName&&(t[e.displayName]=e.field||e.name,t[e.displayName.toLowerCase()]=e.field||e.name),e.displayName&&r.options.importerHeaderFilter&&(t[r.options.importerHeaderFilter(e.displayName)]=e.field||e.name,t[r.options.importerHeaderFilter(e.displayName).toLowerCase()]=e.field||e.name)}),t},addObjects:function(e,r){if(e.api.rowEdit){var t=e.registerDataChangeCallback(function(){e.api.rowEdit.setRowsDirty(r),t()},[i.dataChange.ROW]);e.importer.$scope.$on("$destroy",t)}e.importer.$scope.$apply(e.options.importerDataAddCallback(e,r))},newObject:function(e){return void 0!==e.options&&void 0!==e.options.importerNewObject?new e.options.importerNewObject:{}},alertError:function(e,r,t,i){e.options.importerErrorCallback?e.options.importerErrorCallback(e,r,t,i):(s.alert(a.getSafeText(r)),o.logError(t+i))}};return l}]),e.directive("uiGridImporter",["uiGridImporterConstants","uiGridImporterService","gridUtil","$compile",function(e,o,r,t){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,link:function(e,r,t,i){o.initializeGrid(e,i.grid)}}}]),e.directive("uiGridImporterMenuItem",["uiGridImporterConstants","uiGridImporterService","gridUtil","$compile",function(e,a,s,r){return{replace:!0,priority:0,require:"?^uiGrid",scope:!1,templateUrl:"ui-grid/importerMenuItem",link:function(e,r,t,i){var o;var n=r[0].querySelectorAll(".ui-grid-importer-file-chooser");1!==n.length?s.logError("Found > 1 or < 1 file choosers within the menu item, error, cannot continue"):n[0].addEventListener("change",function(e){var r=e.srcElement||e.target;if(r&&r.files&&1===r.files.length){var t=r.files[0];void 0!==i&&i?(o=i.grid,a.importThisFile(o,t),r.form.reset()):s.logError("Could not import file because UI Grid was not found.")}},!1)}}}])}(),angular.module("ui.grid.importer").run(["$templateCache",function(e){"use strict";e.put("ui-grid/importerMenuItem",'
  • '),e.put("ui-grid/importerMenuItemContainer","
    ")}]); \ No newline at end of file diff --git a/src/features/infinite-scroll/js/infinite-scroll.js b/src/i18n/ui-grid.infinite-scroll.js similarity index 92% rename from src/features/infinite-scroll/js/infinite-scroll.js rename to src/i18n/ui-grid.infinite-scroll.js index 25307ef977..3a83bdca82 100644 --- a/src/features/infinite-scroll/js/infinite-scroll.js +++ b/src/i18n/ui-grid.infinite-scroll.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function() { 'use strict'; /** @@ -20,8 +25,7 @@ * * @description Service for infinite scroll features */ - module.service('uiGridInfiniteScrollService', ['gridUtil', '$compile', '$timeout', 'uiGridConstants', 'ScrollEvent', '$q', function (gridUtil, $compile, $timeout, uiGridConstants, ScrollEvent, $q) { - + module.service('uiGridInfiniteScrollService', ['gridUtil', '$compile', '$rootScope', 'uiGridConstants', 'ScrollEvent', '$q', function (gridUtil, $compile, $rootScope, uiGridConstants, ScrollEvent, $q) { var service = { /** @@ -34,7 +38,7 @@ initializeGrid: function(grid, $scope) { service.defaultGridOptions(grid.options); - if (!grid.options.enableInfiniteScroll){ + if (!grid.options.enableInfiniteScroll) { return; } @@ -103,11 +107,9 @@ dataLoaded: function( scrollUp, scrollDown ) { service.setScrollDirections(grid, scrollUp, scrollDown); - var promise = service.adjustScroll(grid).then(function() { + return service.adjustScroll(grid).then(function() { grid.infiniteScroll.dataLoading = false; }); - - return promise; }, /** @@ -196,7 +198,7 @@ defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.infiniteScroll.api:GridOptions @@ -283,7 +285,7 @@ */ handleScroll: function (args) { // don't request data if already waiting for data, or if source is coming from ui.grid.adjustInfiniteScrollPosition() function - if ( args.grid.infiniteScroll && args.grid.infiniteScroll.dataLoading || args.source === 'ui.grid.adjustInfiniteScrollPosition' ){ + if ( args.grid.infiniteScroll && args.grid.infiniteScroll.dataLoading || args.source === 'ui.grid.adjustInfiniteScrollPosition' ) { return; } @@ -294,20 +296,24 @@ if (args.y.percentage === 0) { args.grid.scrollDirection = uiGridConstants.scrollDirection.UP; service.loadData(args.grid); - } else if (args.y.percentage === 1) { + } + else if (args.y.percentage === 1) { args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; service.loadData(args.grid); - } else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data. - var percentage; - var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length; + } + else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data. + var percentage, + targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length; + if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) { percentage = args.y.percentage; - if (percentage <= targetPercentage){ + if (percentage <= targetPercentage) { service.loadData(args.grid); } - } else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) { + } + else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) { percentage = 1 - args.y.percentage; - if (percentage <= targetPercentage){ + if (percentage <= targetPercentage) { service.loadData(args.grid); } } @@ -335,7 +341,8 @@ if (grid.scrollDirection === uiGridConstants.scrollDirection.UP && grid.infiniteScroll.scrollUp ) { grid.infiniteScroll.dataLoading = true; grid.api.infiniteScroll.raise.needLoadMoreDataTop(); - } else if (grid.scrollDirection === uiGridConstants.scrollDirection.DOWN && grid.infiniteScroll.scrollDown ) { + } + else if (grid.scrollDirection === uiGridConstants.scrollDirection.DOWN && grid.infiniteScroll.scrollDown ) { grid.infiniteScroll.dataLoading = true; grid.api.infiniteScroll.raise.needLoadMoreData(); } @@ -351,7 +358,7 @@ * * If we're scrolling up we scroll to the first row of the old data set - * so we're assuming that you would have gotten to the top of the grid (from the 20% need more data trigger) by - * the time the data comes back. If we're scrolling down we scoll to the last row of the old data set - so we're + * the time the data comes back. If we're scrolling down we scroll to the last row of the old data set - so we're * assuming that you would have gotten to the bottom of the grid (from the 80% need more data trigger) by the time * the data comes back. * @@ -363,15 +370,15 @@ * @param {Grid} grid the grid we're working on * @returns {promise} a promise that is resolved when scrolling has finished */ - adjustScroll: function(grid){ + adjustScroll: function(grid) { var promise = $q.defer(); - $timeout(function () { - var newPercentage, viewportHeight, rowHeight, newVisibleRows, oldTop, newTop; + $rootScope.$applyAsync(function () { + var viewportHeight, rowHeight, newVisibleRows, oldTop, newTop; viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight; rowHeight = grid.options.rowHeight; - if ( grid.infiniteScroll.direction === undefined ){ + if ( grid.infiniteScroll.direction === undefined ) { // called from initialize, tweak our scroll up a little service.adjustInfiniteScrollPosition(grid, 0); } @@ -384,19 +391,19 @@ grid.api.infiniteScroll.raise.needLoadMoreData(); } - if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.UP ){ + if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.UP ) { oldTop = grid.infiniteScroll.prevScrollTop || 0; newTop = oldTop + (newVisibleRows - grid.infiniteScroll.previousVisibleRows)*rowHeight; service.adjustInfiniteScrollPosition(grid, newTop); - $timeout( function() { + $rootScope.$applyAsync( function() { promise.resolve(); }); } - if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.DOWN ){ + if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.DOWN ) { newTop = grid.infiniteScroll.prevScrollTop || (grid.infiniteScroll.previousVisibleRows*rowHeight - viewportHeight); service.adjustInfiniteScrollPosition(grid, newTop); - $timeout( function() { + $rootScope.$applyAsync( function() { promise.resolve(); }); } @@ -421,10 +428,10 @@ rowHeight = grid.options.rowHeight, scrollHeight = visibleRows*rowHeight-viewportHeight; - //for infinite scroll, if there are pages upwards then never allow it to be at the zero position so the up button can be active + // for infinite scroll, if there are pages upwards then never allow it to be at the zero position so the up button can be active if (scrollTop === 0 && grid.infiniteScroll.scrollUp) { // using pixels results in a relative scroll, hence we have to use percentage - scrollEvent.y = {percentage: 1/scrollHeight}; + scrollEvent.y = {pixels: 1}; } else { scrollEvent.y = {percentage: scrollTop/scrollHeight}; @@ -478,6 +485,7 @@ */ dataRemovedBottom: function( grid, scrollUp, scrollDown ) { var newTop; + service.setScrollDirections( grid, scrollUp, scrollDown ); newTop = grid.infiniteScroll.prevScrollTop; @@ -526,7 +534,7 @@ priority: -200, scope: false, require: '^uiGrid', - compile: function($scope, $elm, $attr){ + compile: function() { return { pre: function($scope, $elm, $attr, uiGridCtrl) { uiGridInfiniteScrollService.initializeGrid(uiGridCtrl.grid, $scope); @@ -537,5 +545,4 @@ } }; }]); - })(); diff --git a/src/i18n/ui-grid.infinite-scroll.min.js b/src/i18n/ui-grid.infinite-scroll.min.js new file mode 100644 index 0000000000..8d55ca0697 --- /dev/null +++ b/src/i18n/ui-grid.infinite-scroll.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var i=angular.module("ui.grid.infiniteScroll",["ui.grid"]);i.service("uiGridInfiniteScrollService",["gridUtil","$compile","$rootScope","uiGridConstants","ScrollEvent","$q",function(i,o,c,s,t,n){var a={initializeGrid:function(n,i){if(a.defaultGridOptions(n.options),n.options.enableInfiniteScroll){n.infiniteScroll={dataLoading:!1},a.setScrollDirections(n,n.options.infiniteScrollUp,n.options.infiniteScrollDown),n.api.core.on.scrollEnd(i,a.handleScroll);var o={events:{infiniteScroll:{needLoadMoreData:function(i,o){},needLoadMoreDataTop:function(i,o){}}},methods:{infiniteScroll:{dataLoaded:function(i,o){return a.setScrollDirections(n,i,o),a.adjustScroll(n).then(function(){n.infiniteScroll.dataLoading=!1})},resetScroll:function(i,o){a.setScrollDirections(n,i,o),a.adjustInfiniteScrollPosition(n,0)},saveScrollPercentage:function(){n.infiniteScroll.prevScrollTop=n.renderContainers.body.prevScrollTop,n.infiniteScroll.previousVisibleRows=n.getVisibleRowCount()},dataRemovedTop:function(i,o){a.dataRemovedTop(n,i,o)},dataRemovedBottom:function(i,o){a.dataRemovedBottom(n,i,o)},setScrollDirections:function(i,o){a.setScrollDirections(n,i,o)}}}};n.api.registerEventsFromObject(o.events),n.api.registerMethodsFromObject(o.methods)}},defaultGridOptions:function(i){i.enableInfiniteScroll=!1!==i.enableInfiniteScroll,i.infiniteScrollRowsFromEnd=i.infiniteScrollRowsFromEnd||20,i.infiniteScrollUp=!0===i.infiniteScrollUp,i.infiniteScrollDown=!1!==i.infiniteScrollDown},setScrollDirections:function(i,o,n){i.infiniteScroll.scrollUp=!0===o,i.suppressParentScrollUp=!0===o,i.infiniteScroll.scrollDown=!1!==n,i.suppressParentScrollDown=!1!==n},handleScroll:function(i){if(!(i.grid.infiniteScroll&&i.grid.infiniteScroll.dataLoading||"ui.grid.adjustInfiniteScrollPosition"===i.source)&&i.y)if(0===i.y.percentage)i.grid.scrollDirection=s.scrollDirection.UP,a.loadData(i.grid);else if(1===i.y.percentage)i.grid.scrollDirection=s.scrollDirection.DOWN,a.loadData(i.grid);else{var o=i.grid.options.infiniteScrollRowsFromEnd/i.grid.renderContainers.body.visibleRowCache.length;i.grid.scrollDirection===s.scrollDirection.UP?i.y.percentage<=o&&a.loadData(i.grid):i.grid.scrollDirection===s.scrollDirection.DOWN&&1-i.y.percentage<=o&&a.loadData(i.grid)}},loadData:function(i){i.infiniteScroll.previousVisibleRows=i.renderContainers.body.visibleRowCache.length,i.infiniteScroll.direction=i.scrollDirection,delete i.infiniteScroll.prevScrollTop,i.scrollDirection===s.scrollDirection.UP&&i.infiniteScroll.scrollUp?(i.infiniteScroll.dataLoading=!0,i.api.infiniteScroll.raise.needLoadMoreDataTop()):i.scrollDirection===s.scrollDirection.DOWN&&i.infiniteScroll.scrollDown&&(i.infiniteScroll.dataLoading=!0,i.api.infiniteScroll.raise.needLoadMoreData())},adjustScroll:function(l){var t=n.defer();return c.$applyAsync(function(){var i,o,n,e;i=l.getViewportHeight()+l.headerHeight-l.renderContainers.body.headerHeight-l.scrollbarHeight,o=l.options.rowHeight,void 0===l.infiniteScroll.direction&&a.adjustInfiniteScrollPosition(l,0);var r=o*(n=l.getVisibleRowCount());l.infiniteScroll.scrollDown&&rAlpha This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.
    + * + * This module provides column moving capability to ui.grid. It enables to change the position of columns. + *
    + */ + var module = angular.module('ui.grid.moveColumns', ['ui.grid']); + + /** + * @ngdoc service + * @name ui.grid.moveColumns.service:uiGridMoveColumnService + * @description Service for column moving feature. + */ + module.service('uiGridMoveColumnService', ['$q', '$rootScope', '$log', 'ScrollEvent', 'uiGridConstants', 'gridUtil', function ($q, $rootScope, $log, ScrollEvent, uiGridConstants, gridUtil) { + var service = { + initializeGrid: function (grid) { + var self = this; + this.registerPublicApi(grid); + this.defaultGridOptions(grid.options); + grid.moveColumns = {orderCache: []}; // Used to cache the order before columns are rebuilt + grid.registerColumnBuilder(self.movableColumnBuilder); + grid.registerDataChangeCallback(self.verifyColumnOrder, [uiGridConstants.dataChange.COLUMN]); + }, + registerPublicApi: function (grid) { + var self = this; + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:PublicApi + * @description Public Api for column moving feature. + */ + var publicApi = { + events: { + /** + * @ngdoc event + * @name columnPositionChanged + * @eventOf ui.grid.moveColumns.api:PublicApi + * @description raised when column is moved + *
    +             *      gridApi.colMovable.on.columnPositionChanged(scope,function(colDef, originalPosition, newPosition) {})
    +             * 
    + * @param {object} colDef the column that was moved + * @param {integer} originalPosition of the column + * @param {integer} finalPosition of the column + */ + colMovable: { + columnPositionChanged: function (colDef, originalPosition, newPosition) { + } + } + }, + methods: { + /** + * @ngdoc method + * @name moveColumn + * @methodOf ui.grid.moveColumns.api:PublicApi + * @description Method can be used to change column position. + *
    +             *      gridApi.colMovable.moveColumn(oldPosition, newPosition)
    +             * 
    + * @param {integer} originalPosition of the column + * @param {integer} finalPosition of the column + */ + colMovable: { + moveColumn: function (originalPosition, finalPosition) { + var columns = grid.columns; + if (!angular.isNumber(originalPosition) || !angular.isNumber(finalPosition)) { + gridUtil.logError('MoveColumn: Please provide valid values for originalPosition and finalPosition'); + return; + } + var nonMovableColumns = 0; + for (var i = 0; i < columns.length; i++) { + if ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true) { + nonMovableColumns++; + } + } + if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) { + gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition'); + return; + } + var findPositionForRenderIndex = function (index) { + var position = index; + for (var i = 0; i <= position; i++) { + if (angular.isDefined(columns[i]) && ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true)) { + position++; + } + } + return position; + }; + self.redrawColumnAtPosition(grid, findPositionForRenderIndex(originalPosition), findPositionForRenderIndex(finalPosition)); + } + } + } + }; + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + }, + defaultGridOptions: function (gridOptions) { + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:GridOptions + * + * @description Options for configuring the move column feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + /** + * @ngdoc object + * @name enableColumnMoving + * @propertyOf ui.grid.moveColumns.api:GridOptions + * @description If defined, sets the default value for the colMovable flag on each individual colDefs + * if their individual enableColumnMoving configuration is not defined. Defaults to true. + */ + gridOptions.enableColumnMoving = gridOptions.enableColumnMoving !== false; + }, + movableColumnBuilder: function (colDef, col, gridOptions) { + var promises = []; + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:ColumnDef + * + * @description Column Definition for move column feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + /** + * @ngdoc object + * @name enableColumnMoving + * @propertyOf ui.grid.moveColumns.api:ColumnDef + * @description Enable column moving for the column. + */ + colDef.enableColumnMoving = colDef.enableColumnMoving === undefined ? gridOptions.enableColumnMoving + : colDef.enableColumnMoving; + return $q.all(promises); + }, + /** + * @ngdoc method + * @name updateColumnCache + * @methodOf ui.grid.moveColumns + * @description Cache the current order of columns, so we can restore them after new columnDefs are defined + */ + updateColumnCache: function(grid) { + grid.moveColumns.orderCache = grid.getOnlyDataColumns(); + }, + /** + * @ngdoc method + * @name verifyColumnOrder + * @methodOf ui.grid.moveColumns + * @description dataChangeCallback which uses the cached column order to restore the column order + * when it is reset by altering the columnDefs array. + */ + verifyColumnOrder: function(grid) { + var headerRowOffset = grid.rowHeaderColumns.length; + var newIndex; + + angular.forEach(grid.moveColumns.orderCache, function(cacheCol, cacheIndex) { + newIndex = grid.columns.indexOf(cacheCol); + if ( newIndex !== -1 && newIndex - headerRowOffset !== cacheIndex ) { + var column = grid.columns.splice(newIndex, 1)[0]; + grid.columns.splice(cacheIndex + headerRowOffset, 0, column); + } + }); + }, + redrawColumnAtPosition: function (grid, originalPosition, newPosition) { + var columns = grid.columns; + + if (originalPosition === newPosition) { + return; + } + + // check columns in between move-range to make sure they are visible columns + var pos = (originalPosition < newPosition) ? originalPosition + 1 : originalPosition - 1; + var i0 = Math.min(pos, newPosition); + for (i0; i0 <= Math.max(pos, newPosition); i0++) { + if (columns[i0].visible) { + break; + } + } + if (i0 > Math.max(pos, newPosition)) { + // no visible column found, column did not visibly move + return; + } + + var originalColumn = columns[originalPosition]; + if (originalColumn.colDef.enableColumnMoving) { + if (originalPosition > newPosition) { + for (var i1 = originalPosition; i1 > newPosition; i1--) { + columns[i1] = columns[i1 - 1]; + } + } + else if (newPosition > originalPosition) { + for (var i2 = originalPosition; i2 < newPosition; i2++) { + columns[i2] = columns[i2 + 1]; + } + } + columns[newPosition] = originalColumn; + service.updateColumnCache(grid); + grid.queueGridRefresh(); + $rootScope.$applyAsync(function () { + grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition); + }); + } + } + }; + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.moveColumns.directive:uiGridMoveColumns + * @element div + * @restrict A + * @description Adds column moving features to the ui-grid directive. + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.moveColumns']); + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO', age: 45 }, + { name: 'Frank', title: 'Lowly Developer', age: 25 }, + { name: 'Jenny', title: 'Highly Developer', age: 35 } + ]; + $scope.columnDefs = [ + {name: 'name'}, + {name: 'title'}, + {name: 'age'} + ]; + }]); + + + .grid { + width: 100%; + height: 150px; + } + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridMoveColumns', ['uiGridMoveColumnService', function (uiGridMoveColumnService) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridMoveColumnService.initializeGrid(uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.moveColumns.directive:uiGridHeaderCell + * @element div + * @restrict A + * + * @description Stacks on top of ui.grid.uiGridHeaderCell to provide capability to be able to move it to reposition column. + * + * On receiving mouseDown event headerCell is cloned, now as the mouse moves the cloned header cell also moved in the grid. + * In case the moving cloned header cell reaches the left or right extreme of grid, grid scrolling is triggered (if horizontal scroll exists). + * On mouseUp event column is repositioned at position where mouse is released and cloned header cell is removed. + * + * Events that invoke cloning of header cell: + * - mousedown + * + * Events that invoke movement of cloned header cell: + * - mousemove + * + * Events that invoke repositioning of column: + * - mouseup + */ + module.directive('uiGridHeaderCell', ['$q', 'gridUtil', 'uiGridMoveColumnService', '$document', '$log', 'uiGridConstants', 'ScrollEvent', + function ($q, gridUtil, uiGridMoveColumnService, $document, $log, uiGridConstants, ScrollEvent) { + return { + priority: -10, + require: '^uiGrid', + compile: function () { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + + if ($scope.col.colDef.enableColumnMoving) { + + /* + * Our general approach to column move is that we listen to a touchstart or mousedown + * event over the column header. When we hear one, then we wait for a move of the same type + * - if we are a touchstart then we listen for a touchmove, if we are a mousedown we listen for + * a mousemove (i.e. a drag) before we decide that there's a move underway. If there's never a move, + * and we instead get a mouseup or a touchend, then we just drop out again and do nothing. + * + */ + var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); + + var gridLeft; + var previousMouseX; + var totalMouseMovement; + var rightMoveLimit; + var elmCloned = false; + var movingElm; + var reducedWidth; + var moveOccurred = false; + + var downFn = function( event ) { + // Setting some variables required for calculations. + gridLeft = $scope.grid.element[0].getBoundingClientRect().left; + if ( $scope.grid.hasLeftContainer() ) { + gridLeft += $scope.grid.renderContainers.left.header[0].getBoundingClientRect().width; + } + + previousMouseX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); + totalMouseMovement = 0; + rightMoveLimit = gridLeft + $scope.grid.getViewportWidth(); + + if ( event.type === 'mousedown' ) { + $document.on('mousemove', moveFn); + $document.on('mouseup', upFn); + } + else if ( event.type === 'touchstart' ) { + $document.on('touchmove', moveFn); + $document.on('touchend', upFn); + } + }; + + var moveFn = function( event ) { + var pageX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); + var changeValue = pageX - previousMouseX; + if ( changeValue === 0 ) { return; } + // Disable text selection in Chrome during column move + document.onselectstart = function() { return false; }; + + moveOccurred = true; + + if (!elmCloned) { + cloneElement(); + } + else if (elmCloned) { + moveElement(changeValue); + previousMouseX = pageX; + } + }; + + var upFn = function( event ) { + // Re-enable text selection after column move + document.onselectstart = null; + + // Remove the cloned element on mouse up. + if (movingElm) { + movingElm.remove(); + elmCloned = false; + } + + offAllEvents(); + onDownEvents(); + + if (!moveOccurred) { + return; + } + + var columns = $scope.grid.columns; + var columnIndex = 0; + for (var i = 0; i < columns.length; i++) { + if (columns[i].colDef.name !== $scope.col.colDef.name) { + columnIndex++; + } + else { + break; + } + } + + var targetIndex; + + // Case where column should be moved to a position on its left + if (totalMouseMovement < 0) { + var totalColumnsLeftWidth = 0; + var il; + if ( $scope.grid.isRTL() ) { + for (il = columnIndex + 1; il < columns.length; il++) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, il - 1); + break; + } + } + } + } + else { + for (il = columnIndex - 1; il >= 0; il--) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, il + 1); + break; + } + } + } + } + + // Case where column should be moved to beginning (or end in RTL) of the grid. + if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) { + targetIndex = 0; + if ( $scope.grid.isRTL() ) { + targetIndex = columns.length - 1; + } + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, targetIndex); + } + } + + // Case where column should be moved to a position on its right + else if (totalMouseMovement > 0) { + var totalColumnsRightWidth = 0; + var ir; + if ( $scope.grid.isRTL() ) { + for (ir = columnIndex - 1; ir > 0; ir--) { + if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) { + totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width; + if (totalColumnsRightWidth > totalMouseMovement) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, ir); + break; + } + } + } + } + else { + for (ir = columnIndex + 1; ir < columns.length; ir++) { + if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) { + totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width; + if (totalColumnsRightWidth > totalMouseMovement) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, ir - 1); + break; + } + } + } + } + + + // Case where column should be moved to end (or beginning in RTL) of the grid. + if (totalColumnsRightWidth < totalMouseMovement) { + targetIndex = columns.length - 1; + if ( $scope.grid.isRTL() ) { + targetIndex = 0; + } + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, targetIndex); + } + } + + + + }; + + var onDownEvents = function() { + $contentsElm.on('touchstart', downFn); + $contentsElm.on('mousedown', downFn); + }; + + var offAllEvents = function() { + $contentsElm.off('touchstart', downFn); + $contentsElm.off('mousedown', downFn); + + $document.off('mousemove', moveFn); + $document.off('touchmove', moveFn); + + $document.off('mouseup', upFn); + $document.off('touchend', upFn); + }; + + onDownEvents(); + + + var cloneElement = function () { + elmCloned = true; + + // Cloning header cell and appending to current header cell. + movingElm = $elm.clone(); + $elm.parent().append(movingElm); + + // Left of cloned element should be aligned to original header cell. + movingElm.addClass('movingColumn'); + var movingElementStyles = {}; + movingElementStyles.left = $elm[0].offsetLeft + 'px'; + var gridRight = $scope.grid.element[0].getBoundingClientRect().right; + var elmRight = $elm[0].getBoundingClientRect().right; + if (elmRight > gridRight) { + reducedWidth = $scope.col.drawnWidth + (gridRight - elmRight); + movingElementStyles.width = reducedWidth + 'px'; + } + movingElm.css(movingElementStyles); + }; + + var moveElement = function (changeValue) { + // Calculate total column width + var columns = $scope.grid.columns; + var totalColumnWidth = 0; + for (var i = 0; i < columns.length; i++) { + if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) { + totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width; + } + } + + // Calculate new position of left of column + var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1; + var currentElmRight = movingElm[0].getBoundingClientRect().right; + var newElementLeft; + + newElementLeft = currentElmLeft - gridLeft + changeValue; + newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit; + + // Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid + if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) { + movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft + + (newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'}); + } + else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) { + changeValue *= 8; + var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement'); + scrollEvent.x = {pixels: changeValue}; + scrollEvent.grid.scrollContainers('',scrollEvent); + } + + // Calculate total width of columns on the left of the moving column and the mouse movement + var totalColumnsLeftWidth = 0; + for (var il = 0; il < columns.length; il++) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + if (columns[il].colDef.name !== $scope.col.colDef.name) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + } + else { + break; + } + } + } + if ($scope.newScrollLeft === undefined) { + totalMouseMovement += changeValue; + } + else { + totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth; + } + + // Increase width of moving column, in case the rightmost column was moved and its width was + // decreased because of overflow + if (reducedWidth < $scope.col.drawnWidth) { + reducedWidth += Math.abs(changeValue); + movingElm.css({'width': reducedWidth + 'px'}); + } + }; + + $scope.$on('$destroy', offAllEvents); + } + } + }; + } + }; + }]); +})(); diff --git a/src/i18n/ui-grid.move-columns.min.js b/src/i18n/ui-grid.move-columns.min.js new file mode 100644 index 0000000000..8a6a57d241 --- /dev/null +++ b/src/i18n/ui-grid.move-columns.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.moveColumns",["ui.grid"]);e.service("uiGridMoveColumnService",["$q","$rootScope","$log","ScrollEvent","uiGridConstants","gridUtil",function(o,d,e,i,s,u){var f={initializeGrid:function(e){this.registerPublicApi(e),this.defaultGridOptions(e.options),e.moveColumns={orderCache:[]},e.registerColumnBuilder(this.movableColumnBuilder),e.registerDataChangeCallback(this.verifyColumnOrder,[s.dataChange.COLUMN])},registerPublicApi:function(t){var a=this,e={events:{colMovable:{columnPositionChanged:function(e,i,n){}}},methods:{colMovable:{moveColumn:function(e,i){var o=t.columns;if(angular.isNumber(e)&&angular.isNumber(i)){for(var n=0,r=0;r=o.length-n||i>=o.length-n)u.logError("MoveColumn: Invalid values for originalPosition, finalPosition");else{var l=function(e){for(var i=e,n=0;n<=i;n++)angular.isDefined(o[n])&&(angular.isDefined(o[n].colDef.visible)&&!1===o[n].colDef.visible||!0===o[n].isRowHeader)&&i++;return i};a.redrawColumnAtPosition(t,l(e),l(i))}}else u.logError("MoveColumn: Please provide valid values for originalPosition and finalPosition")}}}};t.api.registerEventsFromObject(e.events),t.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enableColumnMoving=!1!==e.enableColumnMoving},movableColumnBuilder:function(e,i,n){return e.enableColumnMoving=void 0===e.enableColumnMoving?n.enableColumnMoving:e.enableColumnMoving,o.all([])},updateColumnCache:function(e){e.moveColumns.orderCache=e.getOnlyDataColumns()},verifyColumnOrder:function(o){var r,l=o.rowHeaderColumns.length;angular.forEach(o.moveColumns.orderCache,function(e,i){if(-1!==(r=o.columns.indexOf(e))&&r-l!==i){var n=o.columns.splice(r,1)[0];o.columns.splice(i+l,0,n)}})},redrawColumnAtPosition:function(e,i,n){var o=e.columns;if(i!==n){for(var r=iMath.max(r,n))){var t=o[i];if(t.colDef.enableColumnMoving){if(nMath.abs(g)){w.redrawColumnAtPosition(s.grid,o,l-1);break}}else for(l=o-1;0<=l;l--)if((angular.isUndefined(n[l].colDef.visible)||!0===n[l].colDef.visible)&&(t+=n[l].drawnWidth||n[l].width||n[l].colDef.width)>Math.abs(g)){w.redrawColumnAtPosition(s.grid,o,l+1);break}tMath.ceil(f.grid.gridWidth)){e*=8;var a=new M(s.col.grid,null,null,"uiGridHeaderCell.moveElement");a.x={pixels:e},a.grid.scrollContainers("",a)}for(var u=0,d=0;d 0) { gridOptions.paginationPageSize = gridOptions.paginationPageSizes[0]; - } else { + } + else { gridOptions.paginationPageSize = 0; } } @@ -293,10 +300,10 @@ * @param {int} pageSize requested page size */ onPaginationChanged: function (grid, currentPage, pageSize) { - grid.api.pagination.raise.paginationChanged(currentPage, pageSize); - if (!grid.options.useExternalPagination) { - grid.queueGridRefresh(); //client side pagination - } + grid.api.pagination.raise.paginationChanged(currentPage, pageSize); + if (!grid.options.useExternalPagination) { + grid.queueGridRefresh(); // client side pagination + } } }; @@ -362,6 +369,7 @@ gridUtil.getTemplate(uiGridCtrl.grid.options.paginationTemplate) .then(function (contents) { var template = angular.element(contents); + $elm.append(template); uiGridCtrl.innerCompile(template); }); @@ -378,26 +386,35 @@ * * @description Panel for handling pagination */ - module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService', - function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService) { + module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService', 'i18nConstants', + function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService, i18nConstants) { return { priority: -200, scope: true, require: '^uiGrid', link: function ($scope, $elm, $attr, uiGridCtrl) { var defaultFocusElementSelector = '.ui-grid-pager-control-input'; - $scope.aria = i18nService.getSafeText('pagination.aria'); //Returns an object with all of the aria labels - $scope.paginationApi = uiGridCtrl.grid.api.pagination; - $scope.sizesLabel = i18nService.getSafeText('pagination.sizes'); - $scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems'); - $scope.paginationOf = i18nService.getSafeText('pagination.of'); - $scope.paginationThrough = i18nService.getSafeText('pagination.through'); + $scope.aria = i18nService.getSafeText('pagination.aria'); // Returns an object with all of the aria labels + + var updateLabels = function() { + $scope.paginationApi = uiGridCtrl.grid.api.pagination; + $scope.sizesLabel = i18nService.getSafeText('pagination.sizes'); + $scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems'); + $scope.paginationOf = i18nService.getSafeText('pagination.of'); + $scope.paginationThrough = i18nService.getSafeText('pagination.through'); + }; + + updateLabels(); + + $scope.$on(i18nConstants.UPDATE_EVENT, updateLabels); var options = uiGridCtrl.grid.options; uiGridCtrl.grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { - adjustment.height = adjustment.height - gridUtil.elementHeight($elm, "padding"); + if (options.enablePaginationControls) { + adjustment.height = adjustment.height - gridUtil.elementHeight($elm, "padding"); + } return adjustment; }); @@ -410,23 +427,22 @@ $scope.$on('$destroy', dataChangeDereg); var deregP = $scope.$watch('grid.options.paginationCurrentPage + grid.options.paginationPageSize', function (newValues, oldValues) { - if (newValues === oldValues || oldValues === undefined) { - return; - } - - if (!angular.isNumber(options.paginationCurrentPage) || options.paginationCurrentPage < 1) { - options.paginationCurrentPage = 1; - return; - } + if (newValues === oldValues || oldValues === undefined) { + return; + } - if (options.totalItems > 0 && options.paginationCurrentPage > $scope.paginationApi.getTotalPages()) { - options.paginationCurrentPage = $scope.paginationApi.getTotalPages(); - return; - } + if (!angular.isNumber(options.paginationCurrentPage) || options.paginationCurrentPage < 1) { + options.paginationCurrentPage = 1; + return; + } - uiGridPaginationService.onPaginationChanged($scope.grid, options.paginationCurrentPage, options.paginationPageSize); + if (options.totalItems > 0 && options.paginationCurrentPage > $scope.paginationApi.getTotalPages()) { + options.paginationCurrentPage = $scope.paginationApi.getTotalPages(); + return; } - ); + + uiGridPaginationService.onPaginationChanged($scope.grid, options.paginationCurrentPage, options.paginationPageSize); + }); $scope.$on('$destroy', function() { deregP(); @@ -435,13 +451,15 @@ $scope.cantPageForward = function () { if ($scope.paginationApi.getTotalPages()) { return $scope.cantPageToLast(); - } else { + } + else { return options.data.length < 1; } }; $scope.cantPageToLast = function () { var totalPages = $scope.paginationApi.getTotalPages(); + return !totalPages || options.paginationCurrentPage >= totalPages; }; @@ -449,13 +467,13 @@ return options.paginationCurrentPage <= 1; }; - var focusToInputIf = function(condition){ - if (condition){ + var focusToInputIf = function(condition) { + if (condition) { gridUtil.focus.bySelector($elm, defaultFocusElementSelector); } }; - //Takes care of setting focus to the middle element when focus is lost + // Takes care of setting focus to the middle element when focus is lost $scope.pageFirstPageClick = function () { $scope.paginationApi.seek(1); focusToInputIf($scope.cantPageBackward()); @@ -475,9 +493,17 @@ $scope.paginationApi.seek($scope.paginationApi.getTotalPages()); focusToInputIf($scope.cantPageToLast()); }; - } }; } ]); })(); + +angular.module('ui.grid.pagination').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/pagination', + "
    0\">/ {{ paginationApi.getTotalPages() }}
    1 && !grid.options.useCustomPagination\">  {{sizesLabel}}
    {{grid.options.paginationPageSize}} {{sizesLabel}}
    0\">{{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    " + ); + +}]); diff --git a/src/i18n/ui-grid.pagination.min.js b/src/i18n/ui-grid.pagination.min.js new file mode 100644 index 0000000000..eeffd63863 --- /dev/null +++ b/src/i18n/ui-grid.pagination.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var i=angular.module("ui.grid.pagination",["ng","ui.grid"]);i.service("uiGridPaginationService",["gridUtil",function(a){var i={initializeGrid:function(o){i.defaultGridOptions(o.options);var g={events:{pagination:{paginationChanged:function(i,a){}}},methods:{pagination:{getPage:function(){return o.options.enablePagination?o.options.paginationCurrentPage:null},getFirstRowIndex:function(){return o.options.useCustomPagination?o.options.paginationPageSizes.reduce(function(i,a,n){return nn.length&&(t=((o.options.paginationCurrentPage=1)-1)*a),n.slice(t,e+1)},900)},defaultGridOptions:function(i){i.enablePagination=!1!==i.enablePagination,i.enablePaginationControls=!1!==i.enablePaginationControls,i.useExternalPagination=!0===i.useExternalPagination,i.useCustomPagination=!0===i.useCustomPagination,a.isNullOrUndefined(i.totalItems)&&(i.totalItems=0),a.isNullOrUndefined(i.paginationPageSizes)&&(i.paginationPageSizes=[250,500,1e3]),a.isNullOrUndefined(i.paginationPageSize)&&(0n.paginationApi.getTotalPages()?o.paginationCurrentPage=n.paginationApi.getTotalPages():p.onPaginationChanged(n.grid,o.paginationCurrentPage,o.paginationPageSize))});n.$on("$destroy",function(){r()}),n.cantPageForward=function(){return n.paginationApi.getTotalPages()?n.cantPageToLast():o.data.length<1},n.cantPageToLast=function(){var i=n.paginationApi.getTotalPages();return!i||o.paginationCurrentPage>=i},n.cantPageBackward=function(){return o.paginationCurrentPage<=1};var s=function(i){i&&u.focus.bySelector(a,".ui-grid-pager-control-input")};n.pageFirstPageClick=function(){n.paginationApi.seek(1),s(n.cantPageBackward())},n.pagePreviousPageClick=function(){n.paginationApi.previousPage(),s(n.cantPageBackward())},n.pageNextPageClick=function(){n.paginationApi.nextPage(),s(n.cantPageForward())},n.pageLastPageClick=function(){n.paginationApi.seek(n.paginationApi.getTotalPages()),s(n.cantPageToLast())}}}}])}(),angular.module("ui.grid.pagination").run(["$templateCache",function(i){"use strict";i.put("ui-grid/pagination",'
    {{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    ')}]); \ No newline at end of file diff --git a/src/features/pinning/js/pinning.js b/src/i18n/ui-grid.pinning.js similarity index 80% rename from src/features/pinning/js/pinning.js rename to src/i18n/ui-grid.pinning.js index 9a9300b48c..c46cb24705 100644 --- a/src/features/pinning/js/pinning.js +++ b/src/i18n/ui-grid.pinning.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -45,7 +50,7 @@ pinning: { /** * @ngdoc event - * @name columnPin + * @name columnPinned * @eventOf ui.grid.pinning.api:PublicApi * @description raised when column pin state has changed *
    @@ -84,7 +89,7 @@
           },
     
           defaultGridOptions: function (gridOptions) {
    -        //default option to true unless it was explicitly set to false
    +        // default option to true unless it was explicitly set to false
             /**
              *  @ngdoc object
              *  @name ui.grid.pinning.api:GridOptions
    @@ -101,11 +106,26 @@
              *  
    Defaults to true */ gridOptions.enablePinning = gridOptions.enablePinning !== false; - + /** + * @ngdoc object + * @name hidePinLeft + * @propertyOf ui.grid.pinning.api:GridOptions + * @description Hide Pin Left for the entire grid. + *
    Defaults to false + */ + gridOptions.hidePinLeft = gridOptions.enablePinning && gridOptions.hidePinLeft; + /** + * @ngdoc object + * @name hidePinRight + * @propertyOf ui.grid.pinning.api:GridOptions + * @description Hide Pin Right pinning for the entire grid. + *
    Defaults to false + */ + gridOptions.hidePinRight = gridOptions.enablePinning && gridOptions.hidePinRight; }, pinningColumnBuilder: function (colDef, col, gridOptions) { - //default to true unless gridOptions or colDef is explicitly false + // default to true unless gridOptions or colDef is explicitly false /** * @ngdoc object @@ -123,7 +143,22 @@ *
    Defaults to true */ colDef.enablePinning = colDef.enablePinning === undefined ? gridOptions.enablePinning : colDef.enablePinning; - + /** + * @ngdoc object + * @name hidePinLeft + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Hide Pin Left for the individual column. + *
    Defaults to false + */ + colDef.hidePinLeft = colDef.hidePinLeft === undefined ? gridOptions.hidePinLeft : colDef.hidePinLeft; + /** + * @ngdoc object + * @name hidePinRight + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Hide Pin Right for the individual column. + *
    Defaults to false + */ + colDef.hidePinRight = colDef.hidePinRight === undefined ? gridOptions.hidePinRight : colDef.hidePinRight; /** * @ngdoc object @@ -189,10 +224,11 @@ } }; - if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinLeft')) { + // Skip from menu if hidePinLeft or hidePinRight is true + if (!colDef.hidePinLeft && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinLeft')) { col.menuItems.push(pinColumnLeftAction); } - if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinRight')) { + if (!colDef.hidePinRight && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinRight')) { col.menuItems.push(pinColumnRightAction); } if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.unpin')) { @@ -241,6 +277,4 @@ } }; }]); - - })(); diff --git a/src/i18n/ui-grid.pinning.min.js b/src/i18n/ui-grid.pinning.min.js new file mode 100644 index 0000000000..210185ca0d --- /dev/null +++ b/src/i18n/ui-grid.pinning.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var n=angular.module("ui.grid.pinning",["ui.grid"]);n.constant("uiGridPinningConstants",{container:{LEFT:"left",RIGHT:"right",NONE:""}}),n.service("uiGridPinningService",["gridUtil","GridRenderContainer","i18nService","uiGridPinningConstants",function(c,n,d,u){var a={initializeGrid:function(e){a.defaultGridOptions(e.options),e.registerColumnBuilder(a.pinningColumnBuilder);var n={events:{pinning:{columnPinned:function(n,i){}}},methods:{pinning:{pinColumn:function(n,i){a.pinColumn(e,n,i)}}}};e.api.registerEventsFromObject(n.events),e.api.registerMethodsFromObject(n.methods)},defaultGridOptions:function(n){n.enablePinning=!1!==n.enablePinning,n.hidePinLeft=n.enablePinning&&n.hidePinLeft,n.hidePinRight=n.enablePinning&&n.hidePinRight},pinningColumnBuilder:function(n,i,e){if(n.enablePinning=void 0===n.enablePinning?e.enablePinning:n.enablePinning,n.hidePinLeft=void 0===n.hidePinLeft?e.hidePinLeft:n.hidePinLeft,n.hidePinRight=void 0===n.hidePinRight?e.hidePinRight:n.hidePinRight,n.pinnedLeft?(i.renderContainer="left",i.grid.createLeftContainer()):n.pinnedRight&&(i.renderContainer="right",i.grid.createRightContainer()),n.enablePinning){var t={name:"ui.grid.pinning.pinLeft",title:d.get().pinning.pinLeft,icon:"ui-grid-icon-left-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"left"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.LEFT)}},r={name:"ui.grid.pinning.pinRight",title:d.get().pinning.pinRight,icon:"ui-grid-icon-right-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"right"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.RIGHT)}},o={name:"ui.grid.pinning.unpin",title:d.get().pinning.unpin,icon:"ui-grid-icon-cancel",shown:function(){return void 0!==this.context.col.renderContainer&&null!==this.context.col.renderContainer&&"body"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.NONE)}};n.hidePinLeft||c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.pinLeft")||i.menuItems.push(t),n.hidePinRight||c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.pinRight")||i.menuItems.push(r),c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.unpin")||i.menuItems.push(o)}},pinColumn:function(n,i,e){e===u.container.NONE?(i.renderContainer=null,i.colDef.pinnedLeft=i.colDef.pinnedRight=!1):(i.renderContainer=e)===u.container.LEFT?n.createLeftContainer():e===u.container.RIGHT&&n.createRightContainer(),n.refresh().then(function(){n.api.pinning.raise.columnPinned(i.colDef,e)})}};return a}]),n.directive("uiGridPinning",["gridUtil","uiGridPinningService",function(n,r){return{require:"uiGrid",scope:!1,compile:function(){return{pre:function(n,i,e,t){r.initializeGrid(t.grid)},post:function(n,i,e,t){}}}}}])}(); \ No newline at end of file diff --git a/src/features/resize-columns/js/ui-grid-column-resizer.js b/src/i18n/ui-grid.resize-columns.js similarity index 77% rename from src/features/resize-columns/js/ui-grid-column-resizer.js rename to src/i18n/ui-grid.resize-columns.js index 282e0187bb..e1e705384e 100644 --- a/src/features/resize-columns/js/ui-grid-column-resizer.js +++ b/src/i18n/ui-grid.resize-columns.js @@ -1,4 +1,9 @@ -(function(){ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { 'use strict'; /** @@ -14,12 +19,11 @@ */ var module = angular.module('ui.grid.resizeColumns', ['ui.grid']); - module.service('uiGridResizeColumnsService', ['gridUtil', '$q', '$timeout', - function (gridUtil, $q, $timeout) { - - var service = { - defaultGridOptions: function(gridOptions){ - //default option to true unless it was explicitly set to false + module.service('uiGridResizeColumnsService', ['gridUtil', '$q', '$rootScope', + function (gridUtil, $q, $rootScope) { + return { + defaultGridOptions: function(gridOptions) { + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.resizeColumns.api:GridOptions @@ -37,16 +41,16 @@ */ gridOptions.enableColumnResizing = gridOptions.enableColumnResizing !== false; - //legacy support - //use old name if it is explicitly false - if (gridOptions.enableColumnResize === false){ + // legacy support + // use old name if it is explicitly false + if (gridOptions.enableColumnResize === false) { gridOptions.enableColumnResizing = false; } }, colResizerColumnBuilder: function (colDef, col, gridOptions) { - var promises = []; + /** * @ngdoc object * @name ui.grid.resizeColumns.api:ColumnDef @@ -62,12 +66,12 @@ * @description Enable column resizing on an individual column *
    Defaults to GridOptions.enableColumnResizing */ - //default to true unless gridOptions or colDef is explicitly false + // default to true unless gridOptions or colDef is explicitly false colDef.enableColumnResizing = colDef.enableColumnResizing === undefined ? gridOptions.enableColumnResizing : colDef.enableColumnResizing; - //legacy support of old option name - if (colDef.enableColumnResize === false){ + // legacy support of old option name + if (colDef.enableColumnResize === false) { colDef.enableColumnResizing = false; } @@ -88,7 +92,7 @@ * @eventOf ui.grid.resizeColumns.api:PublicApi * @description raised when column is resized *
    -                 *      gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange){})
    +                 *      gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange) {})
                      * 
    * @param {object} colDef the column that was resized * @param {integer} delta of the column size change @@ -103,8 +107,8 @@ }, fireColumnSizeChanged: function (grid, colDef, deltaChange) { - $timeout(function () { - if ( grid.api.colResizable ){ + $rootScope.$applyAsync(function () { + if ( grid.api.colResizable ) { grid.api.colResizable.raise.columnSizeChanged(colDef, deltaChange); } else { gridUtil.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events."); @@ -114,22 +118,21 @@ // get either this column, or the column next to this column, to resize, // returns the column we're going to resize - findTargetCol: function(col, position, rtlMultiplier){ + findTargetCol: function(col, position, rtlMultiplier) { var renderContainer = col.getRenderContainer(); if (position === 'left') { // Get the column to the left of this one var colIndex = renderContainer.visibleColumnCache.indexOf(col); + if (colIndex === 0) { + return renderContainer.visibleColumnCache[0]; + } return renderContainer.visibleColumnCache[colIndex - 1 * rtlMultiplier]; } else { return col; } } - }; - - return service; - }]); @@ -190,7 +193,7 @@ }]); // Extend the uiGridHeaderCell directive - module.directive('uiGridHeaderCell', ['gridUtil', '$templateCache', '$compile', '$q', 'uiGridResizeColumnsService', 'uiGridConstants', '$timeout', function (gridUtil, $templateCache, $compile, $q, uiGridResizeColumnsService, uiGridConstants, $timeout) { + module.directive('uiGridHeaderCell', ['gridUtil', '$templateCache', '$compile', '$q', 'uiGridResizeColumnsService', 'uiGridConstants', function (gridUtil, $templateCache, $compile, $q, uiGridResizeColumnsService, uiGridConstants) { return { // Run after the original uiGridHeaderCell priority: -10, @@ -201,59 +204,57 @@ post: function ($scope, $elm, $attrs, uiGridCtrl) { var grid = uiGridCtrl.grid; - var columnResizerElm = $templateCache.get('ui-grid/columnResizer'); + if (grid.options.enableColumnResizing) { + var columnResizerElm = $templateCache.get('ui-grid/columnResizer'); - var rtlMultiplier = 1; - //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left - if (grid.isRTL()) { - $scope.position = 'left'; - rtlMultiplier = -1; - } - - var displayResizers = function(){ - - // remove any existing resizers. - var resizers = $elm[0].getElementsByClassName('ui-grid-column-resizer'); - for ( var i = 0; i < resizers.length; i++ ){ - angular.element(resizers[i]).remove(); + var rtlMultiplier = 1; + // when in RTL mode reverse the direction using the rtlMultiplier and change the position to left + if (grid.isRTL()) { + $scope.position = 'left'; + rtlMultiplier = -1; } - if (!grid.options.enableColumnResizing) { - return; - } + var displayResizers = function() { - // get the target column for the left resizer - var otherCol = uiGridResizeColumnsService.findTargetCol($scope.col, 'left', rtlMultiplier); - var renderContainer = $scope.col.getRenderContainer(); + // remove any existing resizers. + var resizers = $elm[0].getElementsByClassName('ui-grid-column-resizer'); + for ( var i = 0; i < resizers.length; i++ ) { + angular.element(resizers[i]).remove(); + } - // Don't append the left resizer if this is the first column or the column to the left of this one has resizing disabled - if (otherCol && renderContainer.visibleColumnCache.indexOf($scope.col) !== 0 && otherCol.colDef.enableColumnResizing && !(otherCol.colDef.pinnedLeft || otherCol.colDef.pinnedRight)) { - var resizerLeft = angular.element(columnResizerElm).clone(); - resizerLeft.attr('position', 'left'); + // get the target column for the left resizer + var otherCol = uiGridResizeColumnsService.findTargetCol($scope.col, 'left', rtlMultiplier); + var renderContainer = $scope.col.getRenderContainer(); - $elm.prepend(resizerLeft); - $compile(resizerLeft)($scope); - } + // Don't append the left resizer if this is the first column or the column to the left of this one has resizing disabled + if (otherCol && renderContainer.visibleColumnCache.indexOf($scope.col) !== 0 && otherCol.colDef.enableColumnResizing !== false) { + var resizerLeft = angular.element(columnResizerElm).clone(); + resizerLeft.attr('position', 'left'); + + $elm.prepend(resizerLeft); + $compile(resizerLeft)($scope); + } - // Don't append the right resizer if this column has resizing disabled - if (!$scope.col.colDef.pinnedLeft && !$scope.col.colDef.pinnedRight && $scope.col.colDef.enableColumnResizing) { - var resizerRight = angular.element(columnResizerElm).clone(); - resizerRight.attr('position', 'right'); + // Don't append the right resizer if this column has resizing disabled + if ($scope.col.colDef.enableColumnResizing !== false) { + var resizerRight = angular.element(columnResizerElm).clone(); + resizerRight.attr('position', 'right'); - $elm.append(resizerRight); - $compile(resizerRight)($scope); - } - }; + $elm.append(resizerRight); + $compile(resizerRight)($scope); + } + }; - displayResizers(); + displayResizers(); - var waitDisplay = function(){ - $timeout(displayResizers); - }; + var waitDisplay = function() { + $scope.$applyAsync(displayResizers); + }; - var dataChangeDereg = grid.registerDataChangeCallback( waitDisplay, [uiGridConstants.dataChange.COLUMN] ); + var dataChangeDereg = grid.registerDataChangeCallback( waitDisplay, [uiGridConstants.dataChange.COLUMN] ); - $scope.$on( '$destroy', dataChangeDereg ); + $scope.$on( '$destroy', dataChangeDereg ); + } } }; } @@ -304,7 +305,7 @@ module.directive('uiGridColumnResizer', ['$document', 'gridUtil', 'uiGridConstants', 'uiGridResizeColumnsService', function ($document, gridUtil, uiGridConstants, uiGridResizeColumnsService) { var resizeOverlay = angular.element('
    '); - var resizer = { + return { priority: 0, scope: { col: '=', @@ -318,7 +319,7 @@ gridLeft = 0, rtlMultiplier = 1; - //when in RTL mode reverse the direction using the rtlMultiplier and change the position to left + // when in RTL mode reverse the direction using the rtlMultiplier and change the position to left if (uiGridCtrl.grid.isRTL()) { $scope.position = 'left'; rtlMultiplier = -1; @@ -342,7 +343,7 @@ // Check that the requested width isn't wider than the maxWidth, or narrower than the minWidth // Returns the new recommended with, after constraints applied - function constrainWidth(col, width){ + function constrainWidth(col, width) { var newWidth = width; // If the new width would be less than the column's allowably minimum width, don't allow it @@ -377,7 +378,7 @@ var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); // Don't resize if it's disabled on this column - if (col.colDef.enableColumnResizing === false && uiGridCtrl.grid.options.enableColumnResizing !== true) { + if (col.colDef.enableColumnResizing === false) { return; } @@ -400,7 +401,7 @@ } - function upFunction(event, args) { + function upFunction(event) { if (event.originalEvent) { event = event.originalEvent; } event.preventDefault(); @@ -423,7 +424,7 @@ var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); // Don't resize if it's disabled on this column - if (col.colDef.enableColumnResizing === false && uiGridCtrl.grid.options.enableColumnResizing !== true) { + if (col.colDef.enableColumnResizing === false) { return; } @@ -466,11 +467,12 @@ // we were touchdown then we listen for touchmove and touchup. Also remove the handler for the equivalent // down event - so if we're touchdown, then remove the mousedown handler until this event is over, if we're // mousedown then remove the touchdown handler until this event is over, this avoids processing duplicate events - if ( event.type === 'touchstart' ){ + if ( event.type === 'touchstart' ) { $document.on('touchend', upFunction); $document.on('touchmove', moveFunction); $elm.off('mousedown', downFunction); - } else { + } + else { $document.on('mouseup', upFunction); $document.on('mousemove', moveFunction); $elm.off('touchstart', downFunction); @@ -495,19 +497,18 @@ // On doubleclick, resize to fit all rendered cells - var dblClickFn = function(event, args){ + var dblClickFn = function(event, args) { event.stopPropagation(); var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); // Don't resize if it's disabled on this column - if (col.colDef.enableColumnResizing === false && uiGridCtrl.grid.options.enableColumnResizing !== true) { + if (col.colDef.enableColumnResizing === false) { return; } // Go through the rendered rows and find out the max size for the data in this column var maxWidth = 0; - var xDiff = 0; // Get the parent render container element var renderContainerElm = gridUtil.closestElm($elm, '.ui-grid-render-container'); @@ -515,35 +516,20 @@ // Get the cell contents so we measure correctly. For the header cell we have to account for the sort icon and the menu buttons, if present var cells = renderContainerElm.querySelectorAll('.' + uiGridConstants.COL_CLASS_PREFIX + col.uid + ' .ui-grid-cell-contents'); Array.prototype.forEach.call(cells, function (cell) { + // Get the cell width + // gridUtil.logDebug('width', gridUtil.elementWidth(cell)); // Account for the menu button if it exists var menuButton; if (angular.element(cell).parent().hasClass('ui-grid-header-cell')) { menuButton = angular.element(cell).parent()[0].querySelectorAll('.ui-grid-column-menu-button'); } - // Make the element float since it's a div and can expand to fill its container - // include the cell's font properties since they affect the width. - var style = angular.element(cell).css([ - 'font', - 'fontDisplay', - 'fontFamily', - 'fontFeatureSettings', - 'fontKerning', - 'fontSize', - 'fontStretch', - 'fontStyle', - 'fontVariant', - 'fontVariantCaps', - 'fontVariantEastAsian', - 'fontVariantLigatures', - 'fontVariantNumeric', - 'fontVariationSettings', - 'fontWeight']); - style.float = 'left'; - - gridUtil.fakeElement(cell, style, function(newElm) { - + + gridUtil.fakeElement(cell, {}, function(newElm) { + // Make the element float since it's a div and can expand to fill its container var e = angular.element(newElm); + e.attr('style', 'float: left'); + var width = gridUtil.elementWidth(e); if (menuButton) { @@ -551,16 +537,16 @@ width = width + menuButtonWidth; } - width = Math.ceil(width); if (width > maxWidth) { maxWidth = width; - xDiff = maxWidth - width; } }); }); // check we're not outside the allowable bounds for this column - col.width = constrainWidth(col, maxWidth); + var newWidth = constrainWidth(col, maxWidth); + var xDiff = newWidth - col.drawnWidth; + col.width = newWidth; col.hasCustomWidth = true; refreshCanvas(xDiff); @@ -574,8 +560,14 @@ }); } }; - - return resizer; }]); +})(); + +angular.module('ui.grid.resizeColumns').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/columnResizer', + "
    " + ); -})(); \ No newline at end of file +}]); diff --git a/src/i18n/ui-grid.resize-columns.min.js b/src/i18n/ui-grid.resize-columns.min.js new file mode 100644 index 0000000000..9871bfcad5 --- /dev/null +++ b/src/i18n/ui-grid.resize-columns.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.resizeColumns",["ui.grid"]);e.service("uiGridResizeColumnsService",["gridUtil","$q","$rootScope",function(r,o,t){return{defaultGridOptions:function(e){e.enableColumnResizing=!1!==e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1)},colResizerColumnBuilder:function(e,i,n){return e.enableColumnResizing=void 0===e.enableColumnResizing?n.enableColumnResizing:e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1),o.all([])},registerPublicApi:function(e){e.api.registerEventsFromObject({colResizable:{columnSizeChanged:function(e,i){}}})},fireColumnSizeChanged:function(e,i,n){t.$applyAsync(function(){e.api.colResizable?e.api.colResizable.raise.columnSizeChanged(i,n):r.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events.")})},findTargetCol:function(e,i,n){var r=e.getRenderContainer();if("left"!==i)return e;var o=r.visibleColumnCache.indexOf(e);return 0===o?r.visibleColumnCache[0]:r.visibleColumnCache[o-1*n]}}}]),e.directive("uiGridResizeColumns",["gridUtil","uiGridResizeColumnsService",function(e,o){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,n,r){o.defaultGridOptions(r.grid.options),r.grid.registerColumnBuilder(o.colResizerColumnBuilder),o.registerPublicApi(r.grid)},post:function(e,i,n,r){}}}}}]),e.directive("uiGridHeaderCell",["gridUtil","$templateCache","$compile","$q","uiGridResizeColumnsService","uiGridConstants",function(e,t,d,i,c,g){return{priority:-10,require:"^uiGrid",compile:function(){return{post:function(l,u,e,i){var n=i.grid;if(n.options.enableColumnResizing){var a=t.get("ui-grid/columnResizer"),s=1;n.isRTL()&&(l.position="left",s=-1);var r=function(){for(var e=u[0].getElementsByClassName("ui-grid-column-resizer"),i=0;i
    ');return{priority:0,scope:{col:"=",position:"@",renderIndex:"="},require:"?^uiGrid",link:function(u,a,e,s){var t=0,l=0,d=0,c=1;function g(e){s.grid.refreshCanvas(!0).then(function(){s.grid.queueGridRefresh()})}function f(e,i){var n=i;return e.minWidth&&ne.maxWidth&&(n=e.maxWidth),n}function n(e,i){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),(l=(e.targetTouches?e.targetTouches[0]:e).clientX-d)<0?l=0:l>s.grid.gridWidth&&(l=s.grid.gridWidth);var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){s.grid.element.hasClass("column-resizing")||s.grid.element.addClass("column-resizing");var r=l-t,o=parseInt(n.drawnWidth+r*c,10);l+=(f(n,o)-o)*c,R.css({left:l+"px"}),s.fireEvent(p.events.ITEM_DRAGGING)}}function r(e){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),s.grid.element.removeClass("column-resizing"),R.remove();var i=(l=(e.changedTouches?e.changedTouches[0]:e).clientX-d)-t;if(0===i)return C(),void m();var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){var r=parseInt(n.drawnWidth+i*c,10);n.width=f(n,r),n.hasCustomWidth=!0,g(),z.fireColumnSizeChanged(s.grid,n.colDef,i),C(),m()}}s.grid.isRTL()&&(u.position="left",c=-1),"left"===u.position?a.addClass("left"):"right"===u.position&&a.addClass("right");var o=function(e,i){e.originalEvent&&(e=e.originalEvent),e.stopPropagation(),d=s.grid.element[0].getBoundingClientRect().left,t=(e.targetTouches?e.targetTouches[0]:e).clientX-d,s.grid.element.append(R),R.css({left:t}),"touchstart"===e.type?(v.on("touchend",r),v.on("touchmove",n),a.off("mousedown",o)):(v.on("mouseup",r),v.on("mousemove",n),a.off("touchstart",o))},m=function(){a.on("mousedown",o),a.on("touchstart",o)},C=function(){v.off("mouseup",r),v.off("touchend",r),v.off("mousemove",n),v.off("touchmove",n),a.off("mousedown",o),a.off("touchstart",o)};m();var i=function(e,i){e.stopPropagation();var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){var o=0,r=h.closestElm(a,".ui-grid-render-container").querySelectorAll("."+p.COL_CLASS_PREFIX+n.uid+" .ui-grid-cell-contents");Array.prototype.forEach.call(r,function(e){var r;angular.element(e).parent().hasClass("ui-grid-header-cell")&&(r=angular.element(e).parent()[0].querySelectorAll(".ui-grid-column-menu-button")),h.fakeElement(e,{},function(e){var i=angular.element(e);i.attr("style","float: left");var n=h.elementWidth(i);r&&(n+=h.elementWidth(r));o
    ')}]); \ No newline at end of file diff --git a/src/features/row-edit/js/gridRowEdit.js b/src/i18n/ui-grid.row-edit.js similarity index 92% rename from src/features/row-edit/js/gridRowEdit.js rename to src/i18n/ui-grid.row-edit.js index a6b0109eb4..fae86ff4c5 100644 --- a/src/features/row-edit/js/gridRowEdit.js +++ b/src/i18n/ui-grid.row-edit.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -70,7 +75,7 @@ * whilst this promise is being resolved. * *
    -                 *      gridApi.rowEdit.on.saveRow(scope,function(rowEntity){})
    +                 *      gridApi.rowEdit.on.saveRow(scope,function(rowEntity) {})
                      * 
    * and somewhere within the event handler: *
    @@ -156,10 +161,11 @@
                      * @methodOf ui.grid.rowEdit.api:PublicApi
                      * @name setRowsDirty
                      * @description Sets each of the rows passed in dataRows
    -                 * to be dirty.  note that if you have only just inserted the
    +                 * to be dirty. Note that if you have only just inserted the
                      * rows into your data you will need to wait for a $digest cycle
                      * before the gridRows are present - so often you would wrap this
    -                 * call in a $interval or $timeout
    +                 * call in a $interval or $timeout. Also, you must pass row.entity
    +                 * into this function rather than row objects themselves.
                      * 
                      *      $interval( function() {
                      *        gridApi.rowEdit.setRowsDirty(myDataRows);
    @@ -241,14 +247,14 @@
               return function() {
                 gridRow.isSaving = true;
     
    -            if ( gridRow.rowEditSavePromise ){
    +            if ( gridRow.rowEditSavePromise ) {
                   // don't save the row again if it's already saving - that causes stale object exceptions
                   return gridRow.rowEditSavePromise;
                 }
     
                 var promise = grid.api.rowEdit.raise.saveRow( gridRow.entity );
     
    -            if ( gridRow.rowEditSavePromise ){
    +            if ( gridRow.rowEditSavePromise ) {
                   gridRow.rowEditSavePromise.then( self.processSuccessPromise( grid, gridRow ), self.processErrorPromise( grid, gridRow ));
                 } else {
                   gridUtil.logError( 'A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise' );
    @@ -323,10 +329,10 @@
     
                 gridRow.isError = true;
     
    -            if (!grid.rowEdit.errorRows){
    +            if (!grid.rowEdit.errorRows) {
                   grid.rowEdit.errorRows = [];
                 }
    -            if (!service.isRowPresent( grid.rowEdit.errorRows, gridRow ) ){
    +            if (!service.isRowPresent( grid.rowEdit.errorRows, gridRow ) ) {
                   grid.rowEdit.errorRows.push( gridRow );
                 }
               };
    @@ -343,13 +349,13 @@
              * @param {array} rowArray the array from which to remove the row
              * @param {GridRow} gridRow the row that should be removed
              */
    -        removeRow: function( rowArray, removeGridRow ){
    -          if (typeof(rowArray) === 'undefined' || rowArray === null){
    +        removeRow: function( rowArray, removeGridRow ) {
    +          if (typeof(rowArray) === 'undefined' || rowArray === null) {
                 return;
               }
     
    -          rowArray.forEach( function( gridRow, index ){
    -            if ( gridRow.uid === removeGridRow.uid ){
    +          rowArray.forEach( function( gridRow, index ) {
    +            if ( gridRow.uid === removeGridRow.uid ) {
                   rowArray.splice( index, 1);
                 }
               });
    @@ -365,10 +371,10 @@
              * @param {array} rowArray the array in which to look for the row
              * @param {GridRow} gridRow the row that should be looked for
              */
    -        isRowPresent: function( rowArray, removeGridRow ){
    +        isRowPresent: function( rowArray, removeGridRow ) {
               var present = false;
    -          rowArray.forEach( function( gridRow, index ){
    -            if ( gridRow.uid === removeGridRow.uid ){
    +          rowArray.forEach( function( gridRow, index ) {
    +            if ( gridRow.uid === removeGridRow.uid ) {
                   present = true;
                 }
               });
    @@ -391,9 +397,9 @@
              * the individual save promises have been resolved.
              *
              */
    -        flushDirtyRows: function(grid){
    +        flushDirtyRows: function(grid) {
               var promises = [];
    -          grid.api.rowEdit.getDirtyRows().forEach( function( gridRow ){
    +          grid.api.rowEdit.getDirtyRows().forEach( function( gridRow ) {
                 service.cancelTimer( grid, gridRow );
                 service.saveRow( grid, gridRow )();
                 promises.push( gridRow.rowEditSavePromise );
    @@ -414,17 +420,17 @@
              * @param {object} rowEntity the data entity for which the cell
              * was edited
              */
    -        endEditCell: function( rowEntity, colDef, newValue, previousValue ){
    +        endEditCell: function( rowEntity, colDef, newValue, previousValue ) {
               var grid = this.grid;
               var gridRow = grid.getRow( rowEntity );
    -          if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, dirty flag cannot be set' ); return; }
    +          if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, dirty flag cannot be set' ); return; }
     
    -          if ( newValue !== previousValue || gridRow.isDirty ){
    -            if ( !grid.rowEdit.dirtyRows ){
    +          if ( newValue !== previousValue || gridRow.isDirty ) {
    +            if ( !grid.rowEdit.dirtyRows ) {
                   grid.rowEdit.dirtyRows = [];
                 }
     
    -            if ( !gridRow.isDirty ){
    +            if ( !gridRow.isDirty ) {
                   gridRow.isDirty = true;
                   grid.rowEdit.dirtyRows.push( gridRow );
                 }
    @@ -448,10 +454,10 @@
              * @param {object} rowEntity the data entity for which the cell
              * editing has commenced
              */
    -        beginEditCell: function( rowEntity, colDef ){
    +        beginEditCell: function( rowEntity, colDef ) {
               var grid = this.grid;
               var gridRow = grid.getRow( rowEntity );
    -          if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be cancelled' ); return; }
    +          if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be cancelled' ); return; }
     
               service.cancelTimer( grid, gridRow );
             },
    @@ -472,10 +478,10 @@
              * @param {object} rowEntity the data entity for which the cell
              * editing was cancelled
              */
    -        cancelEditCell: function( rowEntity, colDef ){
    +        cancelEditCell: function( rowEntity, colDef ) {
               var grid = this.grid;
               var gridRow = grid.getRow( rowEntity );
    -          if ( !gridRow ){ gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be set' ); return; }
    +          if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be set' ); return; }
     
               service.considerSetTimer( grid, gridRow );
             },
    @@ -493,13 +499,13 @@
              * @param {object} oldRowCol the row and column that was left
              *
              */
    -        navigate: function( newRowCol, oldRowCol ){
    +        navigate: function( newRowCol, oldRowCol ) {
               var grid = this.grid;
    -          if ( newRowCol.row.rowEditSaveTimer ){
    +          if ( newRowCol.row.rowEditSaveTimer ) {
                 service.cancelTimer( grid, newRowCol.row );
               }
     
    -          if ( oldRowCol && oldRowCol.row && oldRowCol.row !== newRowCol.row ){
    +          if ( oldRowCol && oldRowCol.row && oldRowCol.row !== newRowCol.row ) {
                 service.considerSetTimer( grid, oldRowCol.row );
               }
             },
    @@ -532,11 +538,11 @@
              * @param {GridRow} gridRow the row for which the timer should be adjusted
              *
              */
    -        considerSetTimer: function( grid, gridRow ){
    +        considerSetTimer: function( grid, gridRow ) {
               service.cancelTimer( grid, gridRow );
     
    -          if ( gridRow.isDirty && !gridRow.isSaving ){
    -            if ( grid.options.rowEditWaitInterval !== -1 ){
    +          if ( gridRow.isDirty && !gridRow.isSaving ) {
    +            if ( grid.options.rowEditWaitInterval !== -1 ) {
                   var waitTime = grid.options.rowEditWaitInterval ? grid.options.rowEditWaitInterval : 2000;
                   gridRow.rowEditSaveTimer = $interval( service.saveRow( grid, gridRow ), waitTime, 1);
                 }
    @@ -554,8 +560,8 @@
              * @param {GridRow} gridRow the row for which the timer should be adjusted
              *
              */
    -        cancelTimer: function( grid, gridRow ){
    -          if ( gridRow.rowEditSaveTimer && !gridRow.isSaving ){
    +        cancelTimer: function( grid, gridRow ) {
    +          if ( gridRow.rowEditSaveTimer && !gridRow.isSaving ) {
                 $interval.cancel(gridRow.rowEditSaveTimer);
                 delete gridRow.rowEditSaveTimer;
               }
    @@ -583,14 +589,14 @@
              */
             setRowsDirty: function( grid, myDataRows ) {
               var gridRow;
    -          myDataRows.forEach( function( value, index ){
    +          myDataRows.forEach( function( value, index ) {
                 gridRow = grid.getRow( value );
    -            if ( gridRow ){
    -              if ( !grid.rowEdit.dirtyRows ){
    +            if ( gridRow ) {
    +              if ( !grid.rowEdit.dirtyRows ) {
                     grid.rowEdit.dirtyRows = [];
                   }
     
    -              if ( !gridRow.isDirty ){
    +              if ( !gridRow.isDirty ) {
                     gridRow.isDirty = true;
                     grid.rowEdit.dirtyRows.push( gridRow );
                   }
    @@ -620,9 +626,9 @@
             setRowsClean: function( grid, myDataRows ) {
               var gridRow;
     
    -          myDataRows.forEach( function( value, index ){
    +          myDataRows.forEach( function( value, index ) {
                 gridRow = grid.getRow( value );
    -            if ( gridRow ){
    +            if ( gridRow ) {
                   delete gridRow.isDirty;
                   service.removeRow( grid.rowEdit.dirtyRows, gridRow );
                   service.cancelTimer( grid, gridRow );
    diff --git a/src/i18n/ui-grid.row-edit.min.js b/src/i18n/ui-grid.row-edit.min.js
    new file mode 100644
    index 0000000000..3554bb43b8
    --- /dev/null
    +++ b/src/i18n/ui-grid.row-edit.min.js
    @@ -0,0 +1,7 @@
    +/*!
    + * ui-grid - v4.11.0 - 2021-08-12
    + * Copyright (c) 2021 ; License: MIT 
    + */
    +
    +
    +!function(){"use strict";var r=angular.module("ui.grid.rowEdit",["ui.grid","ui.grid.edit","ui.grid.cellNav"]);r.constant("uiGridRowEditConstants",{}),r.service("uiGridRowEditService",["$interval","$q","uiGridConstants","uiGridRowEditConstants","gridUtil",function(t,r,i,e,s){var d={initializeGrid:function(i,e){e.rowEdit={};var r={events:{rowEdit:{saveRow:function(r){}}},methods:{rowEdit:{setSavePromise:function(r,i){d.setSavePromise(e,r,i)},getDirtyRows:function(){return e.rowEdit.dirtyRows?e.rowEdit.dirtyRows:[]},getErrorRows:function(){return e.rowEdit.errorRows?e.rowEdit.errorRows:[]},flushDirtyRows:function(){return d.flushDirtyRows(e)},setRowsDirty:function(r){d.setRowsDirty(e,r)},setRowsClean:function(r){d.setRowsClean(e,r)}}}};e.api.registerEventsFromObject(r.events),e.api.registerMethodsFromObject(r.methods),e.api.core.on.renderingComplete(i,function(r){e.api.edit.on.afterCellEdit(i,d.endEditCell),e.api.edit.on.beginCellEdit(i,d.beginEditCell),e.api.edit.on.cancelCellEdit(i,d.cancelEditCell),e.api.cellNav&&e.api.cellNav.on.navigate(i,d.navigate)})},defaultGridOptions:function(r){},saveRow:function(i,e){var t=this;return function(){if(e.isSaving=!0,e.rowEditSavePromise)return e.rowEditSavePromise;var r=i.api.rowEdit.raise.saveRow(e.entity);return e.rowEditSavePromise?e.rowEditSavePromise.then(t.processSuccessPromise(i,e),t.processErrorPromise(i,e)):s.logError("A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise"),r}},setSavePromise:function(r,i,e){r.getRow(i).rowEditSavePromise=e},processSuccessPromise:function(r,i){var e=this;return function(){delete i.isSaving,delete i.isDirty,delete i.isError,delete i.rowEditSaveTimer,delete i.rowEditSavePromise,e.removeRow(r.rowEdit.errorRows,i),e.removeRow(r.rowEdit.dirtyRows,i)}},processErrorPromise:function(r,i){return function(){delete i.isSaving,delete i.rowEditSaveTimer,delete i.rowEditSavePromise,i.isError=!0,r.rowEdit.errorRows||(r.rowEdit.errorRows=[]),d.isRowPresent(r.rowEdit.errorRows,i)||r.rowEdit.errorRows.push(i)}},removeRow:function(e,t){null!=e&&e.forEach(function(r,i){r.uid===t.uid&&e.splice(i,1)})},isRowPresent:function(r,e){var t=!1;return r.forEach(function(r,i){r.uid===e.uid&&(t=!0)}),t},flushDirtyRows:function(i){var e=[];return i.api.rowEdit.getDirtyRows().forEach(function(r){d.cancelTimer(i,r),d.saveRow(i,r)(),e.push(r.rowEditSavePromise)}),r.all(e)},endEditCell:function(r,i,e,t){var o=this.grid,n=o.getRow(r);n?(e!==t||n.isDirty)&&(o.rowEdit.dirtyRows||(o.rowEdit.dirtyRows=[]),n.isDirty||(n.isDirty=!0,o.rowEdit.dirtyRows.push(n)),delete n.isError,d.considerSetTimer(o,n)):s.logError("Unable to find rowEntity in grid data, dirty flag cannot be set")},beginEditCell:function(r,i){var e=this.grid,t=e.getRow(r);t?d.cancelTimer(e,t):s.logError("Unable to find rowEntity in grid data, timer cannot be cancelled")},cancelEditCell:function(r,i){var e=this.grid,t=e.getRow(r);t?d.considerSetTimer(e,t):s.logError("Unable to find rowEntity in grid data, timer cannot be set")},navigate:function(r,i){var e=this.grid;r.row.rowEditSaveTimer&&d.cancelTimer(e,r.row),i&&i.row&&i.row!==r.row&&d.considerSetTimer(e,i.row)},considerSetTimer:function(r,i){if(d.cancelTimer(r,i),i.isDirty&&!i.isSaving&&-1!==r.options.rowEditWaitInterval){var e=r.options.rowEditWaitInterval?r.options.rowEditWaitInterval:2e3;i.rowEditSaveTimer=t(d.saveRow(r,i),e,1)}},cancelTimer:function(r,i){i.rowEditSaveTimer&&!i.isSaving&&(t.cancel(i.rowEditSaveTimer),delete i.rowEditSaveTimer)},setRowsDirty:function(e,r){var t;r.forEach(function(r,i){(t=e.getRow(r))?(e.rowEdit.dirtyRows||(e.rowEdit.dirtyRows=[]),t.isDirty||(t.isDirty=!0,e.rowEdit.dirtyRows.push(t)),delete t.isError,d.considerSetTimer(e,t)):s.logError("requested row not found in rowEdit.setRowsDirty, row was: "+r)})},setRowsClean:function(e,r){var t;r.forEach(function(r,i){(t=e.getRow(r))?(delete t.isDirty,d.removeRow(e.rowEdit.dirtyRows,t),d.cancelTimer(e,t),delete t.isError,d.removeRow(e.rowEdit.errorRows,t)):s.logError("requested row not found in rowEdit.setRowsClean, row was: "+r)})}};return d}]),r.directive("uiGridRowEdit",["gridUtil","uiGridRowEditService","uiGridEditConstants",function(r,o,i){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(r,i,e,t){o.initializeGrid(r,t.grid)},post:function(r,i,e,t){}}}}}]),r.directive("uiGridViewport",["$compile","uiGridConstants","gridUtil","$parse",function(r,i,e,t){return{priority:-200,scope:!1,compile:function(r,i){var e=angular.element(r.children().children()[0]),t=e.attr("ng-class"),o="";return o=t?t.slice(0,-1)+", 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}":"{'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}",e.attr("ng-class",o),{pre:function(r,i,e,t){},post:function(r,i,e,t){}}}}}])}();
    \ No newline at end of file
    diff --git a/src/features/saveState/js/saveState.js b/src/i18n/ui-grid.saveState.js
    similarity index 91%
    rename from src/features/saveState/js/saveState.js
    rename to src/i18n/ui-grid.saveState.js
    index e4693030b5..59b27d8382 100644
    --- a/src/features/saveState/js/saveState.js
    +++ b/src/i18n/ui-grid.saveState.js
    @@ -1,3 +1,8 @@
    +/*!
    + * ui-grid - v4.11.0 - 2021-08-12
    + * Copyright (c) 2021 ; License: MIT 
    + */
    +
     (function () {
       'use strict';
     
    @@ -42,14 +47,13 @@
        *
        *  @description Services for saveState feature
        */
    -  module.service('uiGridSaveStateService', ['$q', 'uiGridSaveStateConstants', 'gridUtil', '$compile', '$interval', 'uiGridConstants',
    -    function ($q, uiGridSaveStateConstants, gridUtil, $compile, $interval, uiGridConstants ) {
    -
    +  module.service('uiGridSaveStateService',
    +    function () {
           var service = {
     
             initializeGrid: function (grid) {
     
    -          //add feature namespace and any properties to grid for needed state
    +          // add feature namespace and any properties to grid for needed state
               grid.saveState = {};
               this.defaultGridOptions(grid.options);
     
    @@ -96,11 +100,10 @@
               grid.api.registerEventsFromObject(publicApi.events);
     
               grid.api.registerMethodsFromObject(publicApi.methods);
    -
             },
     
             defaultGridOptions: function (gridOptions) {
    -          //default option to true unless it was explicitly set to false
    +          // default option to true unless it was explicitly set to false
               /**
                * @ngdoc object
                * @name ui.grid.saveState.api:GridOptions
    @@ -269,8 +272,6 @@
               gridOptions.saveTreeView = gridOptions.saveTreeView !== false;
             },
     
    -
    -
             /**
              * @ngdoc function
              * @name save
    @@ -305,28 +306,28 @@
              * @param {object} state the state we'd like to restore
              * @returns {object} the promise created by refresh
              */
    -        restore: function( grid, $scope, state ){
    +        restore: function( grid, $scope, state ) {
               if ( state.columns ) {
                 service.restoreColumns( grid, state.columns );
               }
     
    -          if ( state.scrollFocus ){
    +          if ( state.scrollFocus ) {
                 service.restoreScrollFocus( grid, $scope, state.scrollFocus );
               }
     
    -          if ( state.selection ){
    +          if ( state.selection ) {
                 service.restoreSelection( grid, state.selection );
               }
     
    -          if ( state.grouping ){
    +          if ( state.grouping ) {
                 service.restoreGrouping( grid, state.grouping );
               }
     
    -          if ( state.treeView ){
    +          if ( state.treeView ) {
                 service.restoreTreeView( grid, state.treeView );
               }
     
    -          if ( state.pagination ){
    +          if ( state.pagination ) {
                 service.restorePagination( grid, state.pagination );
               }
     
    @@ -349,29 +350,30 @@
              */
             saveColumns: function( grid ) {
               var columns = [];
    +
               grid.getOnlyDataColumns().forEach( function( column ) {
                 var savedColumn = {};
                 savedColumn.name = column.name;
     
    -            if ( grid.options.saveVisible ){
    +            if ( grid.options.saveVisible ) {
                   savedColumn.visible = column.visible;
                 }
     
    -            if ( grid.options.saveWidths ){
    +            if ( grid.options.saveWidths ) {
                   savedColumn.width = column.width;
                 }
     
                 // these two must be copied, not just pointed too - otherwise our saved state is pointing to the same object as current state
    -            if ( grid.options.saveSort ){
    +            if ( grid.options.saveSort ) {
                   savedColumn.sort = angular.copy( column.sort );
                 }
     
    -            if ( grid.options.saveFilter ){
    +            if ( grid.options.saveFilter ) {
                   savedColumn.filters = [];
    -              column.filters.forEach( function( filter ){
    +              column.filters.forEach( function( filter ) {
                     var copiedFilter = {};
                     angular.forEach( filter, function( value, key) {
    -                  if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder'){
    +                  if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder') {
                         copiedFilter[key] = value;
                       }
                     });
    @@ -379,7 +381,7 @@
                   });
                 }
     
    -            if ( !!grid.api.pinning && grid.options.savePinning ){
    +            if ( !!grid.api.pinning && grid.options.savePinning ) {
                   savedColumn.pinned = column.renderContainer ? column.renderContainer : '';
                 }
     
    @@ -409,20 +411,20 @@
              * @param {Grid} grid the grid whose state we'd like to save
              * @returns {object} the selection state ready to be saved
              */
    -        saveScrollFocus: function( grid ){
    -          if ( !grid.api.cellNav ){
    +        saveScrollFocus: function( grid ) {
    +          if ( !grid.api.cellNav ) {
                 return {};
               }
     
               var scrollFocus = {};
    -          if ( grid.options.saveFocus ){
    +          if ( grid.options.saveFocus ) {
                 scrollFocus.focus = true;
                 var rowCol = grid.api.cellNav.getFocusedCell();
                 if ( rowCol !== null ) {
    -              if ( rowCol.col !== null ){
    +              if ( rowCol.col !== null ) {
                     scrollFocus.colName = rowCol.col.colDef.name;
                   }
    -              if ( rowCol.row !== null ){
    +              if ( rowCol.row !== null ) {
                     scrollFocus.rowVal = service.getRowVal( grid, rowCol.row );
                   }
                 }
    @@ -430,11 +432,11 @@
     
               if ( grid.options.saveScroll || grid.options.saveFocus && !scrollFocus.colName && !scrollFocus.rowVal ) {
                 scrollFocus.focus = false;
    -            if ( grid.renderContainers.body.prevRowScrollIndex ){
    +            if ( grid.renderContainers.body.prevRowScrollIndex ) {
                   scrollFocus.rowVal = service.getRowVal( grid, grid.renderContainers.body.visibleRowCache[ grid.renderContainers.body.prevRowScrollIndex ]);
                 }
     
    -            if ( grid.renderContainers.body.prevColScrollIndex ){
    +            if ( grid.renderContainers.body.prevColScrollIndex ) {
                   scrollFocus.colName = grid.renderContainers.body.visibleColumnCache[ grid.renderContainers.body.prevColScrollIndex ].name;
                 }
               }
    @@ -451,16 +453,14 @@
              * @param {Grid} grid the grid whose state we'd like to save
              * @returns {array} the selection state ready to be saved
              */
    -        saveSelection: function( grid ){
    -          if ( !grid.api.selection || !grid.options.saveSelection ){
    +        saveSelection: function( grid ) {
    +          if ( !grid.api.selection || !grid.options.saveSelection ) {
                 return [];
               }
     
    -          var selection = grid.api.selection.getSelectedGridRows().map( function( gridRow ) {
    +          return grid.api.selection.getSelectedGridRows().map( function( gridRow ) {
                 return service.getRowVal( grid, gridRow );
               });
    -
    -          return selection;
             },
     
     
    @@ -472,8 +472,8 @@
              * @param {Grid} grid the grid whose state we'd like to save
              * @returns {object} the grouping state ready to be saved
              */
    -        saveGrouping: function( grid ){
    -          if ( !grid.api.grouping || !grid.options.saveGrouping ){
    +        saveGrouping: function( grid ) {
    +          if ( !grid.api.grouping || !grid.options.saveGrouping ) {
                 return {};
               }
     
    @@ -490,7 +490,7 @@
              * @returns {object} the pagination state ready to be saved
              */
             savePagination: function( grid ) {
    -          if ( !grid.api.pagination || !grid.options.paginationPageSize ){
    +          if ( !grid.api.pagination || !grid.options.paginationPageSize ) {
                 return {};
               }
     
    @@ -509,8 +509,8 @@
              * @param {Grid} grid the grid whose state we'd like to save
              * @returns {object} the tree view state ready to be saved
              */
    -        saveTreeView: function( grid ){
    -          if ( !grid.api.treeView || !grid.options.saveTreeView ){
    +        saveTreeView: function( grid ) {
    +          if ( !grid.api.treeView || !grid.options.saveTreeView ) {
                 return {};
               }
     
    @@ -529,16 +529,17 @@
              * @returns {object} an object containing { identity: true/false, row: rowNumber/rowIdentity }
              *
              */
    -        getRowVal: function( grid, gridRow ){
    +        getRowVal: function( grid, gridRow ) {
               if ( !gridRow ) {
                 return null;
               }
     
               var rowVal = {};
    -          if ( grid.options.saveRowIdentity ){
    +          if ( grid.options.saveRowIdentity ) {
                 rowVal.identity = true;
                 rowVal.row = grid.options.saveRowIdentity( gridRow.entity );
    -          } else {
    +          }
    +          else {
                 rowVal.identity = false;
                 rowVal.row = grid.renderContainers.body.visibleRowCache.indexOf( gridRow );
               }
    @@ -556,45 +557,45 @@
              * @param {Grid} grid the grid whose state we'd like to restore
              * @param {object} columnsState the list of columns we had before, with their state
              */
    -        restoreColumns: function( grid, columnsState ){
    +        restoreColumns: function( grid, columnsState ) {
               var isSortChanged = false;
     
               columnsState.forEach( function( columnState, index ) {
                 var currentCol = grid.getColumn( columnState.name );
     
    -            if ( currentCol && !grid.isRowHeaderColumn(currentCol) ){
    +            if ( currentCol && !grid.isRowHeaderColumn(currentCol) ) {
                   if ( grid.options.saveVisible &&
                        ( currentCol.visible !== columnState.visible ||
    -                     currentCol.colDef.visible !== columnState.visible ) ){
    +                     currentCol.colDef.visible !== columnState.visible ) ) {
                     currentCol.visible = columnState.visible;
                     currentCol.colDef.visible = columnState.visible;
                     grid.api.core.raise.columnVisibilityChanged(currentCol);
                   }
     
    -              if ( grid.options.saveWidths && currentCol.width !== columnState.width){
    +              if ( grid.options.saveWidths && currentCol.width !== columnState.width) {
                     currentCol.width = columnState.width;
                     currentCol.hasCustomWidth = true;
                   }
     
                   if ( grid.options.saveSort &&
                        !angular.equals(currentCol.sort, columnState.sort) &&
    -                   !( currentCol.sort === undefined && angular.isEmpty(columnState.sort) ) ){
    +                   !( currentCol.sort === undefined && angular.isEmpty(columnState.sort) ) ) {
                     currentCol.sort = angular.copy( columnState.sort );
                     isSortChanged = true;
                   }
     
                   if ( grid.options.saveFilter &&
    -                   !angular.equals(currentCol.filters, columnState.filters ) ){
    -                columnState.filters.forEach( function( filter, index ){
    +                   !angular.equals(currentCol.filters, columnState.filters ) ) {
    +                columnState.filters.forEach( function( filter, index ) {
                       angular.extend( currentCol.filters[index], filter );
    -                  if ( typeof(filter.term) === 'undefined' || filter.term === null ){
    +                  if ( typeof(filter.term) === 'undefined' || filter.term === null ) {
                         delete currentCol.filters[index].term;
                       }
                     });
    -                grid.api.core.raise.filterChanged();
    +                grid.api.core.raise.filterChanged( currentCol );
                   }
     
    -              if ( !!grid.api.pinning && grid.options.savePinning && currentCol.renderContainer !== columnState.pinned ){
    +              if ( !!grid.api.pinning && grid.options.savePinning && currentCol.renderContainer !== columnState.pinned ) {
                     grid.api.pinning.pinColumn(currentCol, columnState.pinned);
                   }
     
    @@ -626,23 +627,24 @@
              * @param {scope} $scope a scope that we can broadcast on
              * @param {object} scrollFocusState the scroll/focus state ready to be restored
              */
    -        restoreScrollFocus: function( grid, $scope, scrollFocusState ){
    -          if ( !grid.api.cellNav ){
    +        restoreScrollFocus: function( grid, $scope, scrollFocusState ) {
    +          if ( !grid.api.cellNav ) {
                 return;
               }
     
               var colDef, row;
    -          if ( scrollFocusState.colName ){
    +          if ( scrollFocusState.colName ) {
                 var colDefs = grid.options.columnDefs.filter( function( colDef ) { return colDef.name === scrollFocusState.colName; });
    -            if ( colDefs.length > 0 ){
    +            if ( colDefs.length > 0 ) {
                   colDef = colDefs[0];
                 }
               }
     
    -          if ( scrollFocusState.rowVal && scrollFocusState.rowVal.row ){
    -            if ( scrollFocusState.rowVal.identity ){
    +          if ( scrollFocusState.rowVal && scrollFocusState.rowVal.row ) {
    +            if ( scrollFocusState.rowVal.identity ) {
                   row = service.findRowByIdentity( grid, scrollFocusState.rowVal );
    -            } else {
    +            }
    +            else {
                   row = grid.renderContainers.body.visibleRowCache[ scrollFocusState.rowVal.row ];
                 }
               }
    @@ -650,9 +652,10 @@
               var entity = row && row.entity ? row.entity : null ;
     
               if ( colDef || entity ) {
    -            if (scrollFocusState.focus ){
    +            if (scrollFocusState.focus ) {
                   grid.api.cellNav.scrollToFocus( entity, colDef );
    -            } else {
    +            }
    +            else {
                   grid.scrollTo( entity, colDef );
                 }
               }
    @@ -669,22 +672,23 @@
              * @param {Grid} grid the grid whose state we'd like to restore
              * @param {object} selectionState the selection state ready to be restored
              */
    -        restoreSelection: function( grid, selectionState ){
    -          if ( !grid.api.selection ){
    +        restoreSelection: function( grid, selectionState ) {
    +          if ( !grid.api.selection ) {
                 return;
               }
     
               grid.api.selection.clearSelectedRows();
     
    -          selectionState.forEach(  function( rowVal ) {
    -            if ( rowVal.identity ){
    +          selectionState.forEach(function( rowVal ) {
    +            if ( rowVal.identity ) {
                   var foundRow = service.findRowByIdentity( grid, rowVal );
     
    -              if ( foundRow ){
    +              if ( foundRow ) {
                     grid.api.selection.selectRow( foundRow.entity );
                   }
     
    -            } else {
    +            }
    +            else {
                   grid.api.selection.selectRowByVisibleIndex( rowVal.row );
                 }
               });
    @@ -700,8 +704,8 @@
              * @param {Grid} grid the grid whose state we'd like to restore
              * @param {object} groupingState the grouping state ready to be restored
              */
    -        restoreGrouping: function( grid, groupingState ){
    -          if ( !grid.api.grouping || typeof(groupingState) === 'undefined' || groupingState === null || angular.equals(groupingState, {}) ){
    +        restoreGrouping: function( grid, groupingState ) {
    +          if ( !grid.api.grouping || typeof(groupingState) === 'undefined' || groupingState === null || angular.equals(groupingState, {}) ) {
                 return;
               }
     
    @@ -717,8 +721,8 @@
              * @param {Grid} grid the grid whose state we'd like to restore
              * @param {object} treeViewState the tree view state ready to be restored
              */
    -        restoreTreeView: function( grid, treeViewState ){
    -          if ( !grid.api.treeView || typeof(treeViewState) === 'undefined' || treeViewState === null || angular.equals(treeViewState, {}) ){
    +        restoreTreeView: function( grid, treeViewState ) {
    +          if ( !grid.api.treeView || typeof(treeViewState) === 'undefined' || treeViewState === null || angular.equals(treeViewState, {}) ) {
                 return;
               }
     
    @@ -735,8 +739,8 @@
              * @param {number} pagination.paginationCurrentPage the page number to restore
              * @param {number} pagination.paginationPageSize the number of items displayed per page
              */
    -        restorePagination: function( grid, pagination ){
    -          if ( !grid.api.pagination || !grid.options.paginationPageSize ){
    +        restorePagination: function( grid, pagination ) {
    +          if ( !grid.api.pagination || !grid.options.paginationPageSize ) {
                 return;
               }
     
    @@ -754,20 +758,16 @@
              * @param {object} rowVal the row we'd like to find
              * @returns {gridRow} the found row, or null if none found
              */
    -        findRowByIdentity: function( grid, rowVal ){
    -          if ( !grid.options.saveRowIdentity ){
    +        findRowByIdentity: function( grid, rowVal ) {
    +          if ( !grid.options.saveRowIdentity ) {
                 return null;
               }
     
               var filteredRows = grid.rows.filter( function( gridRow ) {
    -            if ( grid.options.saveRowIdentity( gridRow.entity ) === rowVal.row ){
    -              return true;
    -            } else {
    -              return false;
    -            }
    +            return ( grid.options.saveRowIdentity( gridRow.entity ) === rowVal.row );
               });
     
    -          if ( filteredRows.length > 0 ){
    +          if ( filteredRows.length > 0 ) {
                 return filteredRows[0];
               } else {
                 return null;
    @@ -776,9 +776,8 @@
           };
     
           return service;
    -
         }
    -  ]);
    +  );
     
       /**
        *  @ngdoc directive
    diff --git a/src/i18n/ui-grid.saveState.min.js b/src/i18n/ui-grid.saveState.min.js
    new file mode 100644
    index 0000000000..bf576b442a
    --- /dev/null
    +++ b/src/i18n/ui-grid.saveState.min.js
    @@ -0,0 +1,7 @@
    +/*!
    + * ui-grid - v4.11.0 - 2021-08-12
    + * Copyright (c) 2021 ; License: MIT 
    + */
    +
    +
    +!function(){"use strict";var e=angular.module("ui.grid.saveState",["ui.grid","ui.grid.selection","ui.grid.cellNav","ui.grid.grouping","ui.grid.pinning","ui.grid.treeView"]);e.constant("uiGridSaveStateConstants",{featureName:"saveState"}),e.service("uiGridSaveStateService",function(){var s={initializeGrid:function(n){n.saveState={},this.defaultGridOptions(n.options);var e={events:{saveState:{}},methods:{saveState:{save:function(){return s.save(n)},restore:function(e,i){return s.restore(n,e,i)}}}};n.api.registerEventsFromObject(e.events),n.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.saveWidths=!1!==e.saveWidths,e.saveOrder=!1!==e.saveOrder,e.saveScroll=!0===e.saveScroll,e.saveFocus=!0!==e.saveScroll&&!1!==e.saveFocus,e.saveVisible=!1!==e.saveVisible,e.saveSort=!1!==e.saveSort,e.saveFilter=!1!==e.saveFilter,e.saveSelection=!1!==e.saveSelection,e.saveGrouping=!1!==e.saveGrouping,e.saveGroupingExpandedStates=!0===e.saveGroupingExpandedStates,e.savePinning=!1!==e.savePinning,e.saveTreeView=!1!==e.saveTreeView},save:function(e){var i={};return i.columns=s.saveColumns(e),i.scrollFocus=s.saveScrollFocus(e),i.selection=s.saveSelection(e),i.grouping=s.saveGrouping(e),i.treeView=s.saveTreeView(e),i.pagination=s.savePagination(e),i},restore:function(e,i,n){return n.columns&&s.restoreColumns(e,n.columns),n.scrollFocus&&s.restoreScrollFocus(e,i,n.scrollFocus),n.selection&&s.restoreSelection(e,n.selection),n.grouping&&s.restoreGrouping(e,n.grouping),n.treeView&&s.restoreTreeView(e,n.treeView),n.pagination&&s.restorePagination(e,n.pagination),e.refresh()},saveColumns:function(n){var o=[];return n.getOnlyDataColumns().forEach(function(e){var i={};i.name=e.name,n.options.saveVisible&&(i.visible=e.visible),n.options.saveWidths&&(i.width=e.width),n.options.saveSort&&(i.sort=angular.copy(e.sort)),n.options.saveFilter&&(i.filters=[],e.filters.forEach(function(e){var n={};angular.forEach(e,function(e,i){"condition"!==i&&"$$hashKey"!==i&&"placeholder"!==i&&(n[i]=e)}),i.filters.push(n)})),n.api.pinning&&n.options.savePinning&&(i.pinned=e.renderContainer?e.renderContainer:""),o.push(i)}),o},saveScrollFocus:function(e){if(!e.api.cellNav)return{};var i={};if(e.options.saveFocus){i.focus=!0;var n=e.api.cellNav.getFocusedCell();null!==n&&(null!==n.col&&(i.colName=n.col.colDef.name),null!==n.row&&(i.rowVal=s.getRowVal(e,n.row)))}return(e.options.saveScroll||e.options.saveFocus&&!i.colName&&!i.rowVal)&&(i.focus=!1,e.renderContainers.body.prevRowScrollIndex&&(i.rowVal=s.getRowVal(e,e.renderContainers.body.visibleRowCache[e.renderContainers.body.prevRowScrollIndex])),e.renderContainers.body.prevColScrollIndex&&(i.colName=e.renderContainers.body.visibleColumnCache[e.renderContainers.body.prevColScrollIndex].name)),i},saveSelection:function(i){return i.api.selection&&i.options.saveSelection?i.api.selection.getSelectedGridRows().map(function(e){return s.getRowVal(i,e)}):[]},saveGrouping:function(e){return e.api.grouping&&e.options.saveGrouping?e.api.grouping.getGrouping(e.options.saveGroupingExpandedStates):{}},savePagination:function(e){return e.api.pagination&&e.options.paginationPageSize?{paginationCurrentPage:e.options.paginationCurrentPage,paginationPageSize:e.options.paginationPageSize}:{}},saveTreeView:function(e){return e.api.treeView&&e.options.saveTreeView?e.api.treeView.getTreeView():{}},getRowVal:function(e,i){if(!i)return null;var n={};return e.options.saveRowIdentity?(n.identity=!0,n.row=e.options.saveRowIdentity(i.entity)):(n.identity=!1,n.row=e.renderContainers.body.visibleRowCache.indexOf(i)),n},restoreColumns:function(r,e){var a=!1;e.forEach(function(e,i){var n=r.getColumn(e.name);if(n&&!r.isRowHeaderColumn(n)){!r.options.saveVisible||n.visible===e.visible&&n.colDef.visible===e.visible||(n.visible=e.visible,n.colDef.visible=e.visible,r.api.core.raise.columnVisibilityChanged(n)),r.options.saveWidths&&n.width!==e.width&&(n.width=e.width,n.hasCustomWidth=!0),!r.options.saveSort||angular.equals(n.sort,e.sort)||void 0===n.sort&&angular.isEmpty(e.sort)||(n.sort=angular.copy(e.sort),a=!0),r.options.saveFilter&&!angular.equals(n.filters,e.filters)&&(e.filters.forEach(function(e,i){angular.extend(n.filters[i],e),void 0!==e.term&&null!==e.term||delete n.filters[i].term}),r.api.core.raise.filterChanged(n)),r.api.pinning&&r.options.savePinning&&n.renderContainer!==e.pinned&&r.api.pinning.pinColumn(n,e.pinned);var o=r.getOnlyDataColumns().indexOf(n);if(-1!==o&&r.options.saveOrder&&o!==i){var t=r.columns.splice(o+r.rowHeaderColumns.length,1)[0];r.columns.splice(i+r.rowHeaderColumns.length,0,t)}}}),a&&r.api.core.raise.sortChanged(r,r.getColumnSorting())},restoreScrollFocus:function(e,i,n){if(e.api.cellNav){var o,t;if(n.colName){var r=e.options.columnDefs.filter(function(e){return e.name===n.colName});0Defaults to false
            */
     
    +      /**
    +       *  @ngdoc object
    +       *  @name isFocused
    +       *  @propertyOf  ui.grid.selection.api:GridRow
    +       *  @description Focused state of row. Should be readonly. Make any changes to focused state using setFocused().
    +       *  
    Defaults to false + */ /** * @ngdoc function @@ -63,7 +75,7 @@ * @methodOf ui.grid.selection.api:GridRow * @description Sets the isSelected property and updates the selectedCount * Changes to isSelected state should only be made via this function - * @param {bool} selected value to set + * @param {Boolean} selected value to set */ $delegate.prototype.setSelected = function (selected) { if (selected !== this.isSelected) { @@ -72,6 +84,22 @@ } }; + /** + * @ngdoc function + * @name setFocused + * @methodOf ui.grid.selection.api:GridRow + * @description Sets the isFocused property + * Changes to isFocused state should only be made via this function + * @param {Boolean} val value to set + */ + $delegate.prototype.setFocused = function(val) { + if (val !== this.isFocused) { + this.grid.selection.focusedRow && (this.grid.selection.focusedRow.isFocused = false); + this.grid.selection.focusedRow = val ? this : null; + this.isFocused = val; + } + }; + return $delegate; }]); }]); @@ -82,23 +110,30 @@ * * @description Services for selection features */ - module.service('uiGridSelectionService', ['$q', '$templateCache', 'uiGridSelectionConstants', 'gridUtil', - function ($q, $templateCache, uiGridSelectionConstants, gridUtil) { - + module.service('uiGridSelectionService', + function () { var service = { initializeGrid: function (grid) { - //add feature namespace and any properties to grid for needed + // add feature namespace and any properties to grid for needed /** * @ngdoc object * @name ui.grid.selection.grid:selection * * @description Grid properties and functions added for selection */ - grid.selection = {}; - grid.selection.lastSelectedRow = null; - grid.selection.selectAll = false; + grid.selection = { + lastSelectedRow: null, + /** + * @ngdoc object + * @name focusedRow + * @propertyOf ui.grid.selection.grid:selection + * @description Focused row. + */ + focusedRow: null, + selectAll: false + }; /** @@ -122,13 +157,24 @@ var publicApi = { events: { selection: { + /** + * @ngdoc event + * @name rowFocusChanged + * @eventOf ui.grid.selection.api:PublicApi + * @description is raised after the row.isFocused state is changed + * @param {object} scope the scope associated with the grid + * @param {GridRow} row the row that was focused/unfocused + * @param {Event} evt object if raised from an event + */ + rowFocusChanged: function (scope, row, evt) {}, /** * @ngdoc event * @name rowSelectionChanged * @eventOf ui.grid.selection.api:PublicApi * @description is raised after the row.isSelected state is changed + * @param {object} scope the scope associated with the grid * @param {GridRow} row the row that was selected/deselected - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ rowSelectionChanged: function (scope, row, evt) { }, @@ -140,8 +186,9 @@ * in bulk, if the `enableSelectionBatchEvent` option is set to true * (which it is by default). This allows more efficient processing * of bulk events. + * @param {object} scope the scope associated with the grid * @param {array} rows the rows that were selected/deselected - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ rowSelectionChangedBatch: function (scope, rows, evt) { } @@ -155,7 +202,7 @@ * @methodOf ui.grid.selection.api:PublicApi * @description Toggles data row as selected or unselected * @param {object} rowEntity gridOptions.data[] array instance - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ toggleRowSelection: function (rowEntity, evt) { var row = grid.getRow(rowEntity); @@ -169,7 +216,7 @@ * @methodOf ui.grid.selection.api:PublicApi * @description Select the data row * @param {object} rowEntity gridOptions.data[] array instance - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ selectRow: function (rowEntity, evt) { var row = grid.getRow(rowEntity); @@ -185,8 +232,8 @@ * specify row 0 you'll get the first visible row selected). In this context * visible means of those rows that are theoretically visible (i.e. not filtered), * rather than rows currently rendered on the screen. - * @param {number} index index within the rowsVisible array - * @param {Event} event object if raised from an event + * @param {number} rowNum index within the rowsVisible array + * @param {Event} evt object if raised from an event */ selectRowByVisibleIndex: function (rowNum, evt) { var row = grid.renderContainers.body.visibleRowCache[rowNum]; @@ -200,7 +247,7 @@ * @methodOf ui.grid.selection.api:PublicApi * @description UnSelect the data row * @param {object} rowEntity gridOptions.data[] array instance - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ unSelectRow: function (rowEntity, evt) { var row = grid.getRow(rowEntity); @@ -208,63 +255,74 @@ service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); } }, + /** + * @ngdoc function + * @name unSelectRowByVisibleIndex + * @methodOf ui.grid.selection.api:PublicApi + * @description Unselect the specified row by visible index (i.e. if you + * specify row 0 you'll get the first visible row unselected). In this context + * visible means of those rows that are theoretically visible (i.e. not filtered), + * rather than rows currently rendered on the screen. + * @param {number} rowNum index within the rowsVisible array + * @param {Event} evt object if raised from an event + */ + unSelectRowByVisibleIndex: function (rowNum, evt) { + var row = grid.renderContainers.body.visibleRowCache[rowNum]; + if (row !== null && typeof (row) !== 'undefined' && row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, /** * @ngdoc function * @name selectAllRows * @methodOf ui.grid.selection.api:PublicApi * @description Selects all rows. Does nothing if multiSelect = false - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ selectAllRows: function (evt) { - if (grid.options.multiSelect === false) { - return; + if (grid.options.multiSelect !== false) { + var changedRows = []; + grid.rows.forEach(function (row) { + if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { + row.setSelected(true); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + }); + grid.selection.selectAll = true; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); } - - var changedRows = []; - grid.rows.forEach(function (row) { - if (!row.isSelected && row.enableSelection !== false) { - row.setSelected(true); - service.decideRaiseSelectionEvent(grid, row, changedRows, evt); - } - }); - service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); - grid.selection.selectAll = true; }, /** * @ngdoc function * @name selectAllVisibleRows * @methodOf ui.grid.selection.api:PublicApi * @description Selects all visible rows. Does nothing if multiSelect = false - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ selectAllVisibleRows: function (evt) { - if (grid.options.multiSelect === false) { - return; - } - - var changedRows = []; - grid.rows.forEach(function (row) { - if (row.visible) { - if (!row.isSelected && row.enableSelection !== false) { - row.setSelected(true); - service.decideRaiseSelectionEvent(grid, row, changedRows, evt); - } - } else { - if (row.isSelected) { + if (grid.options.multiSelect !== false) { + var changedRows = []; + grid.rows.forEach(function(row) { + if (row.visible) { + if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { + row.setSelected(true); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + } else if (row.isSelected) { row.setSelected(false); service.decideRaiseSelectionEvent(grid, row, changedRows, evt); } - } - }); - service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); - grid.selection.selectAll = true; + }); + grid.selection.selectAll = true; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); + } }, /** * @ngdoc function * @name clearSelectedRows * @methodOf ui.grid.selection.api:PublicApi * @description Unselects all rows - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ clearSelectedRows: function (evt) { service.clearSelectedRows(grid, evt); @@ -278,6 +336,8 @@ getSelectedRows: function () { return service.getSelectedRows(grid).map(function (gridRow) { return gridRow.entity; + }).filter(function (entity) { + return entity.hasOwnProperty('$$hashKey') || !angular.isObject(entity); }); }, /** @@ -342,7 +402,7 @@ }, defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.selection.api:GridOptions @@ -399,11 +459,27 @@ * @name enableFullRowSelection * @propertyOf ui.grid.selection.api:GridOptions * @description Enable selection by clicking anywhere on the row. Defaults to - * false if `enableRowHeaderSelection` is true, otherwise defaults to false. + * false if `enableRowHeaderSelection` is true, otherwise defaults to true. */ if (typeof (gridOptions.enableFullRowSelection) === 'undefined') { gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection; } + /** + * @ngdoc object + * @name enableFocusRowOnRowHeaderClick + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable focuse row by clicking on the row header. Defaults to + * true if `enableRowHeaderSelection` is true, otherwise defaults to false. + */ + gridOptions.enableFocusRowOnRowHeaderClick = (gridOptions.enableFocusRowOnRowHeaderClick !== false) + || !gridOptions.enableRowHeaderSelection; + /** + * @ngdoc object + * @name enableSelectRowOnFocus + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable focuse row by clicking on the row anywhere. Defaults true. + */ + gridOptions.enableSelectRowOnFocus = (gridOptions.enableSelectRowOnFocus !== false); /** * @ngdoc object * @name enableSelectAll @@ -431,7 +507,6 @@ *
    Defaults to 30px */ gridOptions.selectionRowHeaderWidth = angular.isDefined(gridOptions.selectionRowHeaderWidth) ? gridOptions.selectionRowHeaderWidth : 30; - /** * @ngdoc object * @name enableFooterTotalSelected @@ -448,7 +523,6 @@ * @propertyOf ui.grid.selection.api:GridOptions * @description Makes it possible to specify a method that evaluates for each row and sets its "enableSelection" property. */ - gridOptions.isRowSelectable = angular.isDefined(gridOptions.isRowSelectable) ? gridOptions.isRowSelectable : angular.noop; }, @@ -459,31 +533,33 @@ * @description Toggles row as selected or unselected * @param {Grid} grid grid object * @param {GridRow} row row to select or deselect - * @param {Event} event object if resulting from event + * @param {Event} evt object if resulting from event * @param {bool} multiSelect if false, only one row at time can be selected * @param {bool} noUnselect if true then rows cannot be unselected */ toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) { - var selected = row.isSelected; - - if (row.enableSelection === false && !selected) { + if ( row.enableSelection === false ) { return; } - var selectedRows; - if (!multiSelect && !selected) { - service.clearSelectedRows(grid, evt); - } else if (!multiSelect && selected) { - selectedRows = service.getSelectedRows(grid); - if (selectedRows.length > 1) { - selected = false; // Enable reselect of the row + var selected = row.isSelected, + selectedRows; + + if (!multiSelect) { + if (!selected) { service.clearSelectedRows(grid, evt); } + else { + selectedRows = service.getSelectedRows(grid); + if (selectedRows.length > 1) { + selected = false; // Enable reselect of the row + service.clearSelectedRows(grid, evt); + } + } } - if (selected && noUnselect) { - // don't deselect the row - } else { + // only select row in this case + if (!(selected && noUnselect)) { row.setSelected(!selected); if (row.isSelected === true) { grid.selection.lastSelectedRow = row; @@ -501,8 +577,8 @@ * @methodOf ui.grid.selection.service:uiGridSelectionService * @description selects a group of rows from the last selected row using the shift key * @param {Grid} grid grid object - * @param {GridRow} clicked row - * @param {Event} event object if raised from an event + * @param {GridRow} row clicked row + * @param {Event} evt object if raised from an event * @param {bool} multiSelect if false, does nothing this is for multiSelect only */ shiftSelect: function (grid, row, evt, multiSelect) { @@ -512,7 +588,7 @@ var selectedRows = service.getSelectedRows(grid); var fromRow = selectedRows.length > 0 ? grid.renderContainers.body.visibleRowCache.indexOf(grid.selection.lastSelectedRow) : 0; var toRow = grid.renderContainers.body.visibleRowCache.indexOf(row); - //reverse select direction + // reverse select direction if (fromRow > toRow) { var tmp = fromRow; fromRow = toRow; @@ -551,19 +627,19 @@ * @methodOf ui.grid.selection.service:uiGridSelectionService * @description Clears all selected rows * @param {Grid} grid grid object - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event */ clearSelectedRows: function (grid, evt) { var changedRows = []; service.getSelectedRows(grid).forEach(function (row) { - if (row.isSelected) { + if (row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { row.setSelected(false); service.decideRaiseSelectionEvent(grid, row, changedRows, evt); } }); - service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); grid.selection.selectAll = false; grid.selection.selectedCount = 0; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); }, /** @@ -574,13 +650,14 @@ * @param {Grid} grid grid object * @param {GridRow} row row that has changed * @param {array} changedRows an array to which we can append the changed - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event * row if we're doing batch events */ decideRaiseSelectionEvent: function (grid, row, changedRows, evt) { if (!grid.options.enableSelectionBatchEvent) { grid.api.selection.raise.rowSelectionChanged(row, evt); - } else { + } + else { changedRows.push(row); } }, @@ -593,7 +670,7 @@ * raises it if we do. * @param {Grid} grid grid object * @param {array} changedRows an array of changed rows, only populated - * @param {Event} event object if raised from an event + * @param {Event} evt object if raised from an event * if we're doing batch events */ decideRaiseSelectionBatchEvent: function (grid, changedRows, evt) { @@ -604,8 +681,7 @@ }; return service; - - }]); + }); /** * @ngdoc directive @@ -639,8 +715,8 @@ */ - module.directive('uiGridSelection', ['uiGridSelectionConstants', 'uiGridSelectionService', '$templateCache', 'uiGridConstants', - function (uiGridSelectionConstants, uiGridSelectionService, $templateCache, uiGridConstants) { + module.directive('uiGridSelection', ['i18nService', 'uiGridSelectionConstants', 'uiGridSelectionService', 'uiGridConstants', + function (i18nService, uiGridSelectionConstants, uiGridSelectionService, uiGridConstants) { return { replace: true, priority: 0, @@ -653,7 +729,7 @@ if (uiGridCtrl.grid.options.enableRowHeaderSelection) { var selectionRowHeaderDef = { name: uiGridSelectionConstants.selectionRowHeaderColName, - displayName: '', + displayName: i18nService.getSafeText('selection.displayName'), width: uiGridCtrl.grid.options.selectionRowHeaderWidth, minWidth: 10, cellTemplate: 'ui-grid/selectionRowHeader', @@ -708,13 +784,20 @@ link: function ($scope, $elm, $attrs, uiGridCtrl) { var self = uiGridCtrl.grid; $scope.selectButtonClick = selectButtonClick; + $scope.selectButtonKeyDown = selectButtonKeyDown; // On IE, prevent mousedowns on the select button from starting a selection. - // If this is not done and you shift+click on another row, the browser will select a big chunk of text + // If this is not done and you shift+click on another row, the browser will select a big chunk of text if (gridUtil.detectBrowser() === 'ie') { $elm.on('mousedown', selectButtonMouseDown); } + function selectButtonKeyDown(row, evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + evt.preventDefault(); + selectButtonClick(row, evt); + } + } function selectButtonClick(row, evt) { evt.stopPropagation(); @@ -723,16 +806,20 @@ uiGridSelectionService.shiftSelect(self, row, evt, self.options.multiSelect); } else if (evt.ctrlKey || evt.metaKey) { - uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect); + uiGridSelectionService.toggleRowSelection(self, row, evt, + self.options.multiSelect, self.options.noUnselect); } else if (row.groupHeader) { + uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect); for (var i = 0; i < row.treeNode.children.length; i++) { uiGridSelectionService.toggleRowSelection(self, row.treeNode.children[i].row, evt, self.options.multiSelect, self.options.noUnselect); } } else { - uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect); + uiGridSelectionService.toggleRowSelection(self, row, evt, + (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect); } + self.options.enableFocusRowOnRowHeaderClick && row.setFocused(!row.isFocused) && self.api.selection.raise.rowFocusChanged(row, evt); } function selectButtonMouseDown(evt) { @@ -756,21 +843,27 @@ restrict: 'E', template: $templateCache.get('ui-grid/selectionSelectAllButtons'), scope: false, - link: function ($scope, $elm, $attrs, uiGridCtrl) { + link: function ($scope) { var self = $scope.col.grid; - $scope.headerButtonClick = function (row, evt) { + $scope.headerButtonKeyDown = function (evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + evt.preventDefault(); + $scope.headerButtonClick(evt); + } + }; + + $scope.headerButtonClick = function (evt) { if (self.selection.selectAll) { uiGridSelectionService.clearSelectedRows(self, evt); if (self.options.noUnselect) { self.api.selection.selectRowByVisibleIndex(0, evt); } self.selection.selectAll = false; - } else { - if (self.options.multiSelect) { - self.api.selection.selectAllVisibleRows(evt); - self.selection.selectAll = true; - } + } + else if (self.options.multiSelect) { + self.api.selection.selectAllVisibleRows(evt); + self.selection.selectAll = true; } }; } @@ -786,33 +879,29 @@ * for the grid row */ module.directive('uiGridViewport', - ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService', - function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService) { + function () { return { priority: -200, // run after default directive scope: false, - compile: function ($elm, $attrs) { - var rowRepeatDiv = angular.element($elm.children().children()[0]); + compile: function ($elm) { + var rowRepeatDiv = angular.element($elm[0].querySelector('.ui-grid-canvas:not(.ui-grid-empty-base-layer-container)').children[0]), + newNgClass = "'ui-grid-row-selected': row.isSelected, 'ui-grid-row-focused': row.isFocused}", + existingNgClass = rowRepeatDiv.attr('ng-class'); - var existingNgClass = rowRepeatDiv.attr("ng-class"); - var newNgClass = ''; if (existingNgClass) { - newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-row-selected': row.isSelected}"; + newNgClass = existingNgClass.slice(0, -1) + ',' + newNgClass; } else { - newNgClass = "{'ui-grid-row-selected': row.isSelected}"; + newNgClass = '{' + newNgClass; } - rowRepeatDiv.attr("ng-class", newNgClass); + rowRepeatDiv.attr('ng-class', newNgClass); return { - pre: function ($scope, $elm, $attrs, controllers) { - - }, - post: function ($scope, $elm, $attrs, controllers) { - } + pre: function ($scope, $elm, $attrs, controllers) {}, + post: function ($scope, $elm, $attrs, controllers) {} }; } }; - }]); + }); /** * @ngdoc directive @@ -823,21 +912,21 @@ * @description Stacks on top of ui.grid.uiGridCell to provide selection feature */ module.directive('uiGridCell', - ['$compile', 'uiGridConstants', 'uiGridSelectionConstants', 'gridUtil', '$parse', 'uiGridSelectionService', '$timeout', - function ($compile, uiGridConstants, uiGridSelectionConstants, gridUtil, $parse, uiGridSelectionService, $timeout) { + ['uiGridConstants', 'uiGridSelectionService', + function (uiGridConstants, uiGridSelectionService) { return { priority: -200, // run after default uiGridCell directive restrict: 'A', require: '?^uiGrid', scope: false, link: function ($scope, $elm, $attrs, uiGridCtrl) { - - var touchStartTime = 0; - var touchTimeout = 300; + var touchStartTime = 0, + touchStartPos = {}, + touchTimeout = 300, + touchPosDiff = 100; // Bind to keydown events in the render container if (uiGridCtrl.grid.api.cellNav) { - uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) { if (rowCol === null || rowCol.row !== $scope.row || @@ -845,22 +934,16 @@ return; } - if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") { - uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect); + if (evt.keyCode === uiGridConstants.keymap.SPACE && $scope.col.colDef.name === 'selectionRowHeaderCol') { + evt.preventDefault(); + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), + $scope.grid.options.noUnselect); $scope.$apply(); } - - // uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col); }); } - //$elm.bind('keydown', function (evt) { - // if (evt.keyCode === 32 && $scope.col.colDef.name === "selectionRowHeaderCol") { - // uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect); - // $scope.$apply(); - // } - //}); - var selectCells = function (evt) { // if you click on expandable icon doesn't trigger selection if (evt.target.className === "ui-grid-icon-minus-squared" || evt.target.className === "ui-grid-icon-plus-squared") { @@ -874,22 +957,28 @@ uiGridSelectionService.shiftSelect($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect); } else if (evt.ctrlKey || evt.metaKey) { - uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect, $scope.grid.options.noUnselect); + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + $scope.grid.options.multiSelect, $scope.grid.options.noUnselect); } - else { - uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), $scope.grid.options.noUnselect); + else if ($scope.grid.options.enableSelectRowOnFocus) { + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), + $scope.grid.options.noUnselect); } + $scope.row.setFocused(!$scope.row.isFocused); + $scope.grid.api.selection.raise.rowFocusChanged($scope.row, evt); $scope.$apply(); // don't re-enable the touchend handler for a little while - some devices generate both, and it will // take a little while to move your hand from the mouse to the screen if you have both modes of input - $timeout(function () { + window.setTimeout(function () { $elm.on('touchend', touchEnd); }, touchTimeout); }; var touchStart = function (evt) { touchStartTime = (new Date()).getTime(); + touchStartPos = evt.changedTouches[0]; // if we get a touch event, then stop listening for click $elm.off('click', selectCells); @@ -897,22 +986,28 @@ var touchEnd = function (evt) { var touchEndTime = (new Date()).getTime(); + var touchEndPos = evt.changedTouches[0]; var touchTime = touchEndTime - touchStartTime; + var touchXDiff = Math.abs(touchStartPos.clientX - touchEndPos.clientX) + var touchYDiff = Math.abs(touchStartPos.clientY - touchEndPos.clientY) - if (touchTime < touchTimeout) { + + if (touchXDiff < touchPosDiff && touchYDiff < touchPosDiff) { + if (touchTime < touchTimeout) { // short touch - selectCells(evt); + selectCells(evt); + } } // don't re-enable the click handler for a little while - some devices generate both, and it will // take a little while to move your hand from the screen to the mouse if you have both modes of input - $timeout(function () { + window.setTimeout(function () { $elm.on('click', selectCells); }, touchTimeout); }; function registerRowSelectionEvents() { - if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection) { + if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && $scope.col.colDef.name !== 'selectionRowHeaderCol') { $elm.addClass('ui-grid-disable-selection'); $elm.on('touchstart', touchStart); $elm.on('touchend', touchEnd); @@ -922,10 +1017,9 @@ } } - function deregisterRowSelectionEvents() { + function unregisterRowSelectionEvents() { if ($scope.registered) { $elm.removeClass('ui-grid-disable-selection'); - $elm.off('touchstart', touchStart); $elm.off('touchend', touchEnd); $elm.off('click', selectCells); @@ -935,39 +1029,39 @@ } registerRowSelectionEvents(); + // register a dataChange callback so that we can change the selection configuration dynamically // if the user changes the options - var dataChangeDereg = $scope.grid.registerDataChangeCallback(function () { + var dataChangeUnreg = $scope.grid.registerDataChangeCallback(function () { if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && !$scope.registered) { registerRowSelectionEvents(); - } else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) && + } + else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) && $scope.registered) { - deregisterRowSelectionEvents(); + unregisterRowSelectionEvents(); } }, [uiGridConstants.dataChange.OPTIONS]); - $elm.on('$destroy', dataChangeDereg); + $elm.on('$destroy', dataChangeUnreg); } }; }]); - module.directive('uiGridGridFooter', ['$compile', 'uiGridConstants', 'gridUtil', function ($compile, uiGridConstants, gridUtil) { + module.directive('uiGridGridFooter', ['$compile', 'gridUtil', function ($compile, gridUtil) { return { restrict: 'EA', replace: true, priority: -1000, require: '^uiGrid', scope: true, - compile: function ($elm, $attrs) { + compile: function () { return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { - if (!uiGridCtrl.grid.options.showGridFooter) { return; } - gridUtil.getTemplate('ui-grid/gridFooterSelectedItems') .then(function (contents) { var template = angular.element(contents); @@ -977,7 +1071,6 @@ angular.element($elm[0].getElementsByClassName('ui-grid-grid-footer')[0]).append(newElm); }); }, - post: function ($scope, $elm, $attrs, controllers) { } @@ -985,5 +1078,33 @@ } }; }]); - })(); + +angular.module('ui.grid.selection').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/gridFooterSelectedItems', + "({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})" + ); + + + $templateCache.put('ui-grid/selectionHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeaderButtons', + "
     
    " + ); + + + $templateCache.put('ui-grid/selectionSelectAllButtons', + "
    " + ); + +}]); diff --git a/src/i18n/ui-grid.selection.min.js b/src/i18n/ui-grid.selection.min.js new file mode 100644 index 0000000000..e1c971c2d5 --- /dev/null +++ b/src/i18n/ui-grid.selection.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.selection",["ui.grid"]);e.constant("uiGridSelectionConstants",{featureName:"selection",selectionRowHeaderColName:"selectionRowHeaderCol"}),angular.module("ui.grid").config(["$provide",function(e){e.decorator("GridRow",["$delegate",function(e){return e.prototype.setSelected=function(e){e!==this.isSelected&&(this.isSelected=e,this.grid.selection.selectedCount+=e?1:-1)},e.prototype.setFocused=function(e){e!==this.isFocused&&(this.grid.selection.focusedRow&&(this.grid.selection.focusedRow.isFocused=!1),this.grid.selection.focusedRow=e?this:null,this.isFocused=e)},e}])}]),e.service("uiGridSelectionService",function(){var a={initializeGrid:function(o){o.selection={lastSelectedRow:null,focusedRow:null,selectAll:!1},o.selection.selectedCount=0,a.defaultGridOptions(o.options);var e={events:{selection:{rowFocusChanged:function(e,t,i){},rowSelectionChanged:function(e,t,i){},rowSelectionChangedBatch:function(e,t,i){}}},methods:{selection:{toggleRowSelection:function(e,t){var i=o.getRow(e);null!==i&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectRow:function(e,t){var i=o.getRow(e);null===i||i.isSelected||a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectRowByVisibleIndex:function(e,t){var i=o.renderContainers.body.visibleRowCache[e];null==i||i.isSelected||a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},unSelectRow:function(e,t){var i=o.getRow(e);null!==i&&i.isSelected&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},unSelectRowByVisibleIndex:function(e,t){var i=o.renderContainers.body.visibleRowCache[e];null!=i&&i.isSelected&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectAllRows:function(t){if(!1!==o.options.multiSelect){var i=[];o.rows.forEach(function(e){e.isSelected||!1===e.enableSelection||!1===o.options.isRowSelectable(e)||(e.setSelected(!0),a.decideRaiseSelectionEvent(o,e,i,t))}),o.selection.selectAll=!0,a.decideRaiseSelectionBatchEvent(o,i,t)}},selectAllVisibleRows:function(t){if(!1!==o.options.multiSelect){var i=[];o.rows.forEach(function(e){e.visible?e.isSelected||!1===e.enableSelection||!1===o.options.isRowSelectable(e)||(e.setSelected(!0),a.decideRaiseSelectionEvent(o,e,i,t)):e.isSelected&&(e.setSelected(!1),a.decideRaiseSelectionEvent(o,e,i,t))}),o.selection.selectAll=!0,a.decideRaiseSelectionBatchEvent(o,i,t)}},clearSelectedRows:function(e){a.clearSelectedRows(o,e)},getSelectedRows:function(){return a.getSelectedRows(o).map(function(e){return e.entity}).filter(function(e){return e.hasOwnProperty("$$hashKey")||!angular.isObject(e)})},getSelectedGridRows:function(){return a.getSelectedRows(o)},getSelectedCount:function(){return o.selection.selectedCount},setMultiSelect:function(e){o.options.multiSelect=e},setModifierKeysToMultiSelect:function(e){o.options.modifierKeysToMultiSelect=e},getSelectAllState:function(){return o.selection.selectAll}}}};o.api.registerEventsFromObject(e.events),o.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enableRowSelection=!1!==e.enableRowSelection,e.multiSelect=!1!==e.multiSelect,e.noUnselect=!0===e.noUnselect,e.modifierKeysToMultiSelect=!0===e.modifierKeysToMultiSelect,e.enableRowHeaderSelection=!1!==e.enableRowHeaderSelection,void 0===e.enableFullRowSelection&&(e.enableFullRowSelection=!e.enableRowHeaderSelection),e.enableFocusRowOnRowHeaderClick=!1!==e.enableFocusRowOnRowHeaderClick||!e.enableRowHeaderSelection,e.enableSelectRowOnFocus=!1!==e.enableSelectRowOnFocus,e.enableSelectAll=!1!==e.enableSelectAll,e.enableSelectionBatchEvent=!1!==e.enableSelectionBatchEvent,e.selectionRowHeaderWidth=angular.isDefined(e.selectionRowHeaderWidth)?e.selectionRowHeaderWidth:30,e.enableFooterTotalSelected=!1!==e.enableFooterTotalSelected,e.isRowSelectable=angular.isDefined(e.isRowSelectable)?e.isRowSelectable:angular.noop},toggleRowSelection:function(e,t,i,o,n){if(!1!==t.enableSelection){var l,c=t.isSelected;o||(c?1<(l=a.getSelectedRows(e)).length&&(c=!1,a.clearSelectedRows(e,i)):a.clearSelectedRows(e,i)),c&&n||(t.setSelected(!c),!0===t.isSelected&&(e.selection.lastSelectedRow=t),l=a.getSelectedRows(e),e.selection.selectAll=e.rows.length===l.length,e.api.selection.raise.rowSelectionChanged(t,i))}},shiftSelect:function(e,t,i,o){if(o){var n=0({{"search.selectedItems" | t}} {{grid.selection.selectedCount}})'),e.put("ui-grid/selectionHeaderCell",'
    \x3c!--
     
    --\x3e
    '),e.put("ui-grid/selectionRowHeader",'
    '),e.put("ui-grid/selectionRowHeaderButtons",''),e.put("ui-grid/selectionSelectAllButtons",'')}]); \ No newline at end of file diff --git a/src/features/tree-base/js/tree-base.js b/src/i18n/ui-grid.tree-base.js similarity index 82% rename from src/features/tree-base/js/tree-base.js rename to src/i18n/ui-grid.tree-base.js index 583a43d400..3ce7e90b09 100644 --- a/src/features/tree-base/js/tree-base.js +++ b/src/i18n/ui-grid.tree-base.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -128,9 +133,9 @@ var service = { - initializeGrid: function (grid, $scope) { + initializeGrid: function (grid) { - //add feature namespace and any properties to grid for needed + // add feature namespace and any properties to grid for needed /** * @ngdoc object * @name ui.grid.treeBase.grid:treeBase @@ -267,7 +272,7 @@ * When the data is loaded the grid will automatically refresh to show these new rows * *
    -               *      gridApi.treeBase.on.rowExpanded(scope,function(row){})
    +               *      gridApi.treeBase.on.rowExpanded(scope,function(row) {})
                    * 
    * @param {gridRow} row the row that was expanded. You can also * retrieve the grid from this row with row.grid @@ -282,7 +287,7 @@ * a purpose at the moment, included for symmetry * *
    -               *      gridApi.treeBase.on.rowCollapsed(scope,function(row){})
    +               *      gridApi.treeBase.on.rowCollapsed(scope,function(row) {})
                    * 
    * @param {gridRow} row the row that was collapsed. You can also * retrieve the grid from this row with row.grid @@ -330,9 +335,10 @@ * @methodOf ui.grid.treeBase.api:PublicApi * @description expand the immediate children of the specified row * @param {gridRow} row the row you wish to expand + * @param {boolean} recursive true if you wish to expand the row's ancients */ - expandRow: function (row) { - service.expandRow(grid, row); + expandRow: function (row, recursive) { + service.expandRow(grid, row, recursive); }, /** @@ -412,8 +418,8 @@ * @returns {Array} array of children of this row, the children * are all gridRows */ - getRowChildren: function ( row ){ - return row.treeNode.children.map( function( childNode ){ + getRowChildren: function ( row ) { + return row.treeNode.children.map( function( childNode ) { return childNode.row; }); } @@ -428,7 +434,7 @@ defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.treeBase.api:GridOptions @@ -455,7 +461,7 @@ * but will make the tree row header wider *
    Defaults to 10 */ - gridOptions.treeIndent = gridOptions.treeIndent || 10; + gridOptions.treeIndent = (gridOptions.treeIndent != null) ? gridOptions.treeIndent : 10; /** * @ngdoc object @@ -501,16 +507,16 @@ * { * aggregationName: { * label: (optional) string, - * aggregationFn: function( aggregation, fieldValue, numValue, row ){...}, - * finalizerFn: (optional) function( aggregation ){...} - * }, + * aggregationFn: function( aggregation, fieldValue, numValue, row ) {...}, + * finalizerFn: (optional) function( aggregation ) {...} + * }, * mean: { * label: 'mean', - * aggregationFn: function( aggregation, fieldValue, numValue ){ - * aggregation.count = (aggregation.count || 1) + 1; + * aggregationFn: function( aggregation, fieldValue, numValue ) { + * aggregation.count = (aggregation.count || 1) + 1; * aggregation.sum = (aggregation.sum || 0) + numValue; * }, - * finalizerFn: function( aggregation ){ + * finalizerFn: function( aggregation ) { * aggregation.value = aggregation.sum / aggregation.count * } * } @@ -545,7 +551,7 @@ * @description Sets the tree defaults based on the columnDefs * * @param {object} colDef columnDef we're basing on - * @param {GridCol} col the column we're to update + * @param {GridColumn} col the column we're to update * @param {object} gridOptions the options we should use * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved */ @@ -565,15 +571,15 @@ * a number (most aggregations work on numbers) * @example *
    -         *    customTreeAggregationFn = function ( aggregation, fieldValue, numValue, row ){
    +         *    customTreeAggregationFn = function ( aggregation, fieldValue, numValue, row ) {
              *      // calculates the average of the squares of the values
    -         *      if ( typeof(aggregation.count) === 'undefined' ){
    +         *      if ( typeof(aggregation.count) === 'undefined' ) {
              *        aggregation.count = 0;
              *      }
              *      aggregation.count++;
              *
    -         *      if ( !isNaN(numValue) ){
    -         *        if ( typeof(aggregation.total) === 'undefined' ){
    +         *      if ( !isNaN(numValue) ) {
    +         *        if ( typeof(aggregation.total) === 'undefined' ) {
              *          aggregation.total = 0;
              *        }
              *        aggregation.total = aggregation.total + numValue * numValue;
    @@ -584,7 +590,7 @@
              *  
    *
    Defaults to undefined. May be overwritten by treeAggregationType, the two options should not be used together. */ - if ( typeof(colDef.customTreeAggregationFn) !== 'undefined' ){ + if ( typeof(colDef.customTreeAggregationFn) !== 'undefined' ) { col.treeAggregationFn = colDef.customTreeAggregationFn; } @@ -611,13 +617,14 @@ *
    Takes precendence over a treeAggregationFn, the two options should not be used together. *
    Defaults to undefined. */ - if ( typeof(colDef.treeAggregationType) !== 'undefined' ){ + if ( typeof(colDef.treeAggregationType) !== 'undefined' ) { col.treeAggregation = { type: colDef.treeAggregationType }; - if ( typeof(gridOptions.treeCustomAggregations[colDef.treeAggregationType]) !== 'undefined' ){ + if ( typeof(gridOptions.treeCustomAggregations[colDef.treeAggregationType]) !== 'undefined' ) { col.treeAggregationFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].aggregationFn; col.treeAggregationFinalizerFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].finalizerFn; col.treeAggregation.label = gridOptions.treeCustomAggregations[colDef.treeAggregationType].label; - } else if ( typeof(service.nativeAggregations()[colDef.treeAggregationType]) !== 'undefined' ){ + } + else if ( typeof(service.nativeAggregations()[colDef.treeAggregationType]) !== 'undefined' ) { col.treeAggregationFn = service.nativeAggregations()[colDef.treeAggregationType].aggregationFn; col.treeAggregation.label = service.nativeAggregations()[colDef.treeAggregationType].label; } @@ -629,8 +636,8 @@ * @propertyOf ui.grid.treeBase.api:ColumnDef * @description A custom label to use for this aggregation. If provided we don't use native i18n. */ - if ( typeof(colDef.treeAggregationLabel) !== 'undefined' ){ - if (typeof(col.treeAggregation) === 'undefined' ){ + if ( typeof(colDef.treeAggregationLabel) !== 'undefined' ) { + if (typeof(col.treeAggregation) === 'undefined' ) { col.treeAggregation = {}; } col.treeAggregation.label = colDef.treeAggregationLabel; @@ -678,13 +685,13 @@ * * @example *
    -         *    customTreeAggregationFinalizerFn = function ( aggregation ){
    +         *    customTreeAggregationFinalizerFn = function ( aggregation ) {
              *      aggregation.rendered = aggregation.label + aggregation.value / 100 + '%';
              *    }
              *  
    *
    Defaults to undefined. */ - if ( typeof(col.customTreeAggregationFinalizerFn) === 'undefined' ){ + if ( typeof(col.customTreeAggregationFinalizerFn) === 'undefined' ) { col.customTreeAggregationFinalizerFn = colDef.customTreeAggregationFinalizerFn; } @@ -700,7 +707,7 @@ * * @param {Grid} grid grid object */ - createRowHeader: function( grid ){ + createRowHeader: function( grid ) { var rowHeaderColumnDef = { name: uiGridTreeBaseConstants.rowHeaderColName, displayName: '', @@ -767,19 +774,20 @@ * @param {string} targetState the state we want to set it to */ setAllNodes: function (grid, treeNode, targetState) { - if ( typeof(treeNode.state) !== 'undefined' && treeNode.state !== targetState ){ + if ( typeof(treeNode.state) !== 'undefined' && treeNode.state !== targetState ) { treeNode.state = targetState; - if ( targetState === uiGridTreeBaseConstants.EXPANDED ){ + if ( targetState === uiGridTreeBaseConstants.EXPANDED ) { grid.api.treeBase.raise.rowExpanded(treeNode.row); - } else { + } + else { grid.api.treeBase.raise.rowCollapsed(treeNode.row); } } // set all child nodes - if ( treeNode.children ){ - treeNode.children.forEach(function( childNode ){ + if ( treeNode.children ) { + treeNode.children.forEach(function( childNode ) { service.setAllNodes(grid, childNode, targetState); }); } @@ -796,15 +804,16 @@ * @param {Grid} grid grid object * @param {GridRow} row the row we want to toggle */ - toggleRowTreeState: function ( grid, row ){ - if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){ + toggleRowTreeState: function ( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { return; } - if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED){ + if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED) { service.collapseRow(grid, row); - } else { - service.expandRow(grid, row); + } + else { + service.expandRow(grid, row, false); } grid.queueGridRefresh(); @@ -819,17 +828,39 @@ * * @param {Grid} grid grid object * @param {GridRow} row the row we want to expand + * @param {boolean} recursive true if you wish to expand the row's ancients */ - expandRow: function ( grid, row ){ - if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){ - return; + expandRow: function ( grid, row, recursive ) { + if ( recursive ) { + var parents = []; + while ( row && typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 && row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ) { + parents.push(row); + row = row.treeNode.parentRow; + } + + if ( parents.length > 0 ) { + row = parents.pop(); + while ( row ) { + row.treeNode.state = uiGridTreeBaseConstants.EXPANDED; + grid.api.treeBase.raise.rowExpanded(row); + row = parents.pop(); + } + + grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); + grid.queueGridRefresh(); + } } + else { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } - if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ){ - row.treeNode.state = uiGridTreeBaseConstants.EXPANDED; - grid.api.treeBase.raise.rowExpanded(row); - grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); - grid.queueGridRefresh(); + if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ) { + row.treeNode.state = uiGridTreeBaseConstants.EXPANDED; + grid.api.treeBase.raise.rowExpanded(row); + grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); + grid.queueGridRefresh(); + } } }, @@ -843,8 +874,8 @@ * @param {Grid} grid grid object * @param {GridRow} row the row we want to expand */ - expandRowChildren: function ( grid, row ){ - if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){ + expandRowChildren: function ( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { return; } @@ -863,12 +894,12 @@ * @param {Grid} grid grid object * @param {GridRow} row the row we want to collapse */ - collapseRow: function( grid, row ){ - if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){ + collapseRow: function( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { return; } - if ( row.treeNode.state !== uiGridTreeBaseConstants.COLLAPSED ){ + if ( row.treeNode.state !== uiGridTreeBaseConstants.COLLAPSED ) { row.treeNode.state = uiGridTreeBaseConstants.COLLAPSED; grid.treeBase.expandAll = false; grid.api.treeBase.raise.rowCollapsed(row); @@ -886,8 +917,8 @@ * @param {Grid} grid grid object * @param {GridRow} row the row we want to collapse */ - collapseRowChildren: function( grid, row ){ - if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ){ + collapseRowChildren: function( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { return; } @@ -912,29 +943,31 @@ * @param {object} tree the grid to check * @returns {boolean} whether or not the tree is all expanded */ - allExpanded: function( tree ){ + allExpanded: function( tree ) { var allExpanded = true; - tree.forEach( function( node ){ - if ( !service.allExpandedInternal( node ) ){ + + tree.forEach(function( node ) { + if ( !service.allExpandedInternal( node ) ) { allExpanded = false; } }); return allExpanded; }, - allExpandedInternal: function( treeNode ){ - if ( treeNode.children && treeNode.children.length > 0 ){ - if ( treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){ + allExpandedInternal: function( treeNode ) { + if ( treeNode.children && treeNode.children.length > 0 ) { + if ( treeNode.state === uiGridTreeBaseConstants.COLLAPSED ) { return false; } var allExpanded = true; - treeNode.children.forEach( function( node ){ - if ( !service.allExpandedInternal( node ) ){ + treeNode.children.forEach( function( node ) { + if ( !service.allExpandedInternal( node ) ) { allExpanded = false; } }); return allExpanded; - } else { + } + else { return true; } }, @@ -962,15 +995,13 @@ * @returns {array} the updated rows */ treeRows: function( renderableRows ) { - if (renderableRows.length === 0){ + var grid = this; + + if (renderableRows.length === 0) { + service.updateRowHeaderWidth( grid ); return renderableRows; } - var grid = this; - var currentLevel = 0; - var currentState = uiGridTreeBaseConstants.EXPANDED; - var parents = []; - grid.treeBase.tree = service.createTree( grid, renderableRows ); service.updateRowHeaderWidth( grid ); @@ -997,20 +1028,21 @@ * * @param {Grid} grid the grid we want to set the row header on */ - updateRowHeaderWidth: function( grid ){ - var rowHeader = grid.getColumn(uiGridTreeBaseConstants.rowHeaderColName); + updateRowHeaderWidth: function( grid ) { + var rowHeader = grid.getColumn(uiGridTreeBaseConstants.rowHeaderColName), + newWidth = grid.options.treeRowHeaderBaseWidth + grid.options.treeIndent * Math.max(grid.treeBase.numberLevels - 1, 0); - var newWidth = grid.options.treeRowHeaderBaseWidth + grid.options.treeIndent * Math.max(grid.treeBase.numberLevels - 1, 0); - if ( rowHeader && newWidth !== rowHeader.width ){ + if ( rowHeader && newWidth !== rowHeader.width ) { rowHeader.width = newWidth; grid.queueRefresh(); } var newVisibility = true; - if ( grid.options.showTreeRowHeader === false ){ + + if ( grid.options.showTreeRowHeader === false ) { newVisibility = false; } - if ( grid.options.treeRowHeaderAlwaysVisible === false && grid.treeBase.numberLevels <= 0 ){ + if ( grid.options.treeRowHeaderAlwaysVisible === false && grid.treeBase.numberLevels <= 0 ) { newVisibility = false; } if ( rowHeader && rowHeader.visible !== newVisibility ) { @@ -1028,18 +1060,18 @@ * @description Creates an array of rows based on the tree, exporting only * the visible nodes and leaves * - * @param {array} nodeList the list of nodes - can be grid.treeBase.tree, or can be node.children when + * @param {array} nodeList The list of nodes - can be grid.treeBase.tree, or can be node.children when * we're calling recursively * @returns {array} renderable rows */ - renderTree: function( nodeList ){ + renderTree: function( nodeList ) { var renderableRows = []; - nodeList.forEach( function ( node ){ - if ( node.row.visible ){ + nodeList.forEach( function ( node ) { + if ( node.row.visible ) { renderableRows.push( node.row ); } - if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){ + if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ) { renderableRows = renderableRows.concat( service.renderTree( node.children ) ); } }); @@ -1053,63 +1085,82 @@ * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService * @description Creates a tree from the renderableRows * - * @param {Grid} grid the grid - * @param {array} renderableRows the rows we want to create a tree from - * @returns {object} the tree we've build + * @param {Grid} grid The grid + * @param {array} renderableRows The rows we want to create a tree from + * @returns {object} The tree we've build */ createTree: function( grid, renderableRows ) { - var currentLevel = -1; - var parents = []; - var currentState; + var currentLevel = -1, + parentsCache = {}, + parents = [], + currentState; + grid.treeBase.tree = []; grid.treeBase.numberLevels = 0; + var aggregations = service.getAggregations( grid ); - var createNode = function( row ){ - if ( typeof(row.entity.$$treeLevel) !== 'undefined' && row.treeLevel !== row.entity.$$treeLevel ){ + function createNode( row ) { + if ( !row.internalRow && row.treeLevel !== row.entity.$$treeLevel ) { row.treeLevel = row.entity.$$treeLevel; } - if ( row.treeLevel <= currentLevel ){ + if ( row.treeLevel <= currentLevel ) { // pop any levels that aren't parents of this level, formatting the aggregation at the same time - while ( row.treeLevel <= currentLevel ){ + while ( row.treeLevel <= currentLevel ) { var lastParent = parents.pop(); service.finaliseAggregations( lastParent ); currentLevel--; } // reset our current state based on the new parent, set to expanded if this is a level 0 node - if ( parents.length > 0 ){ + if ( parents.length > 0 ) { currentState = service.setCurrentState(parents); - } else { + } + else { currentState = uiGridTreeBaseConstants.EXPANDED; } } + // If row header as parent exists in parentsCache + if ( + typeof row.treeLevel !== 'undefined' && + row.treeLevel !== null && + row.treeLevel >= 0 && + parentsCache.hasOwnProperty(row.uid) + ) { + parents.push(parentsCache[row.uid]); + } + // aggregate if this is a leaf node - if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ){ + if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ) { service.aggregate( grid, row, parents ); } // add this node to the tree - service.addOrUseNode(grid, row, parents, aggregations); + if (!parentsCache.hasOwnProperty(row.uid)) { + service.addOrUseNode(grid, row, parents, aggregations); + } - if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ){ - parents.push(row); + if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ) { + if (!parentsCache.hasOwnProperty(row.uid)) { + parentsCache[row.uid] = row; + parents.push(row); + } currentLevel++; currentState = service.setCurrentState(parents); } // update the tree number of levels, so we can set header width if we need to - if ( grid.treeBase.numberLevels < row.treeLevel + 1){ + if ( grid.treeBase.numberLevels < row.treeLevel + 1) { grid.treeBase.numberLevels = row.treeLevel + 1; } - }; + } renderableRows.forEach( createNode ); - // finalise remaining aggregations - while ( parents.length > 0 ){ + // finalize remaining aggregations + while ( parents.length > 0 ) { var lastParent = parents.pop(); service.finaliseAggregations( lastParent ); } @@ -1125,29 +1176,29 @@ * @description Creates a tree node for this row. If this row already has a treeNode * recorded against it, preserves the state, but otherwise overwrites the data. * - * @param {grid} grid the grid we're operating on - * @param {gridRow} row the row we want to set - * @param {array} parents an array of the parents this row should have - * @param {array} aggregationBase empty aggregation information - * @returns {undefined} updates the parents array, updates the row to have a treeNode, and updates the + * @param {grid} grid The grid we're operating on + * @param {gridRow} row The row we want to set + * @param {array} parents An array of the parents this row should have + * @param {array} aggregationBase Empty aggregation information + * @returns {undefined} Updates the parents array, updates the row to have a treeNode, and updates the * grid.treeBase.tree */ - addOrUseNode: function( grid, row, parents, aggregationBase ){ + addOrUseNode: function( grid, row, parents, aggregationBase ) { var newAggregations = []; - aggregationBase.forEach( function(aggregation){ + aggregationBase.forEach( function(aggregation) { newAggregations.push(service.buildAggregationObject(aggregation.col)); }); var newNode = { state: uiGridTreeBaseConstants.COLLAPSED, row: row, parentRow: null, aggregations: newAggregations, children: [] }; - if ( row.treeNode ){ + if ( row.treeNode ) { newNode.state = row.treeNode.state; } - if ( parents.length > 0 ){ + if ( parents.length > 0 ) { newNode.parentRow = parents[parents.length - 1]; } row.treeNode = newNode; - if ( parents.length === 0 ){ + if ( parents.length === 0 ) { grid.treeBase.tree.push( newNode ); } else { parents[parents.length - 1].treeNode.children.push( newNode ); @@ -1163,13 +1214,14 @@ * If any node in the hierarchy is collapsed, then return collapsed, otherwise return * expanded. * - * @param {array} parents an array of the parents this row should have - * @returns {string} the state we should be setting to any nodes we see + * @param {array} parents An array of the parents this row should have + * @returns {string} The state we should be setting to any nodes we see */ - setCurrentState: function( parents ){ + setCurrentState: function( parents ) { var currentState = uiGridTreeBaseConstants.EXPANDED; - parents.forEach( function(parent){ - if ( parent.treeNode.state === uiGridTreeBaseConstants.COLLAPSED ){ + + parents.forEach( function(parent) { + if ( parent.treeNode.state === uiGridTreeBaseConstants.COLLAPSED ) { currentState = uiGridTreeBaseConstants.COLLAPSED; } }); @@ -1191,12 +1243,12 @@ * We only sort tree nodes that are expanded - no point in wasting effort sorting collapsed * nodes * - * @param {Grid} grid the grid to get the aggregation information from - * @returns {array} the aggregation information + * @param {Grid} grid The grid to get the aggregation information from + * @returns {array} The aggregation information */ - sortTree: function( grid ){ + sortTree: function( grid ) { grid.columns.forEach( function( column ) { - if ( column.sort && column.sort.ignoreSort ){ + if ( column.sort && column.sort.ignoreSort ) { delete column.sort.ignoreSort; } }); @@ -1204,19 +1256,19 @@ grid.treeBase.tree = service.sortInternal( grid, grid.treeBase.tree ); }, - sortInternal: function( grid, treeList ){ - var rows = treeList.map( function( node ){ + sortInternal: function( grid, treeList ) { + var rows = treeList.map( function( node ) { return node.row; }); rows = rowSorter.sort( grid, rows, grid.columns ); - var treeNodes = rows.map( function( row ){ + var treeNodes = rows.map( function( row ) { return row.treeNode; }); - treeNodes.forEach( function( node ){ - if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ){ + treeNodes.forEach( function( node ) { + if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ) { node.children = service.sortInternal( grid, node.children ); } }); @@ -1239,11 +1291,11 @@ * * @param {Grid} grid the grid to fix filters on */ - fixFilter: function( grid ){ + fixFilter: function( grid ) { var parentsVisible; - grid.treeBase.tree.forEach( function( node ){ - if ( node.children && node.children.length > 0 ){ + grid.treeBase.tree.forEach( function( node ) { + if ( node.children && node.children.length > 0 ) { parentsVisible = node.row.visible; service.fixFilterInternal( node.children, parentsVisible ); } @@ -1251,13 +1303,13 @@ }, fixFilterInternal: function( nodes, parentsVisible) { - nodes.forEach( function( node ){ - if ( node.row.visible && !parentsVisible ){ + nodes.forEach(function( node ) { + if ( node.row.visible && !parentsVisible ) { service.setParentsVisible( node ); parentsVisible = true; } - if ( node.children && node.children.length > 0 ){ + if ( node.children && node.children.length > 0 ) { if ( service.fixFilterInternal( node.children, ( parentsVisible && node.row.visible ) ) ) { parentsVisible = true; } @@ -1267,8 +1319,8 @@ return parentsVisible; }, - setParentsVisible: function( node ){ - while ( node.parentRow ){ + setParentsVisible: function( node ) { + while ( node.parentRow ) { node.parentRow.visible = true; node = node.parentRow.treeNode; } @@ -1281,17 +1333,17 @@ * @description Build the object which is stored on the column for holding meta-data about the aggregation. * This method should only be called with columns which have an aggregation. * - * @param {Column} the column which this object relates to - * @returns {object} {col: Column object, label: string, type: string (optional)} + * @param {GridColumn} column The column which this object relates to + * @returns {object} {col: GridColumn object, label: string, type: string (optional)} */ - buildAggregationObject: function( column ){ + buildAggregationObject: function( column ) { var newAggregation = { col: column }; - if ( column.treeAggregation && column.treeAggregation.type ){ + if ( column.treeAggregation && column.treeAggregation.type ) { newAggregation.type = column.treeAggregation.type; } - if ( column.treeAggregation && column.treeAggregation.label ){ + if ( column.treeAggregation && column.treeAggregation.label ) { newAggregation.label = column.treeAggregation.label; } @@ -1308,14 +1360,14 @@ * @param {Grid} grid the grid to get the aggregation information from * @returns {array} the aggregation information */ - getAggregations: function( grid ){ + getAggregations: function( grid ) { var aggregateArray = []; - grid.columns.forEach( function(column){ - if ( typeof(column.treeAggregationFn) !== 'undefined' ){ + grid.columns.forEach( function(column) { + if ( typeof(column.treeAggregationFn) !== 'undefined' ) { aggregateArray.push( service.buildAggregationObject(column) ); - if ( grid.options.showColumnFooter && typeof(column.colDef.aggregationType) === 'undefined' && column.treeAggregation ){ + if ( grid.options.showColumnFooter && typeof(column.colDef.aggregationType) === 'undefined' && column.treeAggregation ) { // Add aggregation object for footer column.treeFooterAggregation = service.buildAggregationObject(column); column.aggregationType = service.treeFooterAggregationType; @@ -1339,27 +1391,35 @@ * @param {GridRow} row the row we want to set grouping visibility on * @param {array} parents the parents that we would want to aggregate onto */ - aggregate: function( grid, row, parents ){ - if ( parents.length === 0 && row.treeNode && row.treeNode.aggregations ){ - row.treeNode.aggregations.forEach(function(aggregation){ + aggregate: function( grid, row, parents ) { + if (parents.length === 0 && row.treeNode && row.treeNode.aggregations) { + row.treeNode.aggregations.forEach(function(aggregation) { // Calculate aggregations for footer even if there are no grouped rows - if ( typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ) { + if (typeof(aggregation.col.treeFooterAggregation) !== 'undefined') { var fieldValue = grid.getCellValue(row, aggregation.col); var numValue = Number(fieldValue); - aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + if (aggregation.col.treeAggregationFn) { + aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + } else { + aggregation.col.treeFooterAggregation.value = undefined; + } } }); } - parents.forEach( function( parent, index ){ - if ( parent.treeNode.aggregations ){ - parent.treeNode.aggregations.forEach( function( aggregation ){ + parents.forEach( function( parent, index ) { + if (parent.treeNode.aggregations) { + parent.treeNode.aggregations.forEach( function( aggregation ) { var fieldValue = grid.getCellValue(row, aggregation.col); var numValue = Number(fieldValue); aggregation.col.treeAggregationFn(aggregation, fieldValue, numValue, row); - if ( index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ){ - aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + if (index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined') { + if (aggregation.col.treeAggregationFn) { + aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + } else { + aggregation.col.treeFooterAggregation.value = undefined; + } } }); } @@ -1369,7 +1429,7 @@ // Aggregation routines - no doco needed as self evident nativeAggregations: function() { - var nativeAggregations = { + return { count: { label: i18nService.get().aggregation.count, menuTitle: i18nService.get().grouping.aggregate_count, @@ -1413,11 +1473,11 @@ max: { label: i18nService.get().aggregation.max, menuTitle: i18nService.get().grouping.aggregate_max, - aggregationFn: function( aggregation, fieldValue, numValue ){ - if ( typeof(aggregation.value) === 'undefined' ){ + aggregationFn: function( aggregation, fieldValue, numValue ) { + if ( typeof(aggregation.value) === 'undefined' ) { aggregation.value = fieldValue; } else { - if ( typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue > aggregation.value || aggregation.value === null)){ + if ( typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue > aggregation.value || aggregation.value === null)) { aggregation.value = fieldValue; } } @@ -1427,18 +1487,18 @@ avg: { label: i18nService.get().aggregation.avg, menuTitle: i18nService.get().grouping.aggregate_avg, - aggregationFn: function( aggregation, fieldValue, numValue ){ - if ( typeof(aggregation.count) === 'undefined' ){ + aggregationFn: function( aggregation, fieldValue, numValue ) { + if ( typeof(aggregation.count) === 'undefined' ) { aggregation.count = 1; } else { aggregation.count++; } - if ( isNaN(numValue) ){ + if ( isNaN(numValue) ) { return; } - if ( typeof(aggregation.value) === 'undefined' || typeof(aggregation.sum) === 'undefined' ){ + if ( typeof(aggregation.value) === 'undefined' || typeof(aggregation.sum) === 'undefined' ) { aggregation.value = numValue; aggregation.sum = numValue; } else { @@ -1448,7 +1508,6 @@ } } }; - return nativeAggregations; }, /** @@ -1457,21 +1516,21 @@ * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService * @description Helper function used to finalize aggregation nodes and footer cells * - * @param {gridRow} row the parent we're finalising - * @param {aggregation} the aggregation object manipulated by the aggregationFn + * @param {gridRow} row The parent we're finalising + * @param {aggregation} aggregation The aggregation object manipulated by the aggregationFn */ - finaliseAggregation: function(row, aggregation){ - if ( aggregation.col.treeAggregationUpdateEntity && typeof(row) !== 'undefined' && typeof(row.entity[ '$$' + aggregation.col.uid ]) !== 'undefined' ){ + finaliseAggregation: function(row, aggregation) { + if ( aggregation.col.treeAggregationUpdateEntity && typeof(row) !== 'undefined' && typeof(row.entity[ '$$' + aggregation.col.uid ]) !== 'undefined' ) { angular.extend( aggregation, row.entity[ '$$' + aggregation.col.uid ]); } - if ( typeof(aggregation.col.treeAggregationFinalizerFn) === 'function' ){ + if ( typeof(aggregation.col.treeAggregationFinalizerFn) === 'function' ) { aggregation.col.treeAggregationFinalizerFn( aggregation ); } - if ( typeof(aggregation.col.customTreeAggregationFinalizerFn) === 'function' ){ + if ( typeof(aggregation.col.customTreeAggregationFinalizerFn) === 'function' ) { aggregation.col.customTreeAggregationFinalizerFn( aggregation ); } - if ( typeof(aggregation.rendered) === 'undefined' ){ + if ( typeof(aggregation.rendered) === 'undefined' ) { aggregation.rendered = aggregation.label ? aggregation.label + aggregation.value : aggregation.value; } }, @@ -1494,18 +1553,19 @@ * * @param {gridRow} row the parent we're finalising */ - finaliseAggregations: function( row ){ - if ( row == null || typeof(row.treeNode.aggregations) === 'undefined' ){ + finaliseAggregations: function( row ) { + if ( row == null || typeof(row.treeNode.aggregations) === 'undefined' ) { return; } row.treeNode.aggregations.forEach( function( aggregation ) { service.finaliseAggregation(row, aggregation); - if ( aggregation.col.treeAggregationUpdateEntity ){ + if ( aggregation.col.treeAggregationUpdateEntity ) { var aggregationCopy = {}; - angular.forEach( aggregation, function( value, key ){ - if ( aggregation.hasOwnProperty(key) && key !== 'col' ){ + + angular.forEach( aggregation, function( value, key ) { + if ( aggregation.hasOwnProperty(key) && key !== 'col' ) { aggregationCopy[key] = value; } }); @@ -1522,12 +1582,12 @@ * @description Uses the tree aggregation functions and finalizers to set the * column footer aggregations. * - * @param {rows} visible rows. not used, but accepted to match signature of GridColumn.aggregationType - * @param {gridColumn} the column we are finalizing + * @param {rows} rows The visible rows. not used, but accepted to match signature of GridColumn.aggregationType + * @param {GridColumn} column The column we are finalizing */ treeFooterAggregationType: function( rows, column ) { service.finaliseAggregation(undefined, column.treeFooterAggregation); - if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ){ + if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ) { // The was apparently no aggregation performed (perhaps this is a grouped column return ''; } @@ -1536,7 +1596,6 @@ }; return service; - }]); @@ -1557,9 +1616,25 @@ require: '^uiGrid', link: function($scope, $elm, $attrs, uiGridCtrl) { var self = uiGridCtrl.grid; + $scope.treeButtonClass = function(row) { + if ( ( self.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) { + if (row.treeNode.state === 'expanded' ) { + return 'ui-grid-icon-minus-squared'; + } + if (row.treeNode.state === 'collapsed' ) { + return 'ui-grid-icon-plus-squared'; + } + } + }; $scope.treeButtonClick = function(row, evt) { + evt.stopPropagation(); uiGridTreeBaseService.toggleRowTreeState(self, row, evt); }; + $scope.treeButtonKeyDown = function (row, evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + $scope.treeButtonClick(row, evt); + } + }; } }; }]); @@ -1579,16 +1654,28 @@ restrict: 'E', template: $templateCache.get('ui-grid/treeBaseExpandAllButtons'), scope: false, - link: function($scope, $elm, $attrs, uiGridCtrl) { + link: function($scope) { var self = $scope.col.grid; - + $scope.headerButtonClass = function() { + if (self.treeBase.numberLevels > 0 && self.treeBase.expandAll) { + return 'ui-grid-icon-minus-squared'; + } + if (self.treeBase.numberLevels > 0 && !self.treeBase.expandAll) { + return 'ui-grid-icon-plus-squared'; + } + }; $scope.headerButtonClick = function(row, evt) { - if ( self.treeBase.expandAll ){ + if ( self.treeBase.expandAll ) { uiGridTreeBaseService.collapseAllRows(self, evt); } else { uiGridTreeBaseService.expandAllRows(self, evt); } }; + $scope.headerButtonKeyDown = function (evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + $scope.headerButtonClick(self, evt); + } + }; } }; }]); @@ -1602,12 +1689,11 @@ * @description Stacks on top of ui.grid.uiGridViewport to set formatting on a tree header row */ module.directive('uiGridViewport', - ['$compile', 'uiGridConstants', 'gridUtil', '$parse', - function ($compile, uiGridConstants, gridUtil, $parse) { + function () { return { priority: -200, // run after default directive scope: false, - compile: function ($elm, $attrs) { + compile: function ($elm) { var rowRepeatDiv = angular.element($elm.children().children()[0]); var existingNgClass = rowRepeatDiv.attr("ng-class"); @@ -1628,5 +1714,29 @@ }; } }; - }]); + }); })(); + +angular.module('ui.grid.treeBase').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/treeBaseExpandAllButtons', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeaderButtons', + "
    -1 }\" tabindex=\"0\" ng-keydown=\"treeButtonKeyDown(row, $event)\" ng-click=\"treeButtonClick(row, $event)\">  
    " + ); + +}]); diff --git a/src/i18n/ui-grid.tree-base.min.js b/src/i18n/ui-grid.tree-base.min.js new file mode 100644 index 0000000000..2bb21d49c5 --- /dev/null +++ b/src/i18n/ui-grid.tree-base.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.treeBase",["ui.grid"]);e.constant("uiGridTreeBaseConstants",{featureName:"treeBase",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),e.service("uiGridTreeBaseService",["$q","uiGridTreeBaseConstants","gridUtil","GridRow","gridClassFactory","i18nService","uiGridConstants","rowSorter",function(e,l,t,r,n,o,a,i){var g={initializeGrid:function(r){r.treeBase={},r.treeBase.numberLevels=0,r.treeBase.expandAll=!1,r.treeBase.tree=[],g.defaultGridOptions(r.options),r.registerRowsProcessor(g.treeRows,410),r.registerColumnBuilder(g.treeBaseColumnBuilder),g.createRowHeader(r);var e={events:{treeBase:{rowExpanded:{},rowCollapsed:{}}},methods:{treeBase:{expandAllRows:function(){g.expandAllRows(r)},collapseAllRows:function(){g.collapseAllRows(r)},toggleRowTreeState:function(e){g.toggleRowTreeState(r,e)},expandRow:function(e,t){g.expandRow(r,e,t)},expandRowChildren:function(e){g.expandRowChildren(r,e)},collapseRow:function(e){g.collapseRow(r,e)},collapseRowChildren:function(e){g.collapseRowChildren(r,e)},getTreeExpandedState:function(){return{expandedState:g.getTreeState(r)}},setTreeState:function(e){g.setTreeState(r,e)},getRowChildren:function(e){return e.treeNode.children.map(function(e){return e.row})}}}};r.api.registerEventsFromObject(e.events),r.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.treeRowHeaderBaseWidth=e.treeRowHeaderBaseWidth||30,e.treeIndent=null!=e.treeIndent?e.treeIndent:10,e.showTreeRowHeader=!1!==e.showTreeRowHeader,e.showTreeExpandNoChildren=!1!==e.showTreeExpandNoChildren,e.treeRowHeaderAlwaysVisible=!1!==e.treeRowHeaderAlwaysVisible,e.treeCustomAggregations=e.treeCustomAggregations||{},e.enableExpandAll=!1!==e.enableExpandAll},treeBaseColumnBuilder:function(e,t,r){void 0!==e.customTreeAggregationFn&&(t.treeAggregationFn=e.customTreeAggregationFn),void 0!==e.treeAggregationType&&(t.treeAggregation={type:e.treeAggregationType},void 0!==r.treeCustomAggregations[e.treeAggregationType]?(t.treeAggregationFn=r.treeCustomAggregations[e.treeAggregationType].aggregationFn,t.treeAggregationFinalizerFn=r.treeCustomAggregations[e.treeAggregationType].finalizerFn,t.treeAggregation.label=r.treeCustomAggregations[e.treeAggregationType].label):void 0!==g.nativeAggregations()[e.treeAggregationType]&&(t.treeAggregationFn=g.nativeAggregations()[e.treeAggregationType].aggregationFn,t.treeAggregation.label=g.nativeAggregations()[e.treeAggregationType].label)),void 0!==e.treeAggregationLabel&&(void 0===t.treeAggregation&&(t.treeAggregation={}),t.treeAggregation.label=e.treeAggregationLabel),t.treeAggregationUpdateEntity=!1!==e.treeAggregationUpdateEntity,void 0===t.customTreeAggregationFinalizerFn&&(t.customTreeAggregationFinalizerFn=e.customTreeAggregationFinalizerFn)},createRowHeader:function(e){var t={name:l.rowHeaderColName,displayName:"",width:e.options.treeRowHeaderBaseWidth,minWidth:10,cellTemplate:"ui-grid/treeBaseRowHeader",headerCellTemplate:"ui-grid/treeBaseHeaderCell",enableColumnResizing:!1,enableColumnMenu:!1,exporterSuppressExport:!0,allowCellFocus:!0};t.visible=e.options.treeRowHeaderAlwaysVisible,e.addRowHeaderColumn(t,-100)},expandAllRows:function(t){t.treeBase.tree.forEach(function(e){g.setAllNodes(t,e,l.EXPANDED)}),t.treeBase.expandAll=!0,t.queueGridRefresh()},collapseAllRows:function(t){t.treeBase.tree.forEach(function(e){g.setAllNodes(t,e,l.COLLAPSED)}),t.treeBase.expandAll=!1,t.queueGridRefresh()},setAllNodes:function(t,e,r){void 0!==e.state&&e.state!==r&&((e.state=r)===l.EXPANDED?t.api.treeBase.raise.rowExpanded(e.row):t.api.treeBase.raise.rowCollapsed(e.row)),e.children&&e.children.forEach(function(e){g.setAllNodes(t,e,r)})},toggleRowTreeState:function(e,t){void 0===t.treeLevel||null===t.treeLevel||t.treeLevel<0||(t.treeNode.state===l.EXPANDED?g.collapseRow(e,t):g.expandRow(e,t,!1),e.queueGridRefresh())},expandRow:function(e,t,r){if(r){for(var n=[];t&&void 0!==t.treeLevel&&null!==t.treeLevel&&0<=t.treeLevel&&t.treeNode.state!==l.EXPANDED;)n.push(t),t=t.treeNode.parentRow;if(0e.value||null===e.value)&&(e.value=t)}},avg:{label:o.get().aggregation.avg,menuTitle:o.get().grouping.aggregate_avg,aggregationFn:function(e,t,r){void 0===e.count?e.count=1:e.count++,isNaN(r)||(void 0===e.value||void 0===e.sum?(e.value=r,e.sum=r):(e.sum+=r,e.value=e.sum/e.count))}}}},finaliseAggregation:function(e,t){t.col.treeAggregationUpdateEntity&&void 0!==e&&void 0!==e.entity["$$"+t.col.uid]&&angular.extend(t,e.entity["$$"+t.col.uid]),"function"==typeof t.col.treeAggregationFinalizerFn&&t.col.treeAggregationFinalizerFn(t),"function"==typeof t.col.customTreeAggregationFinalizerFn&&t.col.customTreeAggregationFinalizerFn(t),void 0===t.rendered&&(t.rendered=t.label?t.label+t.value:t.value)},finaliseAggregations:function(e){null!=e&&void 0!==e.treeNode.aggregations&&e.treeNode.aggregations.forEach(function(r){if(g.finaliseAggregation(e,r),r.col.treeAggregationUpdateEntity){var n={};angular.forEach(r,function(e,t){r.hasOwnProperty(t)&&"col"!==t&&(n[t]=e)}),e.entity["$$"+r.col.uid]=n}})},treeFooterAggregationType:function(e,t){return g.finaliseAggregation(void 0,t.treeFooterAggregation),void 0===t.treeFooterAggregation.value||null===t.treeFooterAggregation.rendered?"":t.treeFooterAggregation.rendered}};return g}]),e.directive("uiGridTreeBaseRowHeaderButtons",["$templateCache","uiGridTreeBaseService",function(e,a){return{replace:!0,restrict:"E",template:e.get("ui-grid/treeBaseRowHeaderButtons"),scope:!0,require:"^uiGrid",link:function(r,e,t,n){var o=n.grid;r.treeButtonClass=function(e){if(o.options.showTreeExpandNoChildren&&-1 -1}":"{'ui-grid-tree-header-row': row.treeLevel > -1}",t.attr("ng-class",n),{pre:function(e,t,r,n){},post:function(e,t,r,n){}}}}})}(),angular.module("ui.grid.treeBase").run(["$templateCache",function(e){"use strict";e.put("ui-grid/treeBaseExpandAllButtons",'
    '),e.put("ui-grid/treeBaseHeaderCell",'
    '),e.put("ui-grid/treeBaseRowHeader",'
    '),e.put("ui-grid/treeBaseRowHeaderButtons",'
     
    ')}]); \ No newline at end of file diff --git a/src/features/tree-view/js/tree-view.js b/src/i18n/ui-grid.tree-view.js similarity index 96% rename from src/features/tree-view/js/tree-view.js rename to src/i18n/ui-grid.tree-view.js index 97386bdc9e..852017f4bd 100644 --- a/src/features/tree-view/js/tree-view.js +++ b/src/i18n/ui-grid.tree-view.js @@ -1,3 +1,8 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; @@ -99,7 +104,7 @@ }, defaultGridOptions: function (gridOptions) { - //default option to true unless it was explicitly set to false + // default option to true unless it was explicitly set to false /** * @ngdoc object * @name ui.grid.treeView.api:GridOptions @@ -141,19 +146,17 @@ adjustSorting: function( renderableRows ) { var grid = this; - grid.columns.forEach( function( column ){ - if ( column.sort ){ + grid.columns.forEach( function( column ) { + if ( column.sort ) { column.sort.ignoreSort = true; } }); return renderableRows; } - }; return service; - }]); /** @@ -200,7 +203,7 @@ compile: function () { return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { - if (uiGridCtrl.grid.options.enableTreeView !== false){ + if (uiGridCtrl.grid.options.enableTreeView !== false) { uiGridTreeViewService.initializeGrid(uiGridCtrl.grid, $scope); } }, diff --git a/src/i18n/ui-grid.tree-view.min.js b/src/i18n/ui-grid.tree-view.min.js new file mode 100644 index 0000000000..8b5b1905b8 --- /dev/null +++ b/src/i18n/ui-grid.tree-view.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.treeView",["ui.grid","ui.grid.treeBase"]);e.constant("uiGridTreeViewConstants",{featureName:"treeView",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),e.service("uiGridTreeViewService",["$q","uiGridTreeViewConstants","uiGridTreeBaseConstants","uiGridTreeBaseService","gridUtil","GridRow","gridClassFactory","i18nService","uiGridConstants",function(e,i,r,n,t,o,a,s,u){var d={initializeGrid:function(e,i){n.initializeGrid(e,i),e.treeView={},e.registerRowsProcessor(d.adjustSorting,60);var r={treeView:{}},t={treeView:{}};e.api.registerEventsFromObject(r),e.api.registerMethodsFromObject(t)},defaultGridOptions:function(e){e.enableTreeView=!1!==e.enableTreeView},adjustSorting:function(e){return this.columns.forEach(function(e){e.sort&&(e.sort.ignoreSort=!0)}),e}};return d}]),e.directive("uiGridTreeView",["uiGridTreeViewConstants","uiGridTreeViewService","$templateCache",function(e,n,i){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,r,t){!1!==t.grid.options.enableTreeView&&n.initializeGrid(t.grid,e)},post:function(e,i,r,t){}}}}}])}(); \ No newline at end of file diff --git a/src/features/validate/js/gridValidate.js b/src/i18n/ui-grid.validate.js similarity index 86% rename from src/features/validate/js/gridValidate.js rename to src/i18n/ui-grid.validate.js index 1de69cbe16..db493b5613 100644 --- a/src/features/validate/js/gridValidate.js +++ b/src/i18n/ui-grid.validate.js @@ -1,6 +1,11 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + (function () { 'use strict'; - + /** * @ngdoc overview * @name ui.grid.validate @@ -16,7 +21,7 @@ * ------------------- * * Validation is not based on angularjs validation, since it would work only when editing the field. - * + * * Instead it adds custom properties to any field considered as invalid. * *
    @@ -24,10 +29,8 @@ * *
    */ - var module = angular.module('ui.grid.validate', ['ui.grid']); - - + /** * @ngdoc service * @name ui.grid.validate.service:uiGridValidateService @@ -37,7 +40,7 @@ module.service('uiGridValidateService', ['$sce', '$q', '$http', 'i18nService', 'uiGridConstants', function ($sce, $q, $http, i18nService, uiGridConstants) { var service = { - + /** * @ngdoc object * @name validatorFactories @@ -61,7 +64,6 @@ */ validatorFactories: {}, - /** * @ngdoc service * @name setExternalFactoryFunction @@ -70,13 +72,13 @@ *

    Validators from this external service have a higher priority than default * ones * @param {function} externalFactoryFunction a function that accepts name and argument to pass to a - * validator factory and that returns an object with the same properties as + * validator factory and that returns an object with the same properties as * you can see in {@link ui.grid.validate.service:uiGridValidateService#properties_validatorFactories validatorFactories} */ setExternalFactoryFunction: function(externalFactoryFunction) { service.externalFactoryFunction = externalFactoryFunction; }, - + /** * @ngdoc service * @name clearExternalFactory @@ -99,7 +101,7 @@ getValidatorFromExternalFactory: function(name, argument) { return service.externalFactoryFunction(name, argument).validatorFactory(argument); }, - + /** * @ngdoc service * @name getMessageFromExternalFactory @@ -111,7 +113,7 @@ getMessageFromExternalFactory: function(name, argument) { return service.externalFactoryFunction(name, argument).messageFunction(argument); }, - + /** * @ngdoc service * @name setValidator @@ -155,7 +157,7 @@ * @ngdoc service * @name getMessage * @methodOf ui.grid.validate.service:uiGridValidateService - * @description Returns the error message related to the validator + * @description Returns the error message related to the validator * @param {string} name the name of the validator * @param {object} argument an argument to pass to the message function * @returns {string} the error message related to the validator @@ -174,7 +176,7 @@ * @ngdoc service * @name isInvalid * @methodOf ui.grid.validate.service:uiGridValidateService - * @description Returns true if the cell (identified by rowEntity, colDef) is invalid + * @description Returns true if the cell (identified by rowEntity, colDef) is invalid * @param {object} rowEntity the row entity of the cell * @param {object} colDef the colDef of the cell * @returns {boolean} true if the cell is invalid @@ -194,7 +196,7 @@ setInvalid: function (rowEntity, colDef) { rowEntity['$$invalid'+colDef.name] = true; }, - + /** * @ngdoc service * @name setValid @@ -240,7 +242,7 @@ delete rowEntity['$$errors'+colDef.name][validatorName]; } }, - + /** * @ngdoc function * @name getErrorMessages @@ -260,10 +262,10 @@ Object.keys(rowEntity['$$errors'+colDef.name]).sort().forEach(function(validatorName) { errors.push(service.getMessage(validatorName, colDef.validators[validatorName])); }); - + return errors; }, - + /** * @ngdoc function * @name getFormattedErrors @@ -275,15 +277,13 @@ * message inside the page (i.e. inside a div) */ getFormattedErrors: function(rowEntity, colDef) { + var msgString = "", + errors = service.getErrorMessages(rowEntity, colDef); - var msgString = ""; - - var errors = service.getErrorMessages(rowEntity, colDef); - if (!errors.length) { return; } - + errors.forEach(function(errorMsg) { msgString += errorMsg + "
    "; }); @@ -295,7 +295,7 @@ * @ngdoc function * @name getTitleFormattedErrors * @methodOf ui.grid.validate.service:uiGridValidateService - * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html + * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html * title attribute. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for * @param {object} colDef the column whose errors we are looking for @@ -303,17 +303,14 @@ * message inside an html title attribute */ getTitleFormattedErrors: function(rowEntity, colDef) { + var newLine = "\n", + msgString = "", + errors = service.getErrorMessages(rowEntity, colDef); - var newLine = "\n"; - - var msgString = ""; - - var errors = service.getErrorMessages(rowEntity, colDef); - if (!errors.length) { return; } - + errors.forEach(function(errorMsg) { msgString += errorMsg + newLine; }); @@ -332,18 +329,17 @@ * @param {object} oldValue the value the field had before */ runValidators: function(rowEntity, colDef, newValue, oldValue, grid) { - if (newValue === oldValue) { // If the value has not changed we perform no validation return; } - + if (typeof(colDef.name) === 'undefined' || !colDef.name) { throw new Error('colDef.name is required to perform validation'); } - + service.setValid(rowEntity, colDef); - + var validateClosureFactory = function(rowEntity, colDef, validatorName) { return function(value) { if (!value) { @@ -360,16 +356,16 @@ for (var validatorName in colDef.validators) { service.clearError(rowEntity, colDef, validatorName); - var msg; var validatorFunction = service.getValidator(validatorName, colDef.validators[validatorName]); - // We pass the arguments as oldValue, newValue so they are in the same order + + // We pass the arguments as oldValue, newValue so they are in the same order // as ng-model validators (modelValue, viewValue) - var promise = $q - .when(validatorFunction(oldValue, newValue, rowEntity, colDef)) - .then(validateClosureFactory(rowEntity, colDef, validatorName)); + var promise = $q.when(validatorFunction(oldValue, newValue, rowEntity, colDef)) + .then(validateClosureFactory(rowEntity, colDef, validatorName)); + promises.push(promise); } - + return $q.all(promises); }, @@ -380,58 +376,54 @@ * @description adds the basic validators to the list of service validators */ createDefaultValidators: function() { - service.setValidator('minLength', - function (argument) { - return function (oldValue, newValue, rowEntity, colDef) { - if (newValue === undefined || newValue === null || newValue === '') { - return true; - } - return newValue.length >= argument; - }; - }, - function(argument) { - return i18nService.getSafeText('validate.minLength').replace('THRESHOLD', argument); - }); - - service.setValidator('maxLength', - function (argument) { - return function (oldValue, newValue, rowEntity, colDef) { - if (newValue === undefined || newValue === null || newValue === '') { - return true; - } - return newValue.length <= argument; - }; - }, - function(threshold) { - return i18nService.getSafeText('validate.maxLength').replace('THRESHOLD', threshold); - }); - - service.setValidator('required', - function (argument) { - return function (oldValue, newValue, rowEntity, colDef) { - if (argument) { - return !(newValue === undefined || newValue === null || newValue === ''); - } - return true; - }; - }, - function(argument) { - return i18nService.getSafeText('validate.required'); - }); + service.setValidator('minLength', function (argument) { + return function (oldValue, newValue) { + if (newValue === undefined || newValue === null || newValue === '') { + return true; + } + return newValue.length >= argument; + }; + }, function(argument) { + return i18nService.getSafeText('validate.minLength').replace('THRESHOLD', argument); + }); + + service.setValidator('maxLength', function (argument) { + return function (oldValue, newValue) { + if (newValue === undefined || newValue === null || newValue === '') { + return true; + } + return newValue.length <= argument; + }; + }, function(threshold) { + return i18nService.getSafeText('validate.maxLength').replace('THRESHOLD', threshold); + }); + + service.setValidator('required', function (argument) { + return function (oldValue, newValue) { + if (argument) { + return !(newValue === undefined || newValue === null || newValue === ''); + } + return true; + }; + }, function() { + return i18nService.getSafeText('validate.required'); + }); }, initializeGrid: function (scope, grid) { grid.validate = { - + isInvalid: service.isInvalid, + getErrorMessages: service.getErrorMessages, + getFormattedErrors: service.getFormattedErrors, - + getTitleFormattedErrors: service.getTitleFormattedErrors, runValidators: service.runValidators }; - + /** * @ngdoc object * @name ui.grid.validate.api:PublicApi @@ -444,8 +436,8 @@ /** * @ngdoc event * @name validationFailed - * @eventOf ui.grid.validate.api:PublicApi - * @description raised when one or more failure happened during validation + * @eventOf ui.grid.validate.api:PublicApi + * @description raised when one or more failure happened during validation *

                    *      gridApi.validate.on.validationFailed(scope, function(rowEntity, colDef, newValue, oldValue){...})
                    * 
    @@ -463,7 +455,7 @@ /** * @ngdoc function * @name isInvalid - * @methodOf ui.grid.validate.api:PublicApi + * @methodOf ui.grid.validate.api:PublicApi * @description checks if a cell (identified by rowEntity, colDef) is invalid * @param {object} rowEntity gridOptions.data[] array instance we want to check * @param {object} colDef the column whose errors we want to check @@ -475,7 +467,7 @@ /** * @ngdoc function * @name getErrorMessages - * @methodOf ui.grid.validate.api:PublicApi + * @methodOf ui.grid.validate.api:PublicApi * @description returns an array of i18n-ed error messages. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for * @param {object} colDef the column whose errors we are looking for @@ -487,7 +479,7 @@ /** * @ngdoc function * @name getFormattedErrors - * @methodOf ui.grid.validate.api:PublicApi + * @methodOf ui.grid.validate.api:PublicApi * @description returns the error i18n-ed and formatted in html to be shown inside the page. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for * @param {object} colDef the column whose errors we are looking for @@ -500,8 +492,8 @@ /** * @ngdoc function * @name getTitleFormattedErrors - * @methodOf ui.grid.validate.api:PublicApi - * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html + * @methodOf ui.grid.validate.api:PublicApi + * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html * title attribute. * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for * @param {object} colDef the column whose errors we are looking for @@ -511,10 +503,10 @@ getTitleFormattedErrors: function (rowEntity, colDef) { return grid.validate.getTitleFormattedErrors(rowEntity, colDef); } - } + } } }; - + grid.api.registerEventsFromObject(publicApi.events); grid.api.registerMethodsFromObject(publicApi.methods); @@ -526,13 +518,11 @@ service.createDefaultValidators(); } - }; - + return service; }]); - - + /** * @ngdoc directive * @name ui.grid.validate.directive:uiGridValidate @@ -582,3 +572,17 @@ }; }]); })(); + +angular.module('ui.grid.validate').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/cellTitleValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/cellTooltipValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + +}]); diff --git a/src/i18n/ui-grid.validate.min.js b/src/i18n/ui-grid.validate.min.js new file mode 100644 index 0000000000..3ecae4f725 --- /dev/null +++ b/src/i18n/ui-grid.validate.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var t=angular.module("ui.grid.validate",["ui.grid"]);t.service("uiGridValidateService",["$sce","$q","$http","i18nService","uiGridConstants",function(i,c,t,n,r){var u={validatorFactories:{},setExternalFactoryFunction:function(t){u.externalFactoryFunction=t},clearExternalFactory:function(){delete u.externalFactoryFunction},getValidatorFromExternalFactory:function(t,r){return u.externalFactoryFunction(t,r).validatorFactory(r)},getMessageFromExternalFactory:function(t,r){return u.externalFactoryFunction(t,r).messageFunction(r)},setValidator:function(t,r,e){u.validatorFactories[t]={validatorFactory:r,messageFunction:e}},getValidator:function(t,r){if(u.externalFactoryFunction){var e=u.getValidatorFromExternalFactory(t,r);if(e)return e}if(!u.validatorFactories[t])throw"Invalid validator name: "+t;return u.validatorFactories[t].validatorFactory(r)},getMessage:function(t,r){if(u.externalFactoryFunction){var e=u.getMessageFromExternalFactory(t,r);if(e)return e}return u.validatorFactories[t].messageFunction(r)},isInvalid:function(t,r){return t["$$invalid"+r.name]},setInvalid:function(t,r){t["$$invalid"+r.name]=!0},setValid:function(t,r){delete t["$$invalid"+r.name]},setError:function(t,r,e){t["$$errors"+r.name]||(t["$$errors"+r.name]={}),t["$$errors"+r.name][e]=!0},clearError:function(t,r,e){t["$$errors"+r.name]&&e in t["$$errors"+r.name]&&delete t["$$errors"+r.name][e]},getErrorMessages:function(t,r){var e=[];return t["$$errors"+r.name]&&0!==Object.keys(t["$$errors"+r.name]).length&&Object.keys(t["$$errors"+r.name]).sort().forEach(function(t){e.push(u.getMessage(t,r.validators[t]))}),e},getFormattedErrors:function(t,r){var e="",a=u.getErrorMessages(t,r);if(a.length)return a.forEach(function(t){e+=t+"
    "}),i.trustAsHtml("

    "+n.getSafeText("validate.error")+"

    "+e)},getTitleFormattedErrors:function(t,r){var e="",a=u.getErrorMessages(t,r);if(a.length)return a.forEach(function(t){e+=t+"\n"}),i.trustAsHtml(n.getSafeText("validate.error")+"\n"+e)},runValidators:function(t,r,i,n,o){if(i!==n){if(void 0===r.name||!r.name)throw new Error("colDef.name is required to perform validation");u.setValid(t,r);var e=function(r,e,a){return function(t){t||(u.setInvalid(r,e),u.setError(r,e,a),o&&o.api.validate.raise.validationFailed(r,e,i,n))}},a=[];for(var l in r.validators){u.clearError(t,r,l);var d=u.getValidator(l,r.validators[l]),s=c.when(d(n,i,t,r)).then(e(t,r,l));a.push(s)}return c.all(a)}},createDefaultValidators:function(){u.setValidator("minLength",function(e){return function(t,r){return null==r||""===r||r.length>=e}},function(t){return n.getSafeText("validate.minLength").replace("THRESHOLD",t)}),u.setValidator("maxLength",function(e){return function(t,r){return null==r||""===r||r.length<=e}},function(t){return n.getSafeText("validate.maxLength").replace("THRESHOLD",t)}),u.setValidator("required",function(e){return function(t,r){return!e||!(null==r||""===r)}},function(){return n.getSafeText("validate.required")})},initializeGrid:function(t,i){i.validate={isInvalid:u.isInvalid,getErrorMessages:u.getErrorMessages,getFormattedErrors:u.getFormattedErrors,getTitleFormattedErrors:u.getTitleFormattedErrors,runValidators:u.runValidators};var r={events:{validate:{validationFailed:function(t,r,e,a){}}},methods:{validate:{isInvalid:function(t,r){return i.validate.isInvalid(t,r)},getErrorMessages:function(t,r){return i.validate.getErrorMessages(t,r)},getFormattedErrors:function(t,r){return i.validate.getFormattedErrors(t,r)},getTitleFormattedErrors:function(t,r){return i.validate.getTitleFormattedErrors(t,r)}}}};i.api.registerEventsFromObject(r.events),i.api.registerMethodsFromObject(r.methods),i.edit&&i.api.edit.on.afterCellEdit(t,function(t,r,e,a){i.validate.runValidators(t,r,e,a,i)}),u.createDefaultValidators()}};return u}]),t.directive("uiGridValidate",["gridUtil","uiGridValidateService",function(t,i){return{priority:0,replace:!0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(t,r,e,a){i.initializeGrid(t,a.grid)},post:function(t,r,e,a){}}}}}])}(),angular.module("ui.grid.validate").run(["$templateCache",function(t){"use strict";t.put("ui-grid/cellTitleValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),t.put("ui-grid/cellTooltipValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    ')}]); \ No newline at end of file diff --git a/src/img/arrow.colors-default.svg b/src/img/arrow.colors-default.svg deleted file mode 100644 index eec64baabc..0000000000 --- a/src/img/arrow.colors-default.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/src/js/core/bootstrap.js b/src/js/core/bootstrap.js deleted file mode 100644 index 38dc8aad85..0000000000 --- a/src/js/core/bootstrap.js +++ /dev/null @@ -1,5 +0,0 @@ -(function () { - 'use strict'; - angular.module('ui.grid.i18n', []); - angular.module('ui.grid', ['ui.grid.i18n']); -})(); \ No newline at end of file diff --git a/src/js/core/constants.js b/src/js/core/constants.js deleted file mode 100644 index 89b8aa3442..0000000000 --- a/src/js/core/constants.js +++ /dev/null @@ -1,239 +0,0 @@ -(function () { - 'use strict'; - - /** - * @ngdoc object - * @name ui.grid.service:uiGridConstants - * @description Constants for use across many grid features - * - */ - - - angular.module('ui.grid').constant('uiGridConstants', { - LOG_DEBUG_MESSAGES: true, - LOG_WARN_MESSAGES: true, - LOG_ERROR_MESSAGES: true, - CUSTOM_FILTERS: /CUSTOM_FILTERS/g, - COL_FIELD: /COL_FIELD/g, - MODEL_COL_FIELD: /MODEL_COL_FIELD/g, - TOOLTIP: /title=\"TOOLTIP\"/g, - DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g, - TEMPLATE_REGEXP: /<.+>/, - FUNC_REGEXP: /(\([^)]*\))?$/, - DOT_REGEXP: /\./g, - APOS_REGEXP: /'/g, - BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/, - COL_CLASS_PREFIX: 'ui-grid-col', - ENTITY_BINDING: '$$this', - events: { - GRID_SCROLL: 'uiGridScroll', - COLUMN_MENU_SHOWN: 'uiGridColMenuShown', - ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged - COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick' - }, - // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html - keymap: { - TAB: 9, - STRG: 17, - CAPSLOCK: 20, - CTRL: 17, - CTRLRIGHT: 18, - CTRLR: 18, - SHIFT: 16, - RETURN: 13, - ENTER: 13, - BACKSPACE: 8, - BCKSP: 8, - ALT: 18, - ALTR: 17, - ALTRIGHT: 17, - SPACE: 32, - WIN: 91, - MAC: 91, - FN: null, - PG_UP: 33, - PG_DOWN: 34, - UP: 38, - DOWN: 40, - LEFT: 37, - RIGHT: 39, - ESC: 27, - DEL: 46, - F1: 112, - F2: 113, - F3: 114, - F4: 115, - F5: 116, - F6: 117, - F7: 118, - F8: 119, - F9: 120, - F10: 121, - F11: 122, - F12: 123 - }, - /** - * @ngdoc object - * @name ASC - * @propertyOf ui.grid.service:uiGridConstants - * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and - * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} - * to configure the sorting direction of the column - */ - ASC: 'asc', - /** - * @ngdoc object - * @name DESC - * @propertyOf ui.grid.service:uiGridConstants - * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and - * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} - * to configure the sorting direction of the column - */ - DESC: 'desc', - - - /** - * @ngdoc object - * @name filter - * @propertyOf ui.grid.service:uiGridConstants - * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter} - * to configure filtering on the column - * - * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify - * one of the built-in conditions. - * - * Available `condition` options are: - * - `uiGridConstants.filter.STARTS_WITH` - * - `uiGridConstants.filter.ENDS_WITH` - * - `uiGridConstants.filter.CONTAINS` - * - `uiGridConstants.filter.GREATER_THAN` - * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL` - * - `uiGridConstants.filter.LESS_THAN` - * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL` - * - `uiGridConstants.filter.NOT_EQUAL` - * - * - * Available `type` options are: - * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field - * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field - */ - filter: { - STARTS_WITH: 2, - ENDS_WITH: 4, - EXACT: 8, - CONTAINS: 16, - GREATER_THAN: 32, - GREATER_THAN_OR_EQUAL: 64, - LESS_THAN: 128, - LESS_THAN_OR_EQUAL: 256, - NOT_EQUAL: 512, - SELECT: 'select', - INPUT: 'input' - }, - - /** - * @ngdoc object - * @name aggregationTypes - * @propertyOf ui.grid.service:uiGridConstants - * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType} - * to specify the type of built-in aggregation the column should use. - * - * Available options are: - * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value - * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value - * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value - * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value - * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value - */ - aggregationTypes: { - sum: 2, - count: 4, - avg: 8, - min: 16, - max: 32 - }, - - /** - * @ngdoc array - * @name CURRENCY_SYMBOLS - * @propertyOf ui.grid.service:uiGridConstants - * @description A list of all presently circulating currency symbols that was copied from - * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols - * - * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols. - */ - CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден', - 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu', - 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв', - 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q', - 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/', - 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'], - - /** - * @ngdoc object - * @name scrollDirection - * @propertyOf ui.grid.service:uiGridConstants - * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection}, - * to indicate the direction the grid is currently scrolling in - * - * Available options are: - * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up - * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down - * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left - * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right - * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default - */ - scrollDirection: { - UP: 'up', - DOWN: 'down', - LEFT: 'left', - RIGHT: 'right', - NONE: 'none' - - }, - - /** - * @ngdoc object - * @name dataChange - * @propertyOf ui.grid.service:uiGridConstants - * @description Used with {@link ui.grid.core.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange}, - * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks}, - * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback} - * to specify the type of the event(s). - * - * Available options are: - * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events. - * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited - * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed - * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified - * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified - */ - dataChange: { - ALL: 'all', - EDIT: 'edit', - ROW: 'row', - COLUMN: 'column', - OPTIONS: 'options' - }, - - /** - * @ngdoc object - * @name scrollbars - * @propertyOf ui.grid.service:uiGridConstants - * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar} - * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar} - * to specify the scrollbar policy for that direction. - * - * Available options are: - * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction - * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction - */ - - scrollbars: { - NEVER: 0, - ALWAYS: 1 - //WHEN_NEEDED: 2 - } - }); - -})(); diff --git a/src/js/core/directives/ui-grid-cell.js b/src/js/core/directives/ui-grid-cell.js deleted file mode 100644 index 50c69a0a6e..0000000000 --- a/src/js/core/directives/ui-grid-cell.js +++ /dev/null @@ -1,111 +0,0 @@ -angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) { - var uiGridCell = { - priority: 0, - scope: false, - require: '?^uiGrid', - compile: function() { - return { - pre: function($scope, $elm, $attrs, uiGridCtrl) { - function compileTemplate() { - var compiledElementFn = $scope.col.compiledElementFn; - - compiledElementFn($scope, function(clonedElement, scope) { - $elm.append(clonedElement); - }); - } - - // If the grid controller is present, use it to get the compiled cell template function - if (uiGridCtrl && $scope.col.compiledElementFn) { - compileTemplate(); - } - // No controller, compile the element manually (for unit tests) - else { - if ( uiGridCtrl && !$scope.col.compiledElementFn ){ - // gridUtil.logError('Render has been called before precompile. Please log a ui-grid issue'); - - $scope.col.getCompiledElementFn() - .then(function (compiledElementFn) { - compiledElementFn($scope, function(clonedElement, scope) { - $elm.append(clonedElement); - }); - }).catch(angular.noop); - } - else { - var html = $scope.col.cellTemplate - .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field)) - .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); - - var cellElement = $compile(html)($scope); - $elm.append(cellElement); - } - } - }, - post: function($scope, $elm, $attrs, uiGridCtrl) { - var initColClass = $scope.col.getColClass(false); - $elm.addClass(initColClass); - - var classAdded; - var updateClass = function( grid ){ - var contents = $elm; - if ( classAdded ){ - contents.removeClass( classAdded ); - classAdded = null; - } - - if (angular.isFunction($scope.col.cellClass)) { - classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); - } - else { - classAdded = $scope.col.cellClass; - } - contents.addClass(classAdded); - }; - - if ($scope.col.cellClass) { - updateClass(); - } - - // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs - var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]); - - // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise - // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things - var cellChangeFunction = function( n, o ){ - if ( n !== o ) { - if ( classAdded || $scope.col.cellClass ){ - updateClass(); - } - - // See if the column's internal class has changed - var newColClass = $scope.col.getColClass(false); - if (newColClass !== initColClass) { - $elm.removeClass(initColClass); - $elm.addClass(newColClass); - initColClass = newColClass; - } - } - }; - - // TODO(c0bra): Turn this into a deep array watch -/* shouldn't be needed any more given track by col.name - var colWatchDereg = $scope.$watch( 'col', cellChangeFunction ); -*/ - var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction ); - - - var deregisterFunction = function() { - dataChangeDereg(); -// colWatchDereg(); - rowWatchDereg(); - }; - - $scope.$on( '$destroy', deregisterFunction ); - $elm.on( '$destroy', deregisterFunction ); - } - }; - } - }; - - return uiGridCell; -}]); - diff --git a/src/js/core/directives/ui-grid-column-menu.js b/src/js/core/directives/ui-grid-column-menu.js deleted file mode 100644 index f7f51e5ee7..0000000000 --- a/src/js/core/directives/ui-grid-column-menu.js +++ /dev/null @@ -1,524 +0,0 @@ -(function(){ - -angular.module('ui.grid') -.service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil', -function ( i18nService, uiGridConstants, gridUtil ) { -/** - * @ngdoc service - * @name ui.grid.service:uiGridColumnMenuService - * - * @description Services for working with column menus, factored out - * to make the code easier to understand - */ - - var service = { - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name initialize - * @description Sets defaults, puts a reference to the $scope on - * the uiGridController - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * @param {controller} uiGridCtrl the uiGridController for the grid - * we're on - * - */ - initialize: function( $scope, uiGridCtrl ){ - $scope.grid = uiGridCtrl.grid; - - // Store a reference to this link/controller in the main uiGrid controller - // to allow showMenu later - uiGridCtrl.columnMenuScope = $scope; - - // Save whether we're shown or not so the columns can check - $scope.menuShown = false; - }, - - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name setColMenuItemWatch - * @description Setup a watch on $scope.col.menuItems, and update - * menuItems based on this. $scope.col needs to be set by the column - * before calling the menu. - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * @param {controller} uiGridCtrl the uiGridController for the grid - * we're on - * - */ - setColMenuItemWatch: function ( $scope ){ - var deregFunction = $scope.$watch('col.menuItems', function (n) { - if (typeof(n) !== 'undefined' && n && angular.isArray(n)) { - n.forEach(function (item) { - if (typeof(item.context) === 'undefined' || !item.context) { - item.context = {}; - } - item.context.col = $scope.col; - }); - - $scope.menuItems = $scope.defaultMenuItems.concat(n); - } - else { - $scope.menuItems = $scope.defaultMenuItems; - } - }); - - $scope.$on( '$destroy', deregFunction ); - }, - - - /** - * @ngdoc boolean - * @name enableSorting - * @propertyOf ui.grid.class:GridOptions.columnDef - * @description (optional) True by default. When enabled, this setting adds sort - * widgets to the column header, allowing sorting of the data in the individual column. - */ - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name sortable - * @description determines whether this column is sortable - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * - */ - sortable: function( $scope ) { - if ( $scope.grid.options.enableSorting && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting) { - return true; - } - else { - return false; - } - }, - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name isActiveSort - * @description determines whether the requested sort direction is current active, to - * allow highlighting in the menu - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * @param {string} direction the direction that we'd have selected for us to be active - * - */ - isActiveSort: function( $scope, direction ){ - return (typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' && - typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction); - - }, - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name suppressRemoveSort - * @description determines whether we should suppress the removeSort option - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * - */ - suppressRemoveSort: function( $scope ) { - if ($scope.col && $scope.col.suppressRemoveSort) { - return true; - } - else { - return false; - } - }, - - - /** - * @ngdoc boolean - * @name enableHiding - * @propertyOf ui.grid.class:GridOptions.columnDef - * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column - * using the column menu or the grid menu. - */ - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name hideable - * @description determines whether a column can be hidden, by checking the enableHiding columnDef option - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * - */ - hideable: function( $scope ) { - if (typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding === false ) { - return false; - } - else { - return true; - } - }, - - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name getDefaultMenuItems - * @description returns the default menu items for a column menu - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * - */ - getDefaultMenuItems: function( $scope ){ - return [ - { - title: function(){return i18nService.getSafeText('sort.ascending');}, - icon: 'ui-grid-icon-sort-alt-up', - action: function($event) { - $event.stopPropagation(); - $scope.sortColumn($event, uiGridConstants.ASC); - }, - shown: function () { - return service.sortable( $scope ); - }, - active: function() { - return service.isActiveSort( $scope, uiGridConstants.ASC); - } - }, - { - title: function(){return i18nService.getSafeText('sort.descending');}, - icon: 'ui-grid-icon-sort-alt-down', - action: function($event) { - $event.stopPropagation(); - $scope.sortColumn($event, uiGridConstants.DESC); - }, - shown: function() { - return service.sortable( $scope ); - }, - active: function() { - return service.isActiveSort( $scope, uiGridConstants.DESC); - } - }, - { - title: function(){return i18nService.getSafeText('sort.remove');}, - icon: 'ui-grid-icon-cancel', - action: function ($event) { - $event.stopPropagation(); - $scope.unsortColumn(); - }, - shown: function() { - return service.sortable( $scope ) && - typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' && - typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null && - !service.suppressRemoveSort( $scope ); - } - }, - { - title: function(){return i18nService.getSafeText('column.hide');}, - icon: 'ui-grid-icon-cancel', - shown: function() { - return service.hideable( $scope ); - }, - action: function ($event) { - $event.stopPropagation(); - $scope.hideColumn(); - } - } - ]; - }, - - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name getColumnElementPosition - * @description gets the position information needed to place the column - * menu below the column header - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * @param {GridCol} column the column we want to position below - * @param {element} $columnElement the column element we want to position below - * @returns {hash} containing left, top, offset, height, width - * - */ - getColumnElementPosition: function( $scope, column, $columnElement ){ - var positionData = {}; - positionData.left = $columnElement[0].offsetLeft; - positionData.top = $columnElement[0].offsetTop; - positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft; - - // Get the grid scrollLeft - positionData.offset = 0; - if (column.grid.options.offsetLeft) { - positionData.offset = column.grid.options.offsetLeft; - } - - positionData.height = gridUtil.elementHeight($columnElement, true); - positionData.width = gridUtil.elementWidth($columnElement, true); - - return positionData; - }, - - - /** - * @ngdoc method - * @methodOf ui.grid.service:uiGridColumnMenuService - * @name repositionMenu - * @description Reposition the menu below the new column. If the menu has no child nodes - * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again - * later to fix it - * @param {$scope} $scope the $scope from the uiGridColumnMenu - * @param {GridCol} column the column we want to position below - * @param {hash} positionData a hash containing left, top, offset, height, width - * @param {element} $elm the column menu element that we want to reposition - * @param {element} $columnElement the column element that we want to reposition underneath - * - */ - repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) { - var menu = $elm[0].querySelectorAll('.ui-grid-menu'); - - // It's possible that the render container of the column we're attaching to is - // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft - // between the render container and the grid - var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container'); - var renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left; - - var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft; - - // default value the last width for _this_ column, otherwise last width for _any_ column, otherwise default to 170 - var myWidth = column.lastMenuWidth ? column.lastMenuWidth : ( $scope.lastMenuWidth ? $scope.lastMenuWidth : 170); - var paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10); - - if ( menu.length !== 0 ){ - var mid = menu[0].querySelectorAll('.ui-grid-menu-mid'); - if ( mid.length !== 0 && !angular.element(mid).hasClass('ng-hide') ) { - myWidth = gridUtil.elementWidth(menu, true); - $scope.lastMenuWidth = myWidth; - column.lastMenuWidth = myWidth; - - // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side - // Get the column menu right padding - paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10); - $scope.lastMenuPaddingRight = paddingRight; - column.lastMenuPaddingRight = paddingRight; - } - } - - var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width - myWidth + paddingRight; - if (left < positionData.offset){ - left = positionData.offset; - } - - $elm.css('left', left + 'px'); - $elm.css('top', (positionData.top + positionData.height) + 'px'); - } - - }; - - return service; -}]) - - -.directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document', -function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) { -/** - * @ngdoc directive - * @name ui.grid.directive:uiGridColumnMenu - * @description Provides the column menu framework, leverages uiGridMenu underneath - * - */ - - var uiGridColumnMenu = { - priority: 0, - scope: true, - require: '^uiGrid', - templateUrl: 'ui-grid/uiGridColumnMenu', - replace: true, - link: function ($scope, $elm, $attrs, uiGridCtrl) { - uiGridColumnMenuService.initialize( $scope, uiGridCtrl ); - - $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope ); - - // Set the menu items for use with the column menu. The user can later add additional items via the watch - $scope.menuItems = $scope.defaultMenuItems; - uiGridColumnMenuService.setColMenuItemWatch( $scope ); - - - /** - * @ngdoc method - * @methodOf ui.grid.directive:uiGridColumnMenu - * @name showMenu - * @description Shows the column menu. If the menu is already displayed it - * calls the menu to ask it to hide (it will animate), then it repositions the menu - * to the right place whilst hidden (it will make an assumption on menu width), - * then it asks the menu to show (it will animate), then it repositions the menu again - * once we can calculate it's size. - * @param {GridCol} column the column we want to position below - * @param {element} $columnElement the column element we want to position below - */ - $scope.showMenu = function(column, $columnElement, event) { - // Swap to this column - $scope.col = column; - - // Get the position information for the column element - var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement ); - - if ($scope.menuShown) { - // we want to hide, then reposition, then show, but we want to wait for animations - // we set a variable, and then rely on the menu-hidden event to call the reposition and show - $scope.colElement = $columnElement; - $scope.colElementPosition = colElementPosition; - $scope.hideThenShow = true; - - $scope.$broadcast('hide-menu', { originalEvent: event }); - } else { - $scope.menuShown = true; - uiGridColumnMenuService.repositionMenu( $scope, column, colElementPosition, $elm, $columnElement ); - - $scope.colElement = $columnElement; - $scope.colElementPosition = colElementPosition; - $scope.$broadcast('show-menu', { originalEvent: event }); - - } - }; - - - /** - * @ngdoc method - * @methodOf ui.grid.directive:uiGridColumnMenu - * @name hideMenu - * @description Hides the column menu. - * @param {boolean} broadcastTrigger true if we were triggered by a broadcast - * from the menu itself - in which case don't broadcast again as we'll get - * an infinite loop - */ - $scope.hideMenu = function( broadcastTrigger ) { - $scope.menuShown = false; - if ( !broadcastTrigger ){ - $scope.$broadcast('hide-menu'); - } - }; - - - $scope.$on('menu-hidden', function() { - if ( $scope.hideThenShow ){ - delete $scope.hideThenShow; - uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); - // browdcast the show-menu event after a time out so that the ng-if has a chance to remove - // the old menu from the DOM so that we don't get duplicate items. - $timeout( function() { - $scope.$broadcast('show-menu'); - - $scope.menuShown = true; - }); - - } else { - $scope.hideMenu( true ); - - if ($scope.col) { - //Focus on the menu button - gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false); - } - } - }); - - $scope.$on('menu-shown', function() { - $timeout( function() { - uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); - //Focus on the first item - gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item', true); - delete $scope.colElementPosition; - delete $scope.columnElement; - }, 200); - }); - - - /* Column methods */ - $scope.sortColumn = function (event, dir) { - event.stopPropagation(); - - $scope.grid.sortColumn($scope.col, dir, true) - .then(function () { - $scope.grid.refresh(); - $scope.hideMenu(); - }).catch(angular.noop); - }; - - $scope.unsortColumn = function () { - $scope.col.unsort(); - - $scope.grid.refresh(); - $scope.hideMenu(); - }; - - //Since we are hiding this column the default hide action will fail so we need to focus somewhere else. - var setFocusOnHideColumn = function(){ - $timeout(function(){ - // Get the UID of the first - var focusToGridMenu = function(){ - return gridUtil.focus.byId('grid-menu', $scope.grid); - }; - - var thisIndex; - $scope.grid.columns.some(function(element, index){ - if (angular.equals(element, $scope.col)) { - thisIndex = index; - return true; - } - }); - - var previousVisibleCol; - // Try and find the next lower or nearest column to focus on - $scope.grid.columns.some(function(element, index){ - if (!element.visible){ - return false; - } // This columns index is below the current column index - else if ( index < thisIndex){ - previousVisibleCol = element; - } // This elements index is above this column index and we haven't found one that is lower - else if ( index > thisIndex && !previousVisibleCol) { - // This is the next best thing - previousVisibleCol = element; - // We've found one so use it. - return true; - } // We've reached an element with an index above this column and the previousVisibleCol variable has been set - else if (index > thisIndex && previousVisibleCol) { - // We are done. - return true; - } - }); - // If found then focus on it - if (previousVisibleCol){ - var colClass = previousVisibleCol.getColClass(); - gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason){ - if (reason !== 'canceled'){ // If this is canceled then don't perform the action - //The fallback action is to focus on the grid menu - return focusToGridMenu(); - } - }).catch(angular.noop); - } else { - // Fallback action to focus on the grid menu - focusToGridMenu(); - } - }); - }; - - $scope.hideColumn = function () { - $scope.col.colDef.visible = false; - $scope.col.visible = false; - - $scope.grid.queueGridRefresh(); - $scope.hideMenu(); - $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); - $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col ); - - // We are hiding so the default action of focusing on the button that opened this menu will fail. - setFocusOnHideColumn(); - }; - }, - - - - controller: ['$scope', function ($scope) { - var self = this; - - $scope.$watch('menuItems', function (n) { - self.menuItems = n; - }); - }] - }; - - return uiGridColumnMenu; - -}]); - -})(); diff --git a/src/js/core/directives/ui-grid-filter.js b/src/js/core/directives/ui-grid-filter.js deleted file mode 100644 index 338575c6c6..0000000000 --- a/src/js/core/directives/ui-grid-filter.js +++ /dev/null @@ -1,35 +0,0 @@ -(function(){ - 'use strict'; - - angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) { - - return { - compile: function() { - return { - pre: function ($scope, $elm, $attrs, controllers) { - $scope.col.updateFilters = function( filterable ){ - $elm.children().remove(); - if ( filterable ){ - var template = $scope.col.filterHeaderTemplate; - - $elm.append($compile(template)($scope)); - } - }; - - $scope.$on( '$destroy', function() { - delete $scope.col.updateFilters; - }); - }, - post: function ($scope, $elm, $attrs, controllers){ - $scope.aria = i18nService.getSafeText('headerCell.aria'); - $scope.removeFilter = function(colFilter, index){ - colFilter.term = null; - //Set the focus to the filter input after the action disables the button - gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index); - }; - } - }; - } - }; - }]); -})(); diff --git a/src/js/core/directives/ui-grid-footer-cell.js b/src/js/core/directives/ui-grid-footer-cell.js deleted file mode 100644 index a1886a5b58..0000000000 --- a/src/js/core/directives/ui-grid-footer-cell.js +++ /dev/null @@ -1,82 +0,0 @@ -(function () { - 'use strict'; - - angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile', - function ($timeout, gridUtil, uiGridConstants, $compile) { - var uiGridFooterCell = { - priority: 0, - scope: { - col: '=', - row: '=', - renderIndex: '=' - }, - replace: true, - require: '^uiGrid', - compile: function compile(tElement, tAttrs, transclude) { - return { - pre: function ($scope, $elm, $attrs, uiGridCtrl) { - var cellFooter = $compile($scope.col.footerCellTemplate)($scope); - $elm.append(cellFooter); - }, - post: function ($scope, $elm, $attrs, uiGridCtrl) { - //$elm.addClass($scope.col.getColClass(false)); - $scope.grid = uiGridCtrl.grid; - - var initColClass = $scope.col.getColClass(false); - $elm.addClass(initColClass); - - // apply any footerCellClass - var classAdded; - var updateClass = function( grid ){ - var contents = $elm; - if ( classAdded ){ - contents.removeClass( classAdded ); - classAdded = null; - } - - if (angular.isFunction($scope.col.footerCellClass)) { - classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); - } - else { - classAdded = $scope.col.footerCellClass; - } - contents.addClass(classAdded); - }; - - if ($scope.col.footerCellClass) { - updateClass(); - } - - $scope.col.updateAggregationValue(); - - // Watch for column changes so we can alter the col cell class properly -/* shouldn't be needed any more, given track by col.name - $scope.$watch('col', function (n, o) { - if (n !== o) { - // See if the column's internal class has changed - var newColClass = $scope.col.getColClass(false); - if (newColClass !== initColClass) { - $elm.removeClass(initColClass); - $elm.addClass(newColClass); - initColClass = newColClass; - } - } - }); -*/ - - - // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs - var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]); - // listen for visible rows change and update aggregation values - $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); - $scope.grid.api.core.on.rowsRendered( $scope, updateClass ); - $scope.$on( '$destroy', dataChangeDereg ); - } - }; - } - }; - - return uiGridFooterCell; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-footer.js b/src/js/core/directives/ui-grid-footer.js deleted file mode 100644 index bc5a1b8ce5..0000000000 --- a/src/js/core/directives/ui-grid-footer.js +++ /dev/null @@ -1,65 +0,0 @@ -(function () { - 'use strict'; - - angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) { - - return { - restrict: 'EA', - replace: true, - // priority: 1000, - require: ['^uiGrid', '^uiGridRenderContainer'], - scope: true, - compile: function ($elm, $attrs) { - return { - pre: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var containerCtrl = controllers[1]; - - $scope.grid = uiGridCtrl.grid; - $scope.colContainer = containerCtrl.colContainer; - - containerCtrl.footer = $elm; - - var footerTemplate = $scope.grid.options.footerTemplate; - gridUtil.getTemplate(footerTemplate) - .then(function (contents) { - var template = angular.element(contents); - - var newElm = $compile(template)($scope); - $elm.append(newElm); - - if (containerCtrl) { - // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below - var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; - - if (footerViewport) { - containerCtrl.footerViewport = footerViewport; - } - } - }).catch(angular.noop); - }, - - post: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var containerCtrl = controllers[1]; - - // gridUtil.logDebug('ui-grid-footer link'); - - var grid = uiGridCtrl.grid; - - // Don't animate footer cells - gridUtil.disableAnimations($elm); - - containerCtrl.footer = $elm; - - var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; - if (footerViewport) { - containerCtrl.footerViewport = footerViewport; - } - } - }; - } - }; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-grid-footer.js b/src/js/core/directives/ui-grid-grid-footer.js deleted file mode 100644 index d0424cfa49..0000000000 --- a/src/js/core/directives/ui-grid-grid-footer.js +++ /dev/null @@ -1,38 +0,0 @@ -(function () { - 'use strict'; - - angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) { - - return { - restrict: 'EA', - replace: true, - // priority: 1000, - require: '^uiGrid', - scope: true, - compile: function ($elm, $attrs) { - return { - pre: function ($scope, $elm, $attrs, uiGridCtrl) { - - $scope.grid = uiGridCtrl.grid; - - - - var footerTemplate = $scope.grid.options.gridFooterTemplate; - gridUtil.getTemplate(footerTemplate) - .then(function (contents) { - var template = angular.element(contents); - - var newElm = $compile(template)($scope); - $elm.append(newElm); - }).catch(angular.noop); - }, - - post: function ($scope, $elm, $attrs, controllers) { - - } - }; - } - }; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-group-panel.js b/src/js/core/directives/ui-grid-group-panel.js deleted file mode 100644 index 5d01af48ef..0000000000 --- a/src/js/core/directives/ui-grid-group-panel.js +++ /dev/null @@ -1,36 +0,0 @@ -(function(){ - 'use strict'; - - angular.module('ui.grid').directive('uiGridGroupPanel', ["$compile", "uiGridConstants", "gridUtil", function($compile, uiGridConstants, gridUtil) { - var defaultTemplate = 'ui-grid/ui-grid-group-panel'; - - return { - restrict: 'EA', - replace: true, - require: '?^uiGrid', - scope: false, - compile: function($elm, $attrs) { - return { - pre: function ($scope, $elm, $attrs, uiGridCtrl) { - var groupPanelTemplate = $scope.grid.options.groupPanelTemplate || defaultTemplate; - - gridUtil.getTemplate(groupPanelTemplate) - .then(function (contents) { - var template = angular.element(contents); - - var newElm = $compile(template)($scope); - $elm.append(newElm); - }).catch(angular.noop); - }, - - post: function ($scope, $elm, $attrs, uiGridCtrl) { - $elm.bind('$destroy', function() { - // scrollUnbinder(); - }); - } - }; - } - }; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-header-cell.js b/src/js/core/directives/ui-grid-header-cell.js deleted file mode 100644 index 29ddcbfd2f..0000000000 --- a/src/js/core/directives/ui-grid-header-cell.js +++ /dev/null @@ -1,414 +0,0 @@ -(function(){ - 'use strict'; - - angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', - function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) { - // Do stuff after mouse has been down this many ms on the header cell - var mousedownTimeout = 500; - var changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa - - var uiGridHeaderCell = { - priority: 0, - scope: { - col: '=', - row: '=', - renderIndex: '=' - }, - require: ['^uiGrid', '^uiGridRenderContainer'], - replace: true, - compile: function() { - return { - pre: function ($scope, $elm, $attrs) { - var cellHeader = $compile($scope.col.headerCellTemplate)($scope); - $elm.append(cellHeader); - }, - - post: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var renderContainerCtrl = controllers[1]; - - $scope.i18n = { - headerCell: i18nService.getSafeText('headerCell'), - sort: i18nService.getSafeText('sort') - }; - $scope.isSortPriorityVisible = function() { - //show sort priority if column is sorted and there is at least one other sorted column - return angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index){ - return angular.isNumber(element.sort.priority) && element !== $scope.col; - }); - }; - $scope.getSortDirectionAriaLabel = function(){ - var col = $scope.col; - //Trying to recreate this sort of thing but it was getting messy having it in the template. - //Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending':'none')}}. {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''} - var sortDirectionText = col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none); - var label = sortDirectionText; - - if ($scope.isSortPriorityVisible()) { - label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1); - } - return label; - }; - - $scope.grid = uiGridCtrl.grid; - - $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId]; - - var initColClass = $scope.col.getColClass(false); - $elm.addClass(initColClass); - - // Hide the menu by default - $scope.menuShown = false; - - // Put asc and desc sort directions in scope - $scope.asc = uiGridConstants.ASC; - $scope.desc = uiGridConstants.DESC; - - // Store a reference to menu element - var $colMenu = angular.element( $elm[0].querySelectorAll('.ui-grid-header-cell-menu') ); - - var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); - - - // apply any headerCellClass - var classAdded; - var previousMouseX; - - // filter watchers - var filterDeregisters = []; - - - /* - * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart). - * Once we have a down event, we need to work out whether we have a click, a drag, or a - * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so - * we ignore it. A hold would open the menu. - * - * So, on down event, we put in place handlers for move and up events, and a timer. If the - * timer expires before we see a move or up, then we have a long press and hence a column menu open. - * If the up happens before the timer, then we have a click, and we sort if the column is sortable. - * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature - * will handle it. - * - * To deal with touch enabled devices that also have mice, we only create our handlers when - * we get the down event, and we create the corresponding handlers - if we're touchstart then - * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup. - * - * We also suppress the click action whilst this is happening - otherwise after the mouseup there - * will be a click event and that can cause the column menu to close - * - */ - - $scope.downFn = function( event ){ - event.stopPropagation(); - - if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { - event = event.originalEvent; - } - - // Don't show the menu if it's not the left button - if (event.button && event.button !== 0) { - return; - } - previousMouseX = event.pageX; - - $scope.mousedownStartTime = (new Date()).getTime(); - $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout); - - $scope.mousedownTimeout.then(function () { - if ( $scope.colMenu ) { - uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); - } - }).catch(angular.noop); - - uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name}); - - $scope.offAllEvents(); - if ( event.type === 'touchstart'){ - $document.on('touchend', $scope.upFn); - $document.on('touchmove', $scope.moveFn); - } else if ( event.type === 'mousedown' ){ - $document.on('mouseup', $scope.upFn); - $document.on('mousemove', $scope.moveFn); - } - }; - - $scope.upFn = function( event ){ - event.stopPropagation(); - $timeout.cancel($scope.mousedownTimeout); - $scope.offAllEvents(); - $scope.onDownEvents(event.type); - - var mousedownEndTime = (new Date()).getTime(); - var mousedownTime = mousedownEndTime - $scope.mousedownStartTime; - - if (mousedownTime > mousedownTimeout) { - // long click, handled above with mousedown - } - else { - // short click - if ( $scope.sortable ){ - $scope.handleClick(event); - } - } - }; - - $scope.moveFn = function( event ){ - // Chrome is known to fire some bogus move events. - var changeValue = event.pageX - previousMouseX; - if ( changeValue === 0 ){ return; } - - // we're a move, so do nothing and leave for column move (if enabled) to take over - $timeout.cancel($scope.mousedownTimeout); - $scope.offAllEvents(); - $scope.onDownEvents(event.type); - }; - - $scope.clickFn = function ( event ){ - event.stopPropagation(); - $contentsElm.off('click', $scope.clickFn); - }; - - - $scope.offAllEvents = function(){ - $contentsElm.off('touchstart', $scope.downFn); - $contentsElm.off('mousedown', $scope.downFn); - - $document.off('touchend', $scope.upFn); - $document.off('mouseup', $scope.upFn); - - $document.off('touchmove', $scope.moveFn); - $document.off('mousemove', $scope.moveFn); - - $contentsElm.off('click', $scope.clickFn); - }; - - $scope.onDownEvents = function( type ){ - // If there is a previous event, then wait a while before - // activating the other mode - i.e. if the last event was a touch event then - // don't enable mouse events for a wee while (500ms or so) - // Avoids problems with devices that emulate mouse events when you have touch events - - switch (type){ - case 'touchmove': - case 'touchend': - $contentsElm.on('click', $scope.clickFn); - $contentsElm.on('touchstart', $scope.downFn); - $timeout(function(){ - $contentsElm.on('mousedown', $scope.downFn); - }, changeModeTimeout); - break; - case 'mousemove': - case 'mouseup': - $contentsElm.on('click', $scope.clickFn); - $contentsElm.on('mousedown', $scope.downFn); - $timeout(function(){ - $contentsElm.on('touchstart', $scope.downFn); - }, changeModeTimeout); - break; - default: - $contentsElm.on('click', $scope.clickFn); - $contentsElm.on('touchstart', $scope.downFn); - $contentsElm.on('mousedown', $scope.downFn); - } - }; - - - var updateHeaderOptions = function( grid ){ - var contents = $elm; - if ( classAdded ){ - contents.removeClass( classAdded ); - classAdded = null; - } - - if (angular.isFunction($scope.col.headerCellClass)) { - classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); - } - else { - classAdded = $scope.col.headerCellClass; - } - contents.addClass(classAdded); - - $timeout(function (){ - var rightMostContainer = $scope.grid.renderContainers['right'] ? $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body']; - $scope.isLastCol = ( $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ] ); - }); - - // Figure out whether this column is sortable or not - if ($scope.col.enableSorting) { - $scope.sortable = true; - } - else { - $scope.sortable = false; - } - - // Figure out whether this column is filterable or not - var oldFilterable = $scope.filterable; - if (uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering) { - $scope.filterable = true; - } - else { - $scope.filterable = false; - } - - if ( oldFilterable !== $scope.filterable){ - if ( typeof($scope.col.updateFilters) !== 'undefined' ){ - $scope.col.updateFilters($scope.filterable); - } - - // if column is filterable add a filter watcher - if ($scope.filterable) { - $scope.col.filters.forEach( function(filter, i) { - filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { - if (n !== o) { - uiGridCtrl.grid.api.core.raise.filterChanged(); - uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); - uiGridCtrl.grid.queueGridRefresh(); - } - })); - }); - $scope.$on('$destroy', function() { - filterDeregisters.forEach( function(filterDeregister) { - filterDeregister(); - }); - }); - } else { - filterDeregisters.forEach( function(filterDeregister) { - filterDeregister(); - }); - } - - } - - // figure out whether we support column menus - if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && - $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){ - $scope.colMenu = true; - } else { - $scope.colMenu = false; - } - - /** - * @ngdoc property - * @name enableColumnMenu - * @propertyOf ui.grid.class:GridOptions.columnDef - * @description if column menus are enabled, controls the column menus for this specific - * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus - * using this option. If gridOptions.enableColumnMenus === false then you get no column - * menus irrespective of the value of this option ). Defaults to true. - * - */ - /** - * @ngdoc property - * @name enableColumnMenus - * @propertyOf ui.grid.class:GridOptions.columnDef - * @description Override for column menus everywhere - if set to false then you get no - * column menus. Defaults to true. - * - */ - - $scope.offAllEvents(); - - if ($scope.sortable || $scope.colMenu) { - $scope.onDownEvents(); - - $scope.$on('$destroy', function () { - $scope.offAllEvents(); - }); - } - }; - -/* - $scope.$watch('col', function (n, o) { - if (n !== o) { - // See if the column's internal class has changed - var newColClass = $scope.col.getColClass(false); - if (newColClass !== initColClass) { - $elm.removeClass(initColClass); - $elm.addClass(newColClass); - initColClass = newColClass; - } - } - }); -*/ - updateHeaderOptions(); - - // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs - var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]); - - $scope.$on( '$destroy', dataChangeDereg ); - - function applySort(add) { - if ($scope.col.enableSorting === false) { return; } - // Sort this column then rebuild the grid's rows - uiGridCtrl.grid.sortColumn($scope.col, add) - .then(function () { - if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); } - uiGridCtrl.grid.refresh(); - }).catch(angular.noop); - } - - function applyMoveColumn(moveRight) { - if (!$scope.col) { return; } - if (!uiGridCtrl.grid.api.colMovable) { return; } - - var columns = $scope.grid.columns; - var columnIndex = 0; - for (var i = 0; i < columns.length; i++) { - if (columns[i].colDef.name === $scope.col.colDef.name) { - columnIndex = i; - break; - } - } - - // Move Column already handles checking valid index ranges. - var newIndex = moveRight ? columnIndex + 1 : columnIndex - 1; - uiGridCtrl.grid.api.colMovable.moveColumn(columnIndex, newIndex); - } - - $scope.handleClick = function(event) { - // If the shift key is being held down, add this column to the sort - applySort(event.shiftKey); - }; - - $scope.handleKeyDown = function(event) { - if (event.key === 'Enter' || event.key === ' ') { - applySort(event.shiftKey); - } else if (event.altKey && event.shiftKey && event.key === "ArrowLeft") { - applyMoveColumn(false); - } else if (event.altKey && event.shiftKey && event.key === "ArrowRight") { - applyMoveColumn(true); - } - }; - - $scope.toggleMenu = function(event) { - event.stopPropagation(); - - // If the menu is already showing... - if (uiGridCtrl.columnMenuScope.menuShown) { - // ... and we're the column the menu is on... - if (uiGridCtrl.columnMenuScope.col === $scope.col) { - // ... hide it - uiGridCtrl.columnMenuScope.hideMenu(); - } - // ... and we're NOT the column the menu is on - else { - // ... move the menu to our column - uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm); - } - } - // If the menu is NOT showing - else { - // ... show it on our column - uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm); - } - }; - } - }; - } - }; - - return uiGridHeaderCell; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-header.js b/src/js/core/directives/ui-grid-header.js deleted file mode 100644 index cab6a0d188..0000000000 --- a/src/js/core/directives/ui-grid-header.js +++ /dev/null @@ -1,146 +0,0 @@ -(function(){ - 'use strict'; - - angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent', - function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) { - var defaultTemplate = 'ui-grid/ui-grid-header'; - var emptyTemplate = 'ui-grid/ui-grid-no-header'; - - return { - restrict: 'EA', - // templateUrl: 'ui-grid/ui-grid-header', - replace: true, - // priority: 1000, - require: ['^uiGrid', '^uiGridRenderContainer'], - scope: true, - compile: function($elm, $attrs) { - return { - pre: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var containerCtrl = controllers[1]; - - $scope.grid = uiGridCtrl.grid; - $scope.colContainer = containerCtrl.colContainer; - - updateHeaderReferences(); - - var headerTemplate; - if (!$scope.grid.options.showHeader) { - headerTemplate = emptyTemplate; - } - else { - headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate; - } - - gridUtil.getTemplate(headerTemplate) - .then(function (contents) { - var template = angular.element(contents); - - var newElm = $compile(template)($scope); - $elm.replaceWith(newElm); - - // And update $elm to be the new element - $elm = newElm; - - updateHeaderReferences(); - - if (containerCtrl) { - // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below - var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; - - - if (headerViewport) { - containerCtrl.headerViewport = headerViewport; - angular.element(headerViewport).on('scroll', scrollHandler); - $scope.$on('$destroy', function () { - angular.element(headerViewport).off('scroll', scrollHandler); - }); - } - } - - $scope.grid.queueRefresh(); - }).catch(angular.noop); - - function updateHeaderReferences() { - containerCtrl.header = containerCtrl.colContainer.header = $elm; - - var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas'); - - if (headerCanvases.length > 0) { - containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0]; - } - else { - containerCtrl.headerCanvas = null; - } - } - - function scrollHandler(evt) { - if (uiGridCtrl.grid.isScrollingHorizontally) { - return; - } - var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid); - var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft); - - var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll); - scrollEvent.newScrollLeft = newScrollLeft; - if ( horizScrollPercentage > -1 ){ - scrollEvent.x = { percentage: horizScrollPercentage }; - } - - uiGridCtrl.grid.scrollContainers(null, scrollEvent); - } - }, - - post: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var containerCtrl = controllers[1]; - - // gridUtil.logDebug('ui-grid-header link'); - - var grid = uiGridCtrl.grid; - - // Don't animate header cells - gridUtil.disableAnimations($elm); - - function updateColumnWidths() { - // this styleBuilder always runs after the renderContainer, so we can rely on the column widths - // already being populated correctly - - var columnCache = containerCtrl.colContainer.visibleColumnCache; - - // Build the CSS - // uiGridCtrl.grid.columns.forEach(function (column) { - var ret = ''; - var canvasWidth = 0; - columnCache.forEach(function (column) { - ret = ret + column.getColClassDefinition(); - canvasWidth += column.drawnWidth; - }); - - containerCtrl.colContainer.canvasWidth = canvasWidth; - - // Return the styles back to buildStyles which pops them into the `customStyles` scope variable - return ret; - } - - containerCtrl.header = $elm; - - var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; - if (headerViewport) { - containerCtrl.headerViewport = headerViewport; - } - - //todo: remove this if by injecting gridCtrl into unit tests - if (uiGridCtrl) { - uiGridCtrl.grid.registerStyleComputation({ - priority: 15, - func: updateColumnWidths - }); - } - } - }; - } - }; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-menu-button.js b/src/js/core/directives/ui-grid-menu-button.js deleted file mode 100644 index 159f8253e9..0000000000 --- a/src/js/core/directives/ui-grid-menu-button.js +++ /dev/null @@ -1,409 +0,0 @@ -(function(){ - -angular.module('ui.grid') -.service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) { - /** - * @ngdoc service - * @name ui.grid.gridMenuService - * - * @description Methods for working with the grid menu - */ - - var service = { - /** - * @ngdoc method - * @methodOf ui.grid.gridMenuService - * @name initialize - * @description Sets up the gridMenu. Most importantly, sets our - * scope onto the grid object as grid.gridMenuScope, allowing us - * to operate when passed only the grid. Second most importantly, - * we register the 'addToGridMenu' and 'removeFromGridMenu' methods - * on the core api. - * @param {$scope} $scope the scope of this gridMenu - * @param {Grid} grid the grid to which this gridMenu is associated - */ - initialize: function( $scope, grid ){ - grid.gridMenuScope = $scope; - $scope.grid = grid; - $scope.registeredMenuItems = []; - - // not certain this is needed, but would be bad to create a memory leak - $scope.$on('$destroy', function() { - if ( $scope.grid && $scope.grid.gridMenuScope ){ - $scope.grid.gridMenuScope = null; - } - if ( $scope.grid ){ - $scope.grid = null; - } - if ( $scope.registeredMenuItems ){ - $scope.registeredMenuItems = null; - } - }); - - $scope.registeredMenuItems = []; - - /** - * @ngdoc function - * @name addToGridMenu - * @methodOf ui.grid.core.api:PublicApi - * @description add items to the grid menu. Used by features - * to add their menu items if they are enabled, can also be used by - * end users to add menu items. This method has the advantage of allowing - * remove again, which can simplify management of which items are included - * in the menu when. (Noting that in most cases the shown and active functions - * provide a better way to handle visibility of menu items) - * @param {Grid} grid the grid on which we are acting - * @param {array} items menu items in the format as described in the tutorial, with - * the added note that if you want to use remove you must also specify an `id` field, - * which is provided when you want to remove an item. The id should be unique. - * - */ - grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu ); - - /** - * @ngdoc function - * @name removeFromGridMenu - * @methodOf ui.grid.core.api:PublicApi - * @description Remove an item from the grid menu based on a provided id. Assumes - * that the id is unique, removes only the last instance of that id. Does nothing if - * the specified id is not found - * @param {Grid} grid the grid on which we are acting - * @param {string} id the id we'd like to remove from the menu - * - */ - grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu ); - }, - - - /** - * @ngdoc function - * @name addToGridMenu - * @propertyOf ui.grid.gridMenuService - * @description add items to the grid menu. Used by features - * to add their menu items if they are enabled, can also be used by - * end users to add menu items. This method has the advantage of allowing - * remove again, which can simplify management of which items are included - * in the menu when. (Noting that in most cases the shown and active functions - * provide a better way to handle visibility of menu items) - * @param {Grid} grid the grid on which we are acting - * @param {array} items menu items in the format as described in the tutorial, with - * the added note that if you want to use remove you must also specify an `id` field, - * which is provided when you want to remove an item. The id should be unique. - * - */ - addToGridMenu: function( grid, menuItems ) { - if ( !angular.isArray( menuItems ) ) { - gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items'); - } else { - if ( grid.gridMenuScope ){ - grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : []; - grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems ); - } else { - gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid'); - } - } - }, - - - /** - * @ngdoc function - * @name removeFromGridMenu - * @methodOf ui.grid.gridMenuService - * @description Remove an item from the grid menu based on a provided id. Assumes - * that the id is unique, removes only the last instance of that id. Does nothing if - * the specified id is not found. If there is no gridMenuScope or registeredMenuItems - * then do nothing silently - the desired result is those menu items not be present and they - * aren't. - * @param {Grid} grid the grid on which we are acting - * @param {string} id the id we'd like to remove from the menu - * - */ - removeFromGridMenu: function( grid, id ){ - var foundIndex = -1; - - if ( grid && grid.gridMenuScope ){ - grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) { - if ( value.id === id ){ - if (foundIndex > -1) { - gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' ); - } else { - - foundIndex = index; - } - } - }); - } - - if ( foundIndex > -1 ){ - grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 ); - } - }, - - - /** - * @ngdoc array - * @name gridMenuCustomItems - * @propertyOf ui.grid.class:GridOptions - * @description (optional) An array of menu items that should be added to - * the gridMenu. Follow the format documented in the tutorial for column - * menu customisation. The context provided to the action function will - * include context.grid. An alternative if working with dynamic menus is to use the - * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles - * some of the management of items for you. - * - */ - /** - * @ngdoc boolean - * @name gridMenuShowHideColumns - * @propertyOf ui.grid.class:GridOptions - * @description true by default, whether the grid menu should allow hide/show - * of columns - * - */ - /** - * @ngdoc method - * @methodOf ui.grid.gridMenuService - * @name getMenuItems - * @description Decides the menu items to show in the menu. This is a - * combination of: - * - * - the default menu items that are always included, - * - any menu items that have been provided through the addMenuItem api. These - * are typically added by features within the grid - * - any menu items included in grid.options.gridMenuCustomItems. These can be - * changed dynamically, as they're always recalculated whenever we show the - * menu - * @param {$scope} $scope the scope of this gridMenu, from which we can find all - * the information that we need - * @returns {array} an array of menu items that can be shown - */ - getMenuItems: function( $scope ) { - var menuItems = [ - // this is where we add any menu items we want to always include - ]; - - if ( $scope.grid.options.gridMenuCustomItems ){ - if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ){ - gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not'); - } else { - menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems ); - } - } - - var clearFilters = [{ - title: i18nService.getSafeText('gridMenu.clearAllFilters'), - action: function ($event) { - $scope.grid.clearAllFilters(); - }, - shown: function() { - return $scope.grid.options.enableFiltering; - }, - order: 100 - }]; - menuItems = menuItems.concat( clearFilters ); - - menuItems = menuItems.concat( $scope.registeredMenuItems ); - - if ( $scope.grid.options.gridMenuShowHideColumns !== false ){ - menuItems = menuItems.concat( service.showHideColumns( $scope ) ); - } - - menuItems.sort(function(a, b){ - return a.order - b.order; - }); - - return menuItems; - }, - - - /** - * @ngdoc array - * @name gridMenuTitleFilter - * @propertyOf ui.grid.class:GridOptions - * @description (optional) A function that takes a title string - * (usually the col.displayName), and converts it into a display value. The function - * must return either a string or a promise. - * - * Used for internationalization of the grid menu column names - for angular-translate - * you can pass $translate as the function, for i18nService you can pass getSafeText as the - * function - * @example - *
    -     *   gridOptions = {
    -     *     gridMenuTitleFilter: $translate
    -     *   }
    -     * 
    - */ - /** - * @ngdoc method - * @methodOf ui.grid.gridMenuService - * @name showHideColumns - * @description Adds two menu items for each of the columns in columnDefs. One - * menu item for hide, one menu item for show. Each is visible when appropriate - * (show when column is not visible, hide when column is visible). Each toggles - * the visible property on the columnDef using toggleColumnVisibility - * @param {$scope} $scope of a gridMenu, which contains a reference to the grid - */ - showHideColumns: function( $scope ){ - var showHideColumns = []; - if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) { - return showHideColumns; - } - - // add header for columns - showHideColumns.push({ - title: i18nService.getSafeText('gridMenu.columns'), - order: 300 - }); - - $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; }; - - $scope.grid.options.columnDefs.forEach( function( colDef, index ){ - if ( colDef.enableHiding !== false ){ - // add hide menu item - shows an OK icon as we only show when column is already visible - var menuItem = { - icon: 'ui-grid-icon-ok', - action: function($event) { - $event.stopPropagation(); - service.toggleColumnVisibility( this.context.gridCol ); - }, - shown: function() { - return this.context.gridCol.colDef.visible === true || this.context.gridCol.colDef.visible === undefined; - }, - context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) }, - leaveOpen: true, - order: 301 + index * 2 - }; - service.setMenuItemTitle( menuItem, colDef, $scope.grid ); - showHideColumns.push( menuItem ); - - // add show menu item - shows no icon as we only show when column is invisible - menuItem = { - icon: 'ui-grid-icon-cancel', - action: function($event) { - $event.stopPropagation(); - service.toggleColumnVisibility( this.context.gridCol ); - }, - shown: function() { - return !(this.context.gridCol.colDef.visible === true || this.context.gridCol.colDef.visible === undefined); - }, - context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) }, - leaveOpen: true, - order: 301 + index * 2 + 1 - }; - service.setMenuItemTitle( menuItem, colDef, $scope.grid ); - showHideColumns.push( menuItem ); - } - }); - showHideColumns.forEach( function (menuItem) { - menuItem.templateUrl = $scope.grid.options.menuItemTemplate; - }); - return showHideColumns; - }, - - - /** - * @ngdoc method - * @methodOf ui.grid.gridMenuService - * @name setMenuItemTitle - * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu - * item if it returns a string, otherwise waiting for the promise to resolve or reject then - * putting the result into the title - * @param {object} menuItem the menuItem we want to put the title on - * @param {object} colDef the colDef from which we can get displayName, name or field - * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter - * - */ - setMenuItemTitle: function( menuItem, colDef, grid ){ - var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field ); - - if ( typeof(title) === 'string' ){ - menuItem.title = title; - } else if ( title.then ){ - // must be a promise - menuItem.title = ""; - title.then( function( successValue ) { - menuItem.title = successValue; - }, function( errorValue ) { - menuItem.title = errorValue; - }).catch(angular.noop); - } else { - gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config'); - menuItem.title = 'badconfig'; - } - }, - - /** - * @ngdoc method - * @methodOf ui.grid.gridMenuService - * @name toggleColumnVisibility - * @description Toggles the visibility of an individual column. Expects to be - * provided a context that has on it a gridColumn, which is the column that - * we'll operate upon. We change the visibility, and refresh the grid as appropriate - * @param {GridCol} gridCol the column that we want to toggle - * - */ - toggleColumnVisibility: function( gridCol ) { - gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined ); - - gridCol.grid.refresh(); - gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); - gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol ); - } - }; - - return service; -}]) - - - -.directive('uiGridMenuButton', ['$compile', 'gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService', -function ($compile, gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) { - var defaultTemplate = 'ui-grid/ui-grid-menu-button'; - return { - priority: 0, - scope: true, - require: ['^uiGrid'], - replace: true, - link: function ($scope, $elm, $attrs, controllers) { - var uiGridCtrl = controllers[0]; - var menuButtonTemplate = (uiGridCtrl.grid && uiGridCtrl.grid.options.menuButtonTemplate) ? uiGridCtrl.grid.options.menuButtonTemplate : defaultTemplate; - gridUtil.getTemplate(menuButtonTemplate) - .then(function (contents) { - var template = angular.element(contents); - // Insert the template into the DOM first, so that when we compile it - // the ui-grid-menu will have the required uiGrid controller. - $elm.replaceWith(template); - $compile(template)($scope); - }); - - // For the aria label - $scope.i18n = { - aria: i18nService.getSafeText('gridMenu.aria') - }; - - uiGridGridMenuService.initialize($scope, uiGridCtrl.grid); - - $scope.shown = false; - - $scope.toggleMenu = function () { - if ( $scope.shown ){ - $scope.$broadcast('hide-menu'); - $scope.shown = false; - } else { - $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope ); - $scope.$broadcast('show-menu'); - $scope.shown = true; - } - }; - - $scope.$on('menu-hidden', function() { - $scope.shown = false; - gridUtil.focus.bySelector($elm, '.ui-grid-icon-container'); - }); - } - }; - -}]); - -})(); diff --git a/src/js/core/directives/ui-grid-menu.js b/src/js/core/directives/ui-grid-menu.js deleted file mode 100644 index 8361f47e58..0000000000 --- a/src/js/core/directives/ui-grid-menu.js +++ /dev/null @@ -1,353 +0,0 @@ -(function(){ - -/** - * @ngdoc directive - * @name ui.grid.directive:uiGridMenu - * @element style - * @restrict A - * - * @description - * Allows us to interpolate expressions in ` - I am in a box. -
    - - - it('should apply the right class to the element', function () { - element(by.css('.blah')).getCssValue('border-top-width') - .then(function(c) { - expect(c).toContain('1px'); - }); - }); - - - */ - - - angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) { - return { - // restrict: 'A', - // priority: 1000, - // require: '?^uiGrid', - link: function($scope, $elm, $attrs, uiGridCtrl) { - // gridUtil.logDebug('ui-grid-style link'); - // if (uiGridCtrl === undefined) { - // gridUtil.logWarn('[ui-grid-style link] uiGridCtrl is undefined!'); - // } - - var interpolateFn = $interpolate($elm.text(), true); - - if (interpolateFn) { - $scope.$watch(interpolateFn, function(value) { - $elm.text(value); - }); - } - - // uiGridCtrl.recalcRowStyles = function() { - // var offset = (scope.options.offsetTop || 0) - (scope.options.excessRows * scope.options.rowHeight); - // var rowHeight = scope.options.rowHeight; - - // var ret = ''; - // var rowStyleCount = uiGridCtrl.minRowsToRender() + (scope.options.excessRows * 2); - // for (var i = 1; i <= rowStyleCount; i++) { - // ret = ret + ' .grid' + scope.gridId + ' .ui-grid-row:nth-child(' + i + ') { top: ' + offset + 'px; }'; - // offset = offset + rowHeight; - // } - - // scope.rowStyles = ret; - // }; - - // uiGridCtrl.styleComputions.push(uiGridCtrl.recalcRowStyles); - - } - }; - }]); - -})(); diff --git a/src/js/core/directives/ui-grid-viewport.js b/src/js/core/directives/ui-grid-viewport.js deleted file mode 100644 index e76da574d4..0000000000 --- a/src/js/core/directives/ui-grid-viewport.js +++ /dev/null @@ -1,171 +0,0 @@ -(function(){ - 'use strict'; - - angular.module('ui.grid').directive('uiGridViewport', ['gridUtil','ScrollEvent','uiGridConstants', '$log', - function(gridUtil, ScrollEvent, uiGridConstants, $log) { - return { - replace: true, - scope: {}, - controllerAs: 'Viewport', - templateUrl: 'ui-grid/uiGridViewport', - require: ['^uiGrid', '^uiGridRenderContainer'], - link: function($scope, $elm, $attrs, controllers) { - // gridUtil.logDebug('viewport post-link'); - - var uiGridCtrl = controllers[0]; - var containerCtrl = controllers[1]; - - $scope.containerCtrl = containerCtrl; - - var rowContainer = containerCtrl.rowContainer; - var colContainer = containerCtrl.colContainer; - - var grid = uiGridCtrl.grid; - - $scope.grid = uiGridCtrl.grid; - - // Put the containers in scope so we can get rows and columns from them - $scope.rowContainer = containerCtrl.rowContainer; - $scope.colContainer = containerCtrl.colContainer; - - // Register this viewport with its container - containerCtrl.viewport = $elm; - - /** - * @ngdoc function - * @name customScroller - * @methodOf ui.grid.class:GridOptions - * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default. - * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers - * as this allows you to do that. - * - * - *
    Example
    - *
    -           *   $scope.gridOptions = {
    -           *       customScroller: function myScrolling(uiGridViewport, scrollHandler) {
    -           *           uiGridViewport.on('scroll', function myScrollingOverride(event) {
    -           *               // Do something here
    -           *
    -           *               scrollHandler(event);
    -           *           });
    -           *       }
    -           *   };
    -           * 
    - * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid). - * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid). - */ - if (grid && grid.options && grid.options.customScroller) { - grid.options.customScroller($elm, scrollHandler); - } else { - $elm.on('scroll', scrollHandler); - } - - var ignoreScroll = false; - - function scrollHandler(evt) { - //Leaving in this commented code in case it can someday be used - //It does improve performance, but because the horizontal scroll is normalized, - // using this code will lead to the column header getting slightly out of line with columns - // - //if (ignoreScroll && (grid.isScrollingHorizontally || grid.isScrollingHorizontally)) { - // //don't ask for scrollTop if we just set it - // ignoreScroll = false; - // return; - //} - //ignoreScroll = true; - - var newScrollTop = $elm[0].scrollTop; - var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid); - - var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop); - var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft); - - var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll); - scrollEvent.newScrollLeft = newScrollLeft; - scrollEvent.newScrollTop = newScrollTop; - if ( horizScrollPercentage > -1 ){ - scrollEvent.x = { percentage: horizScrollPercentage }; - } - - if ( vertScrollPercentage > -1 ){ - scrollEvent.y = { percentage: vertScrollPercentage }; - } - - grid.scrollContainers($scope.$parent.containerId, scrollEvent); - } - - if ($scope.$parent.bindScrollVertical) { - grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll); - } - - if ($scope.$parent.bindScrollHorizontal) { - grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll); - grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader); - grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter); - } - - function syncVerticalScroll(scrollEvent){ - containerCtrl.prevScrollArgs = scrollEvent; - var newScrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport); - $elm[0].scrollTop = newScrollTop; - - } - - function syncHorizontalScroll(scrollEvent){ - containerCtrl.prevScrollArgs = scrollEvent; - var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); - $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); - } - - function syncHorizontalHeader(scrollEvent){ - var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); - if (containerCtrl.headerViewport) { - containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); - } - } - - function syncHorizontalFooter(scrollEvent){ - var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); - if (containerCtrl.footerViewport) { - containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); - } - } - - $scope.$on('$destroy', function unbindEvents() { - $elm.off(); - }); - }, - controller: ['$scope', function ($scope) { - this.rowStyle = function (index) { - var rowContainer = $scope.rowContainer; - var colContainer = $scope.colContainer; - - var styles = {}; - - if (rowContainer.currentTopRow !== 0){ - //top offset based on hidden rows count - var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)"; - styles['transform'] = translateY; - styles['-webkit-transform'] = translateY; - styles['-ms-transform'] = translateY; - } - - if (colContainer.currentFirstColumn !== 0) { - if (colContainer.grid.isRTL()) { - styles['margin-right'] = colContainer.columnOffset + 'px'; - } - else { - styles['margin-left'] = colContainer.columnOffset + 'px'; - } - } - - return styles; - }; - }] - }; - } - ]); - -})(); diff --git a/src/js/core/directives/ui-grid-visible.js b/src/js/core/directives/ui-grid-visible.js deleted file mode 100644 index 2328b225b2..0000000000 --- a/src/js/core/directives/ui-grid-visible.js +++ /dev/null @@ -1,13 +0,0 @@ -(function() { - -angular.module('ui.grid') -.directive('uiGridVisible', function uiGridVisibleAction() { - return function ($scope, $elm, $attr) { - $scope.$watch($attr.uiGridVisible, function (visible) { - // $elm.css('visibility', visible ? 'visible' : 'hidden'); - $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible'); - }); - }; -}); - -})(); \ No newline at end of file diff --git a/src/js/core/directives/ui-grid.js b/src/js/core/directives/ui-grid.js deleted file mode 100644 index b9467c9f36..0000000000 --- a/src/js/core/directives/ui-grid.js +++ /dev/null @@ -1,349 +0,0 @@ -(function () { - 'use strict'; - - angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants', - 'gridClassFactory', '$parse', '$compile', - function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants, - gridClassFactory, $parse, $compile) { - // gridUtil.logDebug('ui-grid controller'); - var self = this; - var deregFunctions = []; - - self.grid = gridClassFactory.createGrid($scope.uiGrid); - - //assign $scope.$parent if appScope not already assigned - self.grid.appScope = self.grid.appScope || $scope.$parent; - - $elm.addClass('grid' + self.grid.id); - self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl'; - - - // angular.extend(self.grid.options, ); - - //all properties of grid are available on scope - $scope.grid = self.grid; - - if ($attrs.uiGridColumns) { - deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) { - self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value; - self.grid.buildColumns() - .then(function(){ - self.grid.preCompileCellTemplates(); - - self.grid.refreshCanvas(true); - }).catch(angular.noop); - }) ); - } - - // prevents an error from being thrown when the array is not defined yet and fastWatch is on - function getSize(array) { - return array ? array.length : 0; - } - - // if fastWatch is set we watch only the length and the reference, not every individual object - if (self.grid.options.fastWatch) { - self.uiGrid = $scope.uiGrid; - if (angular.isString($scope.uiGrid.data)) { - deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) ); - deregFunctions.push( $scope.$parent.$watch(function() { - if ( self.grid.appScope[$scope.uiGrid.data] ){ - return self.grid.appScope[$scope.uiGrid.data].length; - } else { - return undefined; - } - }, dataWatchFunction) ); - } else { - deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); - deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function(){ dataWatchFunction($scope.uiGrid.data); }) ); - } - deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); - deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function(){ columnDefsWatchFunction($scope.uiGrid.columnDefs); }) ); - } else { - if (angular.isString($scope.uiGrid.data)) { - deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) ); - } else { - deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); - } - deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); - } - - - function columnDefsWatchFunction(n, o) { - if (n && n !== o) { - self.grid.options.columnDefs = $scope.uiGrid.columnDefs; - self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, { - orderByColumnDefs: true, - preCompileCellTemplates: true - }); - } - } - - var mostRecentData; - - function dataWatchFunction(newData) { - // gridUtil.logDebug('dataWatch fired'); - var promises = []; - - if (angular.isString($scope.uiGrid.data)) { - newData = self.grid.appScope[$scope.uiGrid.data]; - } else { - newData = $scope.uiGrid.data; - } - - mostRecentData = newData; - - if (newData) { - // columns length is greater than the number of row header columns, which don't count because they're created automatically - var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0); - - if ( - // If we have no columns - !hasColumns && - // ... and we don't have a ui-grid-columns attribute, which would define columns for us - !$attrs.uiGridColumns && - // ... and we have no pre-defined columns - self.grid.options.columnDefs.length === 0 && - // ... but we DO have data - newData.length > 0 - ) { - // ... then build the column definitions from the data that we have - self.grid.buildColumnDefsFromData(newData); - } - - // If we haven't built columns before and either have some columns defined or some data defined - if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) { - // Build the column set, then pre-compile the column cell templates - promises.push(self.grid.buildColumns() - .then(function() { - self.grid.preCompileCellTemplates(); - }).catch(angular.noop)); - } - - $q.all(promises).then(function() { - // use most recent data, rather than the potentially outdated data passed into watcher handler - self.grid.modifyRows(mostRecentData) - .then(function () { - // if (self.viewport) { - self.grid.redrawInPlace(true); - // } - - $scope.$evalAsync(function() { - self.grid.refreshCanvas(true); - self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW); - }); - }).catch(angular.noop); - }).catch(angular.noop); - } - } - - var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() { - self.grid.refreshCanvas(true); - }); - - $scope.$on('$destroy', function() { - deregFunctions.forEach( function( deregFn ){ deregFn(); }); - styleWatchDereg(); - }); - - self.fireEvent = function(eventName, args) { - args = args || {}; - - // Add the grid to the event arguments if it's not there - if (angular.isUndefined(args.grid)) { - args.grid = self.grid; - } - - $scope.$broadcast(eventName, args); - }; - - self.innerCompile = function innerCompile(elm) { - $compile(elm)($scope); - }; - }]); - -/** - * @ngdoc directive - * @name ui.grid.directive:uiGrid - * @element div - * @restrict EA - * @param {Object} uiGrid Options for the grid to use - * - * @description Create a very basic grid. - * - * @example - - - var app = angular.module('app', ['ui.grid']); - - app.controller('MainCtrl', ['$scope', function ($scope) { - $scope.data = [ - { name: 'Bob', title: 'CEO' }, - { name: 'Frank', title: 'Lowly Developer' } - ]; - }]); - - -
    -
    -
    -
    -
    - */ -angular.module('ui.grid').directive('uiGrid', uiGridDirective); - -uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants']; -function uiGridDirective($window, gridUtil, uiGridConstants) { - return { - templateUrl: 'ui-grid/ui-grid', - scope: { - uiGrid: '=' - }, - replace: true, - transclude: true, - controller: 'uiGridController', - compile: function () { - return { - post: function ($scope, $elm, $attrs, uiGridCtrl) { - var grid = uiGridCtrl.grid; - // Initialize scrollbars (TODO: move to controller??) - uiGridCtrl.scrollbars = []; - grid.element = $elm; - - - // See if the grid has a rendered width, if not, wait a bit and try again - var sizeCheckInterval = 100; // ms - var maxSizeChecks = 20; // 2 seconds total - var sizeChecks = 0; - - // Setup (event listeners) the grid - setup(); - - // And initialize it - init(); - - // Mark rendering complete so API events can happen - grid.renderingComplete(); - - // If the grid doesn't have size currently, wait for a bit to see if it gets size - checkSize(); - - /*-- Methods --*/ - - function checkSize() { - // If the grid has no width and we haven't checked more than times, check again in milliseconds - if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) { - setTimeout(checkSize, sizeCheckInterval); - sizeChecks++; - } else { - $scope.$applyAsync(init); - } - } - - // Setup event listeners and watchers - function setup() { - var deregisterLeftWatcher, deregisterRightWatcher; - - // Bind to window resize events - angular.element($window).on('resize', gridResize); - - // Unbind from window resize events when the grid is destroyed - $elm.on('$destroy', function () { - angular.element($window).off('resize', gridResize); - deregisterLeftWatcher(); - deregisterRightWatcher(); - }); - - // If we add a left container after render, we need to watch and react - deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) { - if (newValue === oldValue) { - return; - } - grid.refreshCanvas(true); - }); - - // If we add a right container after render, we need to watch and react - deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) { - if (newValue === oldValue) { - return; - } - grid.refreshCanvas(true); - }); - } - - // Initialize the directive - function init() { - grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); - - // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from - grid.canvasWidth = uiGridCtrl.grid.gridWidth; - - grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); - - // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows - if (grid.gridHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) { - autoAdjustHeight(); - } - - // Run initial canvas refresh - grid.refreshCanvas(true); - } - - // Set the grid's height ourselves in the case that its height would be unusably small - function autoAdjustHeight() { - // Figure out the new height - var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight; - var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0; - var footerHeight = grid.calcFooterHeight(); - - var scrollbarHeight = 0; - if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) { - scrollbarHeight = gridUtil.getScrollbarWidth(); - } - - var maxNumberOfFilters = 0; - // Calculates the maximum number of filters in the columns - angular.forEach(grid.options.columnDefs, function(col) { - if (col.hasOwnProperty('filter')) { - if (maxNumberOfFilters < 1) { - maxNumberOfFilters = 1; - } - } - else if (col.hasOwnProperty('filters')) { - if (maxNumberOfFilters < col.filters.length) { - maxNumberOfFilters = col.filters.length; - } - } - }); - - if (grid.options.enableFiltering && !maxNumberOfFilters) { - var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) { - return col.enableFiltering === false; - }); - - if (!allColumnsHaveFilteringTurnedOff) { - maxNumberOfFilters = 1; - } - } - - var filterHeight = maxNumberOfFilters * headerHeight; - - var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight; - - $elm.css('height', newHeight + 'px'); - - grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); - } - - // Resize the grid on window resize events - function gridResize() { - grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); - grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); - - grid.refreshCanvas(true); - } - } - }; - } - }; -} -})(); diff --git a/src/js/core/directives/ui-pinned-container.js b/src/js/core/directives/ui-pinned-container.js deleted file mode 100644 index f8150ffcb4..0000000000 --- a/src/js/core/directives/ui-pinned-container.js +++ /dev/null @@ -1,100 +0,0 @@ -(function(){ - 'use strict'; - - // TODO: rename this file to ui-grid-pinned-container.js - - angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) { - return { - restrict: 'EA', - replace: true, - template: '
    ', - scope: { - side: '=uiGridPinnedContainer' - }, - require: '^uiGrid', - compile: function compile() { - return { - post: function ($scope, $elm, $attrs, uiGridCtrl) { - // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link'); - - var grid = uiGridCtrl.grid; - - var myWidth = 0; - - $elm.addClass('ui-grid-pinned-container-' + $scope.side); - - // Monkey-patch the viewport width function - if ($scope.side === 'left' || $scope.side === 'right') { - grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth; - } - - function monkeyPatchedGetViewportWidth() { - /*jshint validthis: true */ - var self = this; - - var viewportWidth = 0; - self.visibleColumnCache.forEach(function (column) { - viewportWidth += column.drawnWidth; - }); - - var adjustment = self.getViewportAdjustment(); - - viewportWidth = viewportWidth + adjustment.width; - - return viewportWidth; - } - - function updateContainerWidth() { - if ($scope.side === 'left' || $scope.side === 'right') { - var cols = grid.renderContainers[$scope.side].visibleColumnCache; - var width = 0; - for (var i = 0; i < cols.length; i++) { - var col = cols[i]; - width += col.drawnWidth || col.width || 0; - } - - return width; - } - } - - function updateContainerDimensions() { - var ret = ''; - - // Column containers - if ($scope.side === 'left' || $scope.side === 'right') { - myWidth = updateContainerWidth(); - - // gridUtil.logDebug('myWidth', myWidth); - - // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it - $elm.attr('style', null); - - // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; - - ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } '; - } - - return ret; - } - - grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { - myWidth = updateContainerWidth(); - - // Subtract our own width - adjustment.width -= myWidth; - adjustment.side = $scope.side; - - return adjustment; - }); - - // Register style computation to adjust for columns in `side`'s render container - grid.registerStyleComputation({ - priority: 15, - func: updateContainerDimensions - }); - } - }; - } - }; - }]); -})(); \ No newline at end of file diff --git a/src/js/core/factories/Grid.js b/src/js/core/factories/Grid.js deleted file mode 100644 index dbc8b63590..0000000000 --- a/src/js/core/factories/Grid.js +++ /dev/null @@ -1,2609 +0,0 @@ -(function(){ - -angular.module('ui.grid') -.factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent', - function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) { - - /** - * @ngdoc object - * @name ui.grid.core.api:PublicApi - * @description Public Api for the core grid features - * - */ - - /** - * @ngdoc function - * @name ui.grid.class:Grid - * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in - * this prototype. One instance of Grid is created per Grid directive instance. - * @param {object} options Object map of options to pass into the grid. An 'id' property is expected. - */ - var Grid = function Grid(options) { - var self = this; - // Get the id out of the options, then remove it - if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) { - if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) { - throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.'); - } - } - else { - throw new Error('No ID provided. An ID must be given when creating a grid.'); - } - - self.id = options.id; - delete options.id; - - // Get default options - self.options = GridOptions.initialize( options ); - - /** - * @ngdoc object - * @name appScope - * @propertyOf ui.grid.class:Grid - * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller - *
    - * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference - */ - self.appScope = self.options.appScopeProvider; - - self.headerHeight = self.options.headerRowHeight; - - - /** - * @ngdoc object - * @name footerHeight - * @propertyOf ui.grid.class:Grid - * @description returns the total footer height gridFooter + columnFooter - */ - self.footerHeight = self.calcFooterHeight(); - - - /** - * @ngdoc object - * @name columnFooterHeight - * @propertyOf ui.grid.class:Grid - * @description returns the total column footer height - */ - self.columnFooterHeight = self.calcColumnFooterHeight(); - - self.rtl = false; - self.gridHeight = 0; - self.gridWidth = 0; - self.columnBuilders = []; - self.rowBuilders = []; - self.rowsProcessors = []; - self.columnsProcessors = []; - self.styleComputations = []; - self.viewportAdjusters = []; - self.rowHeaderColumns = []; - self.dataChangeCallbacks = {}; - self.verticalScrollSyncCallBackFns = {}; - self.horizontalScrollSyncCallBackFns = {}; - - // self.visibleRowCache = []; - - // Set of 'render' containers for self grid, which can render sets of rows - self.renderContainers = {}; - - // Create a - self.renderContainers.body = new GridRenderContainer('body', self); - - self.cellValueGetterCache = {}; - - // Cached function to use with custom row templates - self.getRowTemplateFn = null; - - - //representation of the rows on the grid. - //these are wrapped references to the actual data rows (options.data) - self.rows = []; - - //represents the columns on the grid - self.columns = []; - - /** - * @ngdoc boolean - * @name isScrollingVertically - * @propertyOf ui.grid.class:Grid - * @description set to true when Grid is scrolling vertically. Set to false via debounced method - */ - self.isScrollingVertically = false; - - /** - * @ngdoc boolean - * @name isScrollingHorizontally - * @propertyOf ui.grid.class:Grid - * @description set to true when Grid is scrolling horizontally. Set to false via debounced method - */ - self.isScrollingHorizontally = false; - - /** - * @ngdoc property - * @name scrollDirection - * @propertyOf ui.grid.class:Grid - * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection} - * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling. - * Set to NONE via debounced method - */ - self.scrollDirection = uiGridConstants.scrollDirection.NONE; - - //if true, grid will not respond to any scroll events - self.disableScrolling = false; - - - function vertical (scrollEvent) { - self.isScrollingVertically = false; - self.api.core.raise.scrollEnd(scrollEvent); - self.scrollDirection = uiGridConstants.scrollDirection.NONE; - } - - var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce); - var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0); - - function horizontal (scrollEvent) { - self.isScrollingHorizontally = false; - self.api.core.raise.scrollEnd(scrollEvent); - self.scrollDirection = uiGridConstants.scrollDirection.NONE; - } - - var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce); - var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0); - - - /** - * @ngdoc function - * @name flagScrollingVertically - * @methodOf ui.grid.class:Grid - * @description sets isScrollingVertically to true and sets it to false in a debounced function - */ - self.flagScrollingVertically = function(scrollEvent) { - if (!self.isScrollingVertically && !self.isScrollingHorizontally) { - self.api.core.raise.scrollBegin(scrollEvent); - } - self.isScrollingVertically = true; - if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { - debouncedVerticalMinDelay(scrollEvent); - } - else { - debouncedVertical(scrollEvent); - } - }; - - /** - * @ngdoc function - * @name flagScrollingHorizontally - * @methodOf ui.grid.class:Grid - * @description sets isScrollingHorizontally to true and sets it to false in a debounced function - */ - self.flagScrollingHorizontally = function(scrollEvent) { - if (!self.isScrollingVertically && !self.isScrollingHorizontally) { - self.api.core.raise.scrollBegin(scrollEvent); - } - self.isScrollingHorizontally = true; - if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { - debouncedHorizontalMinDelay(scrollEvent); - } - else { - debouncedHorizontal(scrollEvent); - } - }; - - self.scrollbarHeight = 0; - self.scrollbarWidth = 0; - if (self.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) { - self.scrollbarHeight = gridUtil.getScrollbarWidth(); - } - - if (self.options.enableVerticalScrollbar === uiGridConstants.scrollbars.ALWAYS) { - self.scrollbarWidth = gridUtil.getScrollbarWidth(); - } - - - - self.api = new GridApi(self); - - /** - * @ngdoc function - * @name refresh - * @methodOf ui.grid.core.api:PublicApi - * @description Refresh the rendered grid on screen. - * The refresh method re-runs both the columnProcessors and the - * rowProcessors, as well as calling refreshCanvas to update all - * the grid sizing. In general you should prefer to use queueGridRefresh - * instead, which is basically a debounced version of refresh. - * - * If you only want to resize the grid, not regenerate all the rows - * and columns, you should consider directly calling refreshCanvas instead. - * - * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed - */ - self.api.registerMethod( 'core', 'refresh', this.refresh ); - - /** - * @ngdoc function - * @name queueGridRefresh - * @methodOf ui.grid.core.api:PublicApi - * @description Request a refresh of the rendered grid on screen, if multiple - * calls to queueGridRefresh are made within a digest cycle only one will execute. - * The refresh method re-runs both the columnProcessors and the - * rowProcessors, as well as calling refreshCanvas to update all - * the grid sizing. In general you should prefer to use queueGridRefresh - * instead, which is basically a debounced version of refresh. - * - */ - self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh ); - - /** - * @ngdoc function - * @name refreshRows - * @methodOf ui.grid.core.api:PublicApi - * @description Runs only the rowProcessors, columns remain as they were. - * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing. - * @returns {promise} promise that is resolved when render completes? - * - */ - self.api.registerMethod( 'core', 'refreshRows', this.refreshRows ); - - /** - * @ngdoc function - * @name queueRefresh - * @methodOf ui.grid.core.api:PublicApi - * @description Requests execution of refreshCanvas, if multiple requests are made - * during a digest cycle only one will run. RefreshCanvas updates the grid sizing. - * @returns {promise} promise that is resolved when render completes? - * - */ - self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh ); - - /** - * @ngdoc function - * @name handleWindowResize - * @methodOf ui.grid.core.api:PublicApi - * @description Trigger a grid resize, normally this would be picked - * up by a watch on window size, but in some circumstances it is necessary - * to call this manually - * @returns {promise} promise that is resolved when render completes? - * - */ - self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize ); - - - /** - * @ngdoc function - * @name addRowHeaderColumn - * @methodOf ui.grid.core.api:PublicApi - * @description adds a row header column to the grid - * @param {object} column def - * @param {number} order Determines order of header column on grid. Lower order means header - * is positioned to the left of higher order headers - * - */ - self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn ); - - /** - * @ngdoc function - * @name scrollToIfNecessary - * @methodOf ui.grid.core.api:PublicApi - * @description Scrolls the grid to make a certain row and column combo visible, - * in the case that it is not completely visible on the screen already. - * @param {GridRow} gridRow row to make visible - * @param {GridCol} gridCol column to make visible - * @returns {promise} a promise that is resolved when scrolling is complete - * - */ - self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} ); - - /** - * @ngdoc function - * @name scrollTo - * @methodOf ui.grid.core.api:PublicApi - * @description Scroll the grid such that the specified - * row and column is in view - * @param {object} rowEntity gridOptions.data[] array instance to make visible - * @param {object} colDef to make visible - * @returns {promise} a promise that is resolved after any scrolling is finished - */ - self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} ); - - /** - * @ngdoc function - * @name registerRowsProcessor - * @methodOf ui.grid.core.api:PublicApi - * @description - * Register a "rows processor" function. When the rows are updated, - * the grid calls each registered "rows processor", which has a chance - * to alter the set of rows (sorting, etc) as long as the count is not - * modified. - * - * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which - * is run in the context of the grid (i.e. this for the function will be the grid), and must - * return the updated rows list, which is passed to the next processor in the chain - * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room - * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier. - * - * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100, - * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last) - * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last) - */ - self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor ); - - /** - * @ngdoc function - * @name registerColumnsProcessor - * @methodOf ui.grid.core.api:PublicApi - * @description - * Register a "columns processor" function. When the columns are updated, - * the grid calls each registered "columns processor", which has a chance - * to alter the set of columns as long as the count is not - * modified. - * - * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which - * is run in the context of the grid (i.e. this for the function will be the grid), and must - * return the updated columns list, which is passed to the next processor in the chain - * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room - * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier. - * - * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last) - */ - self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor ); - - - - /** - * @ngdoc function - * @name sortHandleNulls - * @methodOf ui.grid.core.api:PublicApi - * @description A null handling method that can be used when building custom sort - * functions - * @example - *
    -     *   mySortFn = function(a, b) {
    -     *   var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
    -     *   if ( nulls !== null ){
    -     *     return nulls;
    -     *   } else {
    -     *     // your code for sorting here
    -     *   };
    -     * 
    - * @param {object} a sort value a - * @param {object} b sort value b - * @returns {number} null if there were no nulls/undefineds, otherwise returns - * a sort value that should be passed back from the sort function - * - */ - self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls ); - - - /** - * @ngdoc function - * @name sortChanged - * @methodOf ui.grid.core.api:PublicApi - * @description The sort criteria on one or more columns has - * changed. Provides as parameters the grid and the output of - * getColumnSorting, which is an array of gridColumns - * that have sorting on them, sorted in priority order. - * - * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. - * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of - * columns with sorts on them, in priority order. - * - * @example - *
    -     *      gridApi.core.on.sortChanged( $scope, function(grid, sortColumns){
    -     *        // do something
    -     *      });
    -     * 
    - */ - self.api.registerEvent( 'core', 'sortChanged' ); - - /** - * @ngdoc function - * @name columnVisibilityChanged - * @methodOf ui.grid.core.api:PublicApi - * @description The visibility of a column has changed, - * the column itself is passed out as a parameter of the event. - * - * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. - * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed. - * - * @example - *
    -     *      gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
    -     *        // do something
    -     *      } );
    -     * 
    - */ - self.api.registerEvent( 'core', 'columnVisibilityChanged' ); - - /** - * @ngdoc method - * @name notifyDataChange - * @methodOf ui.grid.core.api:PublicApi - * @description Notify the grid that a data or config change has occurred, - * where that change isn't something the grid was otherwise noticing. This - * might be particularly relevant where you've changed values within the data - * and you'd like cell classes to be re-evaluated, or changed config within - * the columnDef and you'd like headerCellClasses to be re-evaluated. - * @param {string} type one of the - * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} - * values (ALL, ROW, EDIT, COLUMN), which tells us which refreshes to fire. - * - */ - self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange ); - - /** - * @ngdoc method - * @name clearAllFilters - * @methodOf ui.grid.core.api:PublicApi - * @description Clears all filters and optionally refreshes the visible rows. - * @param {object} refreshRows Defaults to true. - * @param {object} clearConditions Defaults to false. - * @param {object} clearFlags Defaults to false. - * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing. - */ - self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters); - - self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]); - self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]); - self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]); - - self.registerStyleComputation({ - priority: 10, - func: self.getFooterStyles - }); - }; - - Grid.prototype.calcFooterHeight = function () { - if (!this.hasFooter()) { - return 0; - } - - var height = 0; - if (this.options.showGridFooter) { - height += this.options.gridFooterHeight; - } - - height += this.calcColumnFooterHeight(); - - return height; - }; - - Grid.prototype.calcColumnFooterHeight = function () { - var height = 0; - - if (this.options.showColumnFooter) { - height += this.options.columnFooterHeight; - } - - return height; - }; - - Grid.prototype.getFooterStyles = function () { - var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }'; - style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }'; - return style; - }; - - Grid.prototype.hasFooter = function () { - return this.options.showGridFooter || this.options.showColumnFooter; - }; - - /** - * @ngdoc function - * @name isRTL - * @methodOf ui.grid.class:Grid - * @description Returns true if grid is RightToLeft - */ - Grid.prototype.isRTL = function () { - return this.rtl; - }; - - - /** - * @ngdoc function - * @name registerColumnBuilder - * @methodOf ui.grid.class:Grid - * @description When the build creates columns from column definitions, the columnbuilders will be called to add - * additional properties to the column. - * @param {function(colDef, col, gridOptions)} columnBuilder function to be called - */ - Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) { - this.columnBuilders.push(columnBuilder); - }; - - /** - * @ngdoc function - * @name unregisterColumnBulder - * @methodOf ui.grid.class:Grid - * @description When the build creates columns from column definitions, the columnbuilders will be called to add - * additional properties to the column. - * @param {function(colDef, col, gridOptions)} columnBuilder function to be called - */ - Grid.prototype.unregisterColumnBulder = function unregisterColumnBulder(columnBuilder) { - var builder = this.columnBuilders.indexOf(columnBuilder); - - if (builder !== -1) { - this.columnBuilders.splice(builder, 1); - } - }; - - /** - * @ngdoc function - * @name buildColumnDefsFromData - * @methodOf ui.grid.class:Grid - * @description Populates columnDefs from the provided data - * @param {function(colDef, col, gridOptions)} rowBuilder function to be called - */ - Grid.prototype.buildColumnDefsFromData = function (dataRows){ - this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties); - }; - - /** - * @ngdoc function - * @name registerRowBuilder - * @methodOf ui.grid.class:Grid - * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add - * additional properties to the row. - * @param {function(row, gridOptions)} rowBuilder function to be called - */ - Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) { - this.rowBuilders.push(rowBuilder); - }; - - - /** - * @ngdoc function - * @name registerDataChangeCallback - * @methodOf ui.grid.class:Grid - * @description When a data change occurs, the data change callbacks of the specified type - * will be called. The rules are: - * - * - when the data watch fires, that is considered a ROW change (the data watch only notices - * added or removed rows) - * - when the api is called to inform us of a change, the declared type of that change is used - * - when a cell edit completes, the EDIT callbacks are triggered - * - when the columnDef watch fires, the COLUMN callbacks are triggered - * - when the options watch fires, the OPTIONS callbacks are triggered - * - * For a given event: - * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks - * - ROW calls ROW and ALL callbacks - * - EDIT calls EDIT and ALL callbacks - * - COLUMN calls COLUMN and ALL callbacks - * - OPTIONS calls OPTIONS and ALL callbacks - * - * @param {function(grid)} callback function to be called - * @param {array} types the types of data change you want to be informed of. Values from - * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} - * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL - * @returns {function} deregister function - a function that can be called to deregister this callback - */ - Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) { - var uid = gridUtil.nextUid(); - if ( !types ){ - types = [uiGridConstants.dataChange.ALL]; - } - if ( !Array.isArray(types)){ - gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types ); - } - this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this:_this }; - - var self = this; - var deregisterFunction = function() { - delete self.dataChangeCallbacks[uid]; - }; - return deregisterFunction; - }; - - /** - * @ngdoc function - * @name callDataChangeCallbacks - * @methodOf ui.grid.class:Grid - * @description Calls the callbacks based on the type of data change that - * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the - * event type is matching, or if the type is ALL. - * @param {string} type the type of event that occurred - one of the - * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} - * values (ALL, ROW, EDIT, COLUMN, OPTIONS) - */ - Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) { - angular.forEach( this.dataChangeCallbacks, function( callback, uid ){ - if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 || - callback.types.indexOf( type ) !== -1 || - type === uiGridConstants.dataChange.ALL ) { - if (callback._this) { - callback.callback.apply(callback._this, this, options); - } - else { - callback.callback(this, options); - } - } - }, this); - }; - - /** - * @ngdoc function - * @name notifyDataChange - * @methodOf ui.grid.class:Grid - * @description Notifies us that a data change has occurred, used in the public - * api for users to tell us when they've changed data or some other event that - * our watches cannot pick up - * @param {string} type the type of event that occurred - one of the - * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN) - */ - Grid.prototype.notifyDataChange = function notifyDataChange(type) { - var constants = uiGridConstants.dataChange; - if ( type === constants.ALL || - type === constants.COLUMN || - type === constants.EDIT || - type === constants.ROW || - type === constants.OPTIONS ){ - this.callDataChangeCallbacks( type ); - } else { - gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type); - } - }; - - - /** - * @ngdoc function - * @name columnRefreshCallback - * @methodOf ui.grid.class:Grid - * @description refreshes the grid when a column refresh - * is notified, which triggers handling of the visible flag. - * This is called on uiGridConstants.dataChange.COLUMN, and is - * registered as a dataChangeCallback in grid.js - * @param {object} grid The grid object. - * @param {object} options Any options passed into the callback. - */ - Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options){ - grid.buildColumns(options); - grid.queueGridRefresh(); - }; - - - /** - * @ngdoc function - * @name processRowsCallback - * @methodOf ui.grid.class:Grid - * @description calls the row processors, specifically - * intended to reset the sorting when an edit is called, - * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT - * @param {string} name column name - */ - Grid.prototype.processRowsCallback = function processRowsCallback( grid ){ - grid.queueGridRefresh(); - }; - - - /** - * @ngdoc function - * @name updateFooterHeightCallback - * @methodOf ui.grid.class:Grid - * @description recalculates the footer height, - * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS - * @param {string} name column name - */ - Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ){ - grid.footerHeight = grid.calcFooterHeight(); - grid.columnFooterHeight = grid.calcColumnFooterHeight(); - }; - - - /** - * @ngdoc function - * @name getColumn - * @methodOf ui.grid.class:Grid - * @description returns a grid column for the column name - * @param {string} name column name - */ - Grid.prototype.getColumn = function getColumn(name) { - var columns = this.columns.filter(function (column) { - return column.colDef.name === name; - }); - return columns.length > 0 ? columns[0] : null; - }; - - /** - * @ngdoc function - * @name getColDef - * @methodOf ui.grid.class:Grid - * @description returns a grid colDef for the column name - * @param {string} name column.field - */ - Grid.prototype.getColDef = function getColDef(name) { - var colDefs = this.options.columnDefs.filter(function (colDef) { - return colDef.name === name; - }); - return colDefs.length > 0 ? colDefs[0] : null; - }; - - /** - * @ngdoc function - * @name assignTypes - * @methodOf ui.grid.class:Grid - * @description uses the first row of data to assign colDef.type for any types not defined. - */ - /** - * @ngdoc property - * @name type - * @propertyOf ui.grid.class:GridOptions.columnDef - * @description the type of the column, used in sorting. If not provided then the - * grid will guess the type. Add this only if the grid guessing is not to your - * satisfaction. One of: - * - 'string' - * - 'boolean' - * - 'number' - * - 'date' - * - 'object' - * - 'numberStr' - * Note that if you choose date, your dates should be in a javascript date type - * - */ - Grid.prototype.assignTypes = function(){ - var self = this; - self.options.columnDefs.forEach(function (colDef, index) { - - //Assign colDef type if not specified - if (!colDef.type) { - var col = new GridColumn(colDef, index, self); - var firstRow = self.rows.length > 0 ? self.rows[0] : null; - if (firstRow) { - colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col)); - } - else { - colDef.type = 'string'; - } - } - }); - }; - - - /** - * @ngdoc function - * @name isRowHeaderColumn - * @methodOf ui.grid.class:Grid - * @description returns true if the column is a row Header - * @param {object} column column - */ - Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) { - return this.rowHeaderColumns.indexOf(column) !== -1; - }; - - /** - * @ngdoc function - * @name addRowHeaderColumn - * @methodOf ui.grid.class:Grid - * @description adds a row header column to the grid - * @param {object} colDef Column definition object. - * @param {float} order Number that indicates where the column should be placed in the grid. - * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve - * performance of the grid during initial load. - */ - Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) { - var self = this; - - //default order - if (order === undefined) { - order = 0; - } - - var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self); - rowHeaderCol.isRowHeader = true; - if (self.isRTL()) { - self.createRightContainer(); - rowHeaderCol.renderContainer = 'right'; - } - else { - self.createLeftContainer(); - rowHeaderCol.renderContainer = 'left'; - } - - // relies on the default column builder being first in array, as it is instantiated - // as part of grid creation - self.columnBuilders[0](colDef,rowHeaderCol,self.options) - .then(function(){ - rowHeaderCol.enableFiltering = false; - rowHeaderCol.enableSorting = false; - rowHeaderCol.enableHiding = false; - rowHeaderCol.headerPriority = order; - self.rowHeaderColumns.push(rowHeaderCol); - self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) { - return a.headerPriority - b.headerPriority; - }); - - if (!stopColumnBuild) { - self.buildColumns() - .then(function() { - self.preCompileCellTemplates(); - self.queueGridRefresh(); - }).catch(angular.noop); - } - }).catch(angular.noop); - }; - - /** - * @ngdoc function - * @name getOnlyDataColumns - * @methodOf ui.grid.class:Grid - * @description returns all columns except for rowHeader columns - */ - Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() { - var self = this; - var cols = []; - self.columns.forEach(function (col) { - if (self.rowHeaderColumns.indexOf(col) === -1) { - cols.push(col); - } - }); - return cols; - }; - - /** - * @ngdoc function - * @name buildColumns - * @methodOf ui.grid.class:Grid - * @description creates GridColumn objects from the columnDefinition. Calls each registered - * columnBuilder to further process the column - * @param {object} options An object contains options to use when building columns - * - * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions. - * - * @returns {Promise} a promise to load any needed column resources - */ - Grid.prototype.buildColumns = function buildColumns(opts) { - var options = { - orderByColumnDefs: false - }; - - angular.extend(options, opts); - - // gridUtil.logDebug('buildColumns'); - var self = this; - var builderPromises = []; - var headerOffset = self.rowHeaderColumns.length; - var i; - - // Remove any columns for which a columnDef cannot be found - // Deliberately don't use forEach, as it doesn't like splice being called in the middle - // Also don't cache columns.length, as it will change during this operation - for (i = 0; i < self.columns.length; i++){ - if (!self.getColDef(self.columns[i].name)) { - self.columns.splice(i, 1); - i--; - } - } - - //add row header columns to the grid columns array _after_ columns without columnDefs have been removed - //rowHeaderColumns is ordered by priority so insert in reverse - for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) { - self.columns.unshift(self.rowHeaderColumns[j]); - } - - - - // look at each column def, and update column properties to match. If the column def - // doesn't have a column, then splice in a new gridCol - self.options.columnDefs.forEach(function (colDef, index) { - self.preprocessColDef(colDef); - var col = self.getColumn(colDef.name); - - if (!col) { - col = new GridColumn(colDef, gridUtil.nextUid(), self); - self.columns.splice(index + headerOffset, 0, col); - } - else { - // tell updateColumnDef that the column was pre-existing - col.updateColumnDef(colDef, false); - } - - self.columnBuilders.forEach(function (builder) { - builderPromises.push(builder.call(self, colDef, col, self.options)); - }); - }); - - /*** Reorder columns if necessary ***/ - if (!!options.orderByColumnDefs) { - // Create a shallow copy of the columns as a cache - var columnCache = self.columns.slice(0); - - // We need to allow for the "row headers" when mapping from the column defs array to the columns array - // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0] - - // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then - // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result - var len = Math.min(self.options.columnDefs.length, self.columns.length); - for (i = 0; i < len; i++) { - // If the column at this index has a different name than the column at the same index in the column defs... - if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) { - // Replace the one in the cache with the appropriate column - columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name); - } - else { - // Otherwise just copy over the one from the initial columns - columnCache[i + headerOffset] = self.columns[i + headerOffset]; - } - } - - // Empty out the columns array, non-destructively - self.columns.length = 0; - - // And splice in the updated, ordered columns from the cache - Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache)); - } - - return $q.all(builderPromises).then(function(){ - if (self.rows.length > 0){ - self.assignTypes(); - } - if (options.preCompileCellTemplates) { - self.preCompileCellTemplates(); - } - }).catch(angular.noop); - }; - - Grid.prototype.preCompileCellTemplate = function(col) { - var self = this; - var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col)); - html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); - - var compiledElementFn = $compile(html); - col.compiledElementFn = compiledElementFn; - - if (col.compiledElementFnDefer) { - col.compiledElementFnDefer.resolve(col.compiledElementFn); - } - }; - -/** - * @ngdoc function - * @name preCompileCellTemplates - * @methodOf ui.grid.class:Grid - * @description precompiles all cell templates - */ - Grid.prototype.preCompileCellTemplates = function() { - var self = this; - self.columns.forEach(function (col) { - if ( col.cellTemplate ){ - self.preCompileCellTemplate( col ); - } else if ( col.cellTemplatePromise ){ - col.cellTemplatePromise.then( function() { - self.preCompileCellTemplate( col ); - }).catch(angular.noop); - } - }); - }; - - /** - * @ngdoc function - * @name getGridQualifiedColField - * @methodOf ui.grid.class:Grid - * @description Returns the $parse-able accessor for a column within its $scope - * @param {GridColumn} col col object - */ - Grid.prototype.getQualifiedColField = function (col) { - var base = 'row.entity'; - if ( col.field === uiGridConstants.ENTITY_BINDING ) { - return base; - } - return gridUtil.preEval(base + '.' + col.field); - }; - - /** - * @ngdoc function - * @name createLeftContainer - * @methodOf ui.grid.class:Grid - * @description creates the left render container if it doesn't already exist - */ - Grid.prototype.createLeftContainer = function() { - if (!this.hasLeftContainer()) { - this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true }); - } - }; - - /** - * @ngdoc function - * @name createRightContainer - * @methodOf ui.grid.class:Grid - * @description creates the right render container if it doesn't already exist - */ - Grid.prototype.createRightContainer = function() { - if (!this.hasRightContainer()) { - this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true }); - } - }; - - /** - * @ngdoc function - * @name hasLeftContainer - * @methodOf ui.grid.class:Grid - * @description returns true if leftContainer exists - */ - Grid.prototype.hasLeftContainer = function() { - return this.renderContainers.left !== undefined; - }; - - /** - * @ngdoc function - * @name hasRightContainer - * @methodOf ui.grid.class:Grid - * @description returns true if rightContainer exists - */ - Grid.prototype.hasRightContainer = function() { - return this.renderContainers.right !== undefined; - }; - - - /** - * undocumented function - * @name preprocessColDef - * @methodOf ui.grid.class:Grid - * @description defaults the name property from field to maintain backwards compatibility with 2.x - * validates that name or field is present - */ - Grid.prototype.preprocessColDef = function preprocessColDef(colDef) { - var self = this; - - if (!colDef.field && !colDef.name) { - throw new Error('colDef.name or colDef.field property is required'); - } - - //maintain backwards compatibility with 2.x - //field was required in 2.x. now name is required - if (colDef.name === undefined && colDef.field !== undefined) { - // See if the column name already exists: - var newName = colDef.field, - counter = 2; - while (self.getColumn(newName)) { - newName = colDef.field + counter.toString(); - counter++; - } - colDef.name = newName; - } - }; - - // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters - Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) { - var self = this; - - var t = []; - for (var i = 0; i < n.length; i++) { - var nV = nAccessor ? n[i][nAccessor] : n[i]; - - var found = false; - for (var j = 0; j < o.length; j++) { - var oV = oAccessor ? o[j][oAccessor] : o[j]; - if (self.options.rowEquality(nV, oV)) { - found = true; - break; - } - } - if (!found) { - t.push(nV); - } - } - - return t; - }; - - /** - * @ngdoc function - * @name getRow - * @methodOf ui.grid.class:Grid - * @description returns the GridRow that contains the rowEntity - * @param {object} rowEntity the gridOptions.data array element instance - * @param {array} lookInRows [optional] the rows to look in - if not provided then - * looks in grid.rows - */ - Grid.prototype.getRow = function getRow(rowEntity, lookInRows) { - var self = this; - - lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows; - - var rows = lookInRows.filter(function (row) { - return self.options.rowEquality(row.entity, rowEntity); - }); - return rows.length > 0 ? rows[0] : null; - }; - - - /** - * @ngdoc function - * @name modifyRows - * @methodOf ui.grid.class:Grid - * @description creates or removes GridRow objects from the newRawData array. Calls each registered - * rowBuilder to further process the row - * @param {array} newRawData Modified set of data - * - * This method aims to achieve three things: - * 1. the resulting rows array is in the same order as the newRawData, we'll call - * rowsProcessors immediately after to sort the data anyway - * 2. if we have row hashing available, we try to use the rowHash to find the row - * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected - * - * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates - * the newRows and newHash - * - * ``` - * newRawData.forEach newEntity - * if (hashing enabled) - * check oldHash for newEntity - * else - * look for old row directly in oldRows - * if !oldRowFound // must be a new row - * create newRow - * append to the newRows and add to newHash - * run the processors - * ``` - * - * Rows are identified using the hashKey if configured. If not configured, then rows - * are identified using the gridOptions.rowEquality function - * - * This method is useful when trying to select rows immediately after loading data without - * using a $timeout/$interval, e.g.: - * - * $scope.gridOptions.data = someData; - * $scope.gridApi.grid.modifyRows($scope.gridOptions.data); - * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); - * - * OR to persist row selection after data update (e.g. rows selected, new data loaded, want - * originally selected rows to be re-selected)) - */ - Grid.prototype.modifyRows = function modifyRows(newRawData) { - var self = this; - var oldRows = self.rows.slice(0); - var oldRowHash = self.rowHashMap || self.createRowHashMap(); - var allRowsSelected = true; - self.rowHashMap = self.createRowHashMap(); - self.rows.length = 0; - - newRawData.forEach( function( newEntity, i ) { - var newRow, oldRow; - - if ( self.options.enableRowHashing ){ - // if hashing is enabled, then this row will be in the hash if we already know about it - oldRow = oldRowHash.get( newEntity ); - } else { - // otherwise, manually search the oldRows to see if we can find this row - oldRow = self.getRow(newEntity, oldRows); - } - - // update newRow to have an entity - if ( oldRow ) { - newRow = oldRow; - newRow.entity = newEntity; - } - - // if we didn't find the row, it must be new, so create it - if ( !newRow ){ - newRow = self.processRowBuilders(new GridRow(newEntity, i, self)); - } - - self.rows.push( newRow ); - self.rowHashMap.put( newEntity, newRow ); - if (!newRow.isSelected) { - allRowsSelected = false; - } - }); - - if (self.selection) { - self.selection.selectAll = allRowsSelected; - } - - self.assignTypes(); - - var p1 = $q.when(self.processRowsProcessors(self.rows)) - .then(function (renderableRows) { - return self.setVisibleRows(renderableRows); - }).catch(angular.noop); - - var p2 = $q.when(self.processColumnsProcessors(self.columns)) - .then(function (renderableColumns) { - return self.setVisibleColumns(renderableColumns); - }).catch(angular.noop); - - return $q.all([p1, p2]); - }; - - - /** - * Private Undocumented Method - * @name addRows - * @methodOf ui.grid.class:Grid - * @description adds the newRawData array of rows to the grid and calls all registered - * rowBuilders. this keyword will reference the grid - */ - Grid.prototype.addRows = function addRows(newRawData) { - var self = this; - - var existingRowCount = self.rows.length; - for (var i = 0; i < newRawData.length; i++) { - var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self)); - - if (self.options.enableRowHashing) { - var found = self.rowHashMap.get(newRow.entity); - if (found) { - found.row = newRow; - } - } - - self.rows.push(newRow); - } - }; - - /** - * @ngdoc function - * @name processRowBuilders - * @methodOf ui.grid.class:Grid - * @description processes all RowBuilders for the gridRow - * @param {GridRow} gridRow reference to gridRow - * @returns {GridRow} the gridRow with all additional behavior added - */ - Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) { - var self = this; - - self.rowBuilders.forEach(function (builder) { - builder.call(self, gridRow, self.options); - }); - - return gridRow; - }; - - /** - * @ngdoc function - * @name registerStyleComputation - * @methodOf ui.grid.class:Grid - * @description registered a styleComputation function - * - * If the function returns a value it will be appended into the grid's ` - -
    -
    - -
    - -
    -
    - -
    - - -
    - -
    - -
    -
    -
    diff --git a/src/templates/ui-grid/uiGridCell.html b/src/templates/ui-grid/uiGridCell.html deleted file mode 100644 index 100e407e83..0000000000 --- a/src/templates/ui-grid/uiGridCell.html +++ /dev/null @@ -1,5 +0,0 @@ -
    - {{COL_FIELD CUSTOM_FILTERS}} -
    diff --git a/src/templates/ui-grid/uiGridColumnMenu.html b/src/templates/ui-grid/uiGridColumnMenu.html deleted file mode 100644 index 370f8ef7a7..0000000000 --- a/src/templates/ui-grid/uiGridColumnMenu.html +++ /dev/null @@ -1,15 +0,0 @@ -
    -
    - -
    -
    \ No newline at end of file diff --git a/src/templates/ui-grid/uiGridFooterCell.html b/src/templates/ui-grid/uiGridFooterCell.html deleted file mode 100644 index eb5cf1bf52..0000000000 --- a/src/templates/ui-grid/uiGridFooterCell.html +++ /dev/null @@ -1,7 +0,0 @@ -
    -
    - {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }} -
    -
    diff --git a/src/templates/ui-grid/uiGridHeaderCell.html b/src/templates/ui-grid/uiGridHeaderCell.html deleted file mode 100644 index d3480a643e..0000000000 --- a/src/templates/ui-grid/uiGridHeaderCell.html +++ /dev/null @@ -1,53 +0,0 @@ -
    -
    - - {{ col.displayName CUSTOM_FILTERS }} - - - - - - {{col.sort.priority + 1}} - - -
    - -
    - -
    - -
    -
    diff --git a/src/templates/ui-grid/uiGridMenu.html b/src/templates/ui-grid/uiGridMenu.html deleted file mode 100644 index 4c9ce94611..0000000000 --- a/src/templates/ui-grid/uiGridMenu.html +++ /dev/null @@ -1,33 +0,0 @@ -
    - -
    -
    - -
    -
    -
    diff --git a/src/templates/ui-grid/uiGridMenuItem.html b/src/templates/ui-grid/uiGridMenuItem.html deleted file mode 100644 index 2918f76a3a..0000000000 --- a/src/templates/ui-grid/uiGridMenuItem.html +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/src/templates/ui-grid/uiGridRenderContainer.html b/src/templates/ui-grid/uiGridRenderContainer.html deleted file mode 100644 index da2108b1e7..0000000000 --- a/src/templates/ui-grid/uiGridRenderContainer.html +++ /dev/null @@ -1,17 +0,0 @@ -
    - -
    -
    -
    -
    - - -
    \ No newline at end of file diff --git a/src/templates/ui-grid/uiGridViewport.html b/src/templates/ui-grid/uiGridViewport.html deleted file mode 100644 index 500016bdc5..0000000000 --- a/src/templates/ui-grid/uiGridViewport.html +++ /dev/null @@ -1,18 +0,0 @@ -
    -
    -
    -
    -
    -
    -
    -
    diff --git a/src/ui-grid.auto-resize.js b/src/ui-grid.auto-resize.js new file mode 100644 index 0000000000..c3deb08e36 --- /dev/null +++ b/src/ui-grid.auto-resize.js @@ -0,0 +1,68 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + /** + * @ngdoc overview + * @name ui.grid.autoResize + * + * @description + * + * #ui.grid.autoResize + * + * + * + * This module provides auto-resizing functionality to UI-Grid. + */ + var module = angular.module('ui.grid.autoResize', ['ui.grid']); + + /** + * @ngdoc directive + * @name ui.grid.autoResize.directive:uiGridAutoResize + * @element div + * @restrict A + * + * @description Stacks on top of the ui-grid directive and + * adds the a watch to the grid's height and width which refreshes + * the grid content whenever its dimensions change. + * + */ + module.directive('uiGridAutoResize', ['gridUtil', function(gridUtil) { + return { + require: 'uiGrid', + scope: false, + link: function($scope, $elm, $attrs, uiGridCtrl) { + var debouncedRefresh; + + function getDimensions() { + return { + width: gridUtil.elementWidth($elm), + height: gridUtil.elementHeight($elm) + }; + } + + function refreshGrid(prevWidth, prevHeight, width, height) { + if ($elm[0].offsetParent !== null) { + uiGridCtrl.grid.gridWidth = width; + uiGridCtrl.grid.gridHeight = height; + uiGridCtrl.grid.queueGridRefresh() + .then(function() { + uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevHeight, prevWidth, height, width); + }); + } + } + + debouncedRefresh = gridUtil.debounce(refreshGrid, 400); + + $scope.$watchCollection(getDimensions, function(newValues, oldValues) { + if (!angular.equals(newValues, oldValues)) { + debouncedRefresh(oldValues.width, oldValues.height, newValues.width, newValues.height); + } + }); + } + }; + }]); +})(); diff --git a/src/ui-grid.auto-resize.min.js b/src/ui-grid.auto-resize.min.js new file mode 100644 index 0000000000..c7cd2d213a --- /dev/null +++ b/src/ui-grid.auto-resize.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";angular.module("ui.grid.autoResize",["ui.grid"]).directive("uiGridAutoResize",["gridUtil",function(n){return{require:"uiGrid",scope:!1,link:function(i,r,e,u){var t;t=n.debounce(function(i,e,t,n){null!==r[0].offsetParent&&(u.grid.gridWidth=t,u.grid.gridHeight=n,u.grid.queueGridRefresh().then(function(){u.grid.api.core.raise.gridDimensionChanged(e,i,n,t)}))},400),i.$watchCollection(function(){return{width:n.elementWidth(r),height:n.elementHeight(r)}},function(i,e){angular.equals(i,e)||t(e.width,e.height,i.width,i.height)})}}}])}(); \ No newline at end of file diff --git a/src/ui-grid.cellnav.js b/src/ui-grid.cellnav.js new file mode 100644 index 0000000000..c86aaec631 --- /dev/null +++ b/src/ui-grid.cellnav.js @@ -0,0 +1,1180 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.cellNav + * + * @description + + #ui.grid.cellNav + + + + This module provides cell navigation functionality to UI-Grid. + */ + var module = angular.module('ui.grid.cellNav', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.cellNav.constant:uiGridCellNavConstants + * + * @description constants available in cellNav + */ + module.constant('uiGridCellNavConstants', { + FEATURE_NAME: 'gridCellNav', + CELL_NAV_EVENT: 'cellNav', + direction: {LEFT: 0, RIGHT: 1, UP: 2, DOWN: 3, PG_UP: 4, PG_DOWN: 5}, + EVENT_TYPE: { + KEYDOWN: 0, + CLICK: 1, + CLEAR: 2 + } + }); + + + module.factory('uiGridCellNavFactory', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', 'GridRowColumn', '$q', + function (gridUtil, uiGridConstants, uiGridCellNavConstants, GridRowColumn, $q) { + /** + * @ngdoc object + * @name ui.grid.cellNav.object:CellNav + * @description returns a CellNav prototype function + * @param {object} rowContainer container for rows + * @param {object} colContainer parent column container + * @param {object} leftColContainer column container to the left of parent + * @param {object} rightColContainer column container to the right of parent + */ + var UiGridCellNav = function UiGridCellNav(rowContainer, colContainer, leftColContainer, rightColContainer) { + this.rows = rowContainer.visibleRowCache; + this.columns = colContainer.visibleColumnCache; + this.leftColumns = leftColContainer ? leftColContainer.visibleColumnCache : []; + this.rightColumns = rightColContainer ? rightColContainer.visibleColumnCache : []; + this.bodyContainer = rowContainer; + }; + + /** returns focusable columns of all containers */ + UiGridCellNav.prototype.getFocusableCols = function () { + var allColumns = this.leftColumns.concat(this.columns, this.rightColumns); + + return allColumns.filter(function (col) { + return col.colDef.allowCellFocus; + }); + }; + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:GridRow + * + * @description GridRow settings for cellNav feature, these are available to be + * set only internally (for example, by other features) + */ + + /** + * @ngdoc object + * @name allowCellFocus + * @propertyOf ui.grid.cellNav.api:GridRow + * @description Enable focus on a cell within this row. If set to false then no cells + * in this row can be focused - group header rows as an example would set this to false. + *
    Defaults to true + */ + /** returns focusable rows */ + UiGridCellNav.prototype.getFocusableRows = function () { + return this.rows.filter(function(row) { + return row.allowCellFocus !== false; + }); + }; + + UiGridCellNav.prototype.getNextRowCol = function (direction, curRow, curCol) { + switch (direction) { + case uiGridCellNavConstants.direction.LEFT: + return this.getRowColLeft(curRow, curCol); + case uiGridCellNavConstants.direction.RIGHT: + return this.getRowColRight(curRow, curCol); + case uiGridCellNavConstants.direction.UP: + return this.getRowColUp(curRow, curCol); + case uiGridCellNavConstants.direction.DOWN: + return this.getRowColDown(curRow, curCol); + case uiGridCellNavConstants.direction.PG_UP: + return this.getRowColPageUp(curRow, curCol); + case uiGridCellNavConstants.direction.PG_DOWN: + return this.getRowColPageDown(curRow, curCol); + } + }; + + UiGridCellNav.prototype.initializeSelection = function () { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + if (focusableCols.length === 0 || focusableRows.length === 0) { + return null; + } + + return new GridRowColumn(focusableRows[0], focusableCols[0]); // return same row + }; + + UiGridCellNav.prototype.getRowColLeft = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 1 + if (curColIndex === -1) { + curColIndex = 1; + } + + var nextColIndex = curColIndex === 0 ? focusableCols.length - 1 : curColIndex - 1; + + // get column to left + if (nextColIndex >= curColIndex) { + // On the first row + // if (curRowIndex === 0 && curColIndex === 0) { + // return null; + // } + if (curRowIndex === 0) { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row + } + else { + // up one row and far right column + return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[nextColIndex]); + } + } + else { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); + } + }; + + + + UiGridCellNav.prototype.getRowColRight = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + var nextColIndex = curColIndex === focusableCols.length - 1 ? 0 : curColIndex + 1; + + if (nextColIndex <= curColIndex) { + if (curRowIndex === focusableRows.length - 1) { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row + } + else { + // down one row and far left column + return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[nextColIndex]); + } + } + else { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColDown = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + if (curRowIndex === focusableRows.length - 1) { + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row + } + else { + // down one row + return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColPageDown = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + var pageSize = this.bodyContainer.minRowsToRender(); + if (curRowIndex >= focusableRows.length - pageSize) { + return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); // return last row + } + else { + // down one page + return new GridRowColumn(focusableRows[curRowIndex + pageSize], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColUp = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + if (curRowIndex === 0) { + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row + } + else { + // up one row + return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColPageUp = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + var pageSize = this.bodyContainer.minRowsToRender(); + if (curRowIndex - pageSize < 0) { + return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); // return first row + } + else { + // up one page + return new GridRowColumn(focusableRows[curRowIndex - pageSize], focusableCols[curColIndex]); + } + }; + return UiGridCellNav; + }]); + + /** + * @ngdoc service + * @name ui.grid.cellNav.service:uiGridCellNavService + * + * @description Services for cell navigation features. If you don't like the key maps we use, + * or the direction cells navigation, override with a service decorator (see angular docs) + */ + module.service('uiGridCellNavService', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', '$q', 'uiGridCellNavFactory', 'GridRowColumn', 'ScrollEvent', + function (gridUtil, uiGridConstants, uiGridCellNavConstants, $q, UiGridCellNav, GridRowColumn, ScrollEvent) { + + var service = { + + initializeGrid: function (grid) { + grid.registerColumnBuilder(service.cellNavColumnBuilder); + + + /** + * @ngdoc object + * @name ui.grid.cellNav.Grid:cellNav + * @description cellNav properties added to grid class + */ + grid.cellNav = {}; + grid.cellNav.lastRowCol = null; + grid.cellNav.focusedCells = []; + + service.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:PublicApi + * + * @description Public Api for cellNav feature + */ + var publicApi = { + events: { + cellNav: { + /** + * @ngdoc event + * @name navigate + * @eventOf ui.grid.cellNav.api:PublicApi + * @description raised when the active cell is changed + *
    +                 *      gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol) {})
    +                 * 
    + * @param {object} newRowCol new position + * @param {object} oldRowCol old position + */ + navigate: function (newRowCol, oldRowCol) {}, + /** + * @ngdoc event + * @name viewPortKeyDown + * @eventOf ui.grid.cellNav.api:PublicApi + * @description is raised when the viewPort receives a keyDown event. Cells never get focus in uiGrid + * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this + * event whenever you need a keydown event on a cell + *
    + * @param {object} event keydown event + * @param {object} rowCol current rowCol position + */ + viewPortKeyDown: function (event, rowCol) {}, + + /** + * @ngdoc event + * @name viewPortKeyPress + * @eventOf ui.grid.cellNav.api:PublicApi + * @description is raised when the viewPort receives a keyPress event. Cells never get focus in uiGrid + * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this + * event whenever you need a keypress event on a cell + *
    + * @param {object} event keypress event + * @param {object} rowCol current rowCol position + */ + viewPortKeyPress: function (event, rowCol) {} + } + }, + methods: { + cellNav: { + /** + * @ngdoc function + * @name scrollToFocus + * @methodOf ui.grid.cellNav.api:PublicApi + * @description brings the specified row and column into view, and sets focus + * to that cell + * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus + * @param {object} colDef to make visible and set focus + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + scrollToFocus: function (rowEntity, colDef) { + return service.scrollToFocus(grid, rowEntity, colDef); + }, + + /** + * @ngdoc function + * @name getFocusedCell + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns the current (or last if Grid does not have focus) focused row and column + *
    value is null if no selection has occurred + */ + getFocusedCell: function () { + return grid.cellNav.lastRowCol; + }, + + /** + * @ngdoc function + * @name getCurrentSelection + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns an array containing the current selection + *
    array is empty if no selection has occurred + */ + getCurrentSelection: function () { + return grid.cellNav.focusedCells; + }, + + /** + * @ngdoc function + * @name rowColSelectIndex + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns the index in the order in which the GridRowColumn was selected, returns -1 if the GridRowColumn + * isn't selected + * @param {object} rowCol the rowCol to evaluate + */ + rowColSelectIndex: function (rowCol) { + // return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) && + var index = -1; + for (var i = 0; i < grid.cellNav.focusedCells.length; i++) { + if (grid.cellNav.focusedCells[i].col.uid === rowCol.col.uid && + grid.cellNav.focusedCells[i].row.uid === rowCol.row.uid) { + index = i; + break; + } + } + return index; + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + defaultGridOptions: function (gridOptions) { + /** + * @ngdoc object + * @name ui.grid.cellNav.api:GridOptions + * + * @description GridOptions for cellNav feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name modifierKeysToMultiSelectCells + * @propertyOf ui.grid.cellNav.api:GridOptions + * @description Enable multiple cell selection only when using the ctrlKey or shiftKey. + *
    Defaults to false + */ + gridOptions.modifierKeysToMultiSelectCells = gridOptions.modifierKeysToMultiSelectCells === true; + + /** + * @ngdoc array + * @name keyDownOverrides + * @propertyOf ui.grid.cellNav.api:GridOptions + * @description An array of event objects to override on keydown. If an event is overridden, the viewPortKeyDown event will + * be raised with the overridden events, allowing custom keydown behavior. + *
    Defaults to [] + */ + gridOptions.keyDownOverrides = gridOptions.keyDownOverrides || []; + + }, + + /** + * @ngdoc service + * @name decorateRenderContainers + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description decorates grid renderContainers with cellNav functions + */ + decorateRenderContainers: function (grid) { + + var rightContainer = grid.hasRightContainer() ? grid.renderContainers.right : null; + var leftContainer = grid.hasLeftContainer() ? grid.renderContainers.left : null; + + if (leftContainer !== null) { + grid.renderContainers.left.cellNav = new UiGridCellNav(grid.renderContainers.body, leftContainer, rightContainer, grid.renderContainers.body); + } + if (rightContainer !== null) { + grid.renderContainers.right.cellNav = new UiGridCellNav(grid.renderContainers.body, rightContainer, grid.renderContainers.body, leftContainer); + } + + grid.renderContainers.body.cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, leftContainer, rightContainer); + }, + + /** + * @ngdoc service + * @name getDirection + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description determines which direction to for a given keyDown event + * @returns {uiGridCellNavConstants.direction} direction + */ + getDirection: function (evt) { + if (evt.keyCode === uiGridConstants.keymap.LEFT || + (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey)) { + return uiGridCellNavConstants.direction.LEFT; + } + if (evt.keyCode === uiGridConstants.keymap.RIGHT || + evt.keyCode === uiGridConstants.keymap.TAB) { + return uiGridCellNavConstants.direction.RIGHT; + } + + if (evt.keyCode === uiGridConstants.keymap.UP || + (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ) { + return uiGridCellNavConstants.direction.UP; + } + + if (evt.keyCode === uiGridConstants.keymap.PG_UP) { + return uiGridCellNavConstants.direction.PG_UP; + } + + if (evt.keyCode === uiGridConstants.keymap.DOWN || + evt.keyCode === uiGridConstants.keymap.ENTER && !(evt.ctrlKey || evt.altKey)) { + return uiGridCellNavConstants.direction.DOWN; + } + + if (evt.keyCode === uiGridConstants.keymap.PG_DOWN) { + return uiGridCellNavConstants.direction.PG_DOWN; + } + + return null; + }, + + /** + * @ngdoc service + * @name cellNavColumnBuilder + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description columnBuilder function that adds cell navigation properties to grid column + * @returns {promise} promise that will load any needed templates when resolved + */ + cellNavColumnBuilder: function (colDef, col, gridOptions) { + var promises = []; + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:ColumnDef + * + * @description Column Definitions for cellNav feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name allowCellFocus + * @propertyOf ui.grid.cellNav.api:ColumnDef + * @description Enable focus on a cell within this column. + *
    Defaults to true + */ + colDef.allowCellFocus = colDef.allowCellFocus === undefined ? true : colDef.allowCellFocus; + + return $q.all(promises); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @name scrollToFocus + * @description Scroll the grid such that the specified + * row and column is in view, and set focus to the cell in that row and column + * @param {Grid} grid the grid you'd like to act upon, usually available + * from gridApi.grid + * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus to + * @param {object} colDef to make visible and set focus to + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + scrollToFocus: function (grid, rowEntity, colDef) { + var gridRow = null, gridCol = null; + + if (typeof(rowEntity) !== 'undefined' && rowEntity !== null) { + gridRow = grid.getRow(rowEntity); + } + + if (typeof(colDef) !== 'undefined' && colDef !== null) { + gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field); + } + return grid.api.core.scrollToIfNecessary(gridRow, gridCol).then(function () { + var rowCol = { row: gridRow, col: gridCol }; + + // Broadcast the navigation + if (gridRow !== null && gridCol !== null) { + grid.cellNav.broadcastCellNav(rowCol, null, null); + } + }); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @name getLeftWidth + * @description Get the current drawn width of the columns in the + * grid up to the numbered column, and add an apportionment for the + * column that we're on. So if we are on column 0, we want to scroll + * 0% (i.e. exclude this column from calc). If we're on the last column + * we want to scroll to 100% (i.e. include this column in the calc). So + * we include (thisColIndex / totalNumberCols) % of this column width + * @param {Grid} grid the grid you'd like to act upon, usually available + * from gridApi.grid + * @param {GridColumn} upToCol the column to total up to and including + */ + getLeftWidth: function (grid, upToCol) { + var width = 0; + + if (!upToCol) { + return width; + } + + var lastIndex = grid.renderContainers.body.visibleColumnCache.indexOf( upToCol ); + + // total column widths up-to but not including the passed in column + grid.renderContainers.body.visibleColumnCache.forEach( function( col, index ) { + if ( index < lastIndex ) { + width += col.drawnWidth; + } + }); + + // pro-rata the final column based on % of total columns. + var percentage = lastIndex === 0 ? 0 : (lastIndex + 1) / grid.renderContainers.body.visibleColumnCache.length; + width += upToCol.drawnWidth * percentage; + + return width; + } + }; + + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.cellNav.directive:uiCellNav + * @element div + * @restrict EA + * + * @description Adds cell navigation features to the grid columns + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.cellNav']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name'}, + {name: 'title'} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridCellnav', ['gridUtil', 'uiGridCellNavService', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', '$timeout', '$compile', 'i18nService', + function (gridUtil, uiGridCellNavService, uiGridCellNavConstants, uiGridConstants, GridRowColumn, $timeout, $compile, i18nService) { + return { + replace: true, + priority: -150, + require: '^uiGrid', + scope: false, + controller: function () {}, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + var _scope = $scope; + + var grid = uiGridCtrl.grid; + uiGridCellNavService.initializeGrid(grid); + + uiGridCtrl.cellNav = {}; + + // Ensure that the object has all of the methods we expect it to + uiGridCtrl.cellNav.makeRowCol = function (obj) { + if (!(obj instanceof GridRowColumn)) { + obj = new GridRowColumn(obj.row, obj.col); + } + return obj; + }; + + uiGridCtrl.cellNav.getActiveCell = function () { + var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus'); + if (elms.length > 0) { + return elms[0]; + } + + return undefined; + }; + + uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); + + newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol); + + uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt); + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt); + }; + + uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () { + grid.cellNav.focusedCells = []; + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT); + }; + + uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); + + rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol); + + var row = rowCol.row, + col = rowCol.col; + + var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); + + if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1 || (grid.cellNav.lastRowCol.col === col && grid.cellNav.lastRowCol.row === row)) { + var newRowCol = new GridRowColumn(row, col); + + if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col || grid.options.enableCellEditOnFocus) { + grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol, originEvt); + grid.cellNav.lastRowCol = newRowCol; + } + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) { + grid.cellNav.focusedCells.push(rowCol); + } else { + grid.cellNav.focusedCells = [rowCol]; + } + } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown && + rowColSelectIndex >= 0) { + + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + } + }; + + uiGridCtrl.cellNav.handleKeyDown = function (evt) { + var direction = uiGridCellNavService.getDirection(evt); + if (direction === null) { + return null; + } + + var containerId = 'body'; + if (evt.uiGridTargetRenderContainerId) { + containerId = evt.uiGridTargetRenderContainerId; + } + + // Get the last-focused row+col combo + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol) { + // Figure out which new row+combo we're navigating to + var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col); + var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols(); + var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); + // Shift+tab on top-left cell should exit cellnav on render container + if ( + // Navigating left + direction === uiGridCellNavConstants.direction.LEFT && + // New col is last col (i.e. wrap around) + rowCol.col === focusableCols[focusableCols.length - 1] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + evt.shiftKey + ) { + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; + } + // Tab on bottom-right cell should exit cellnav on render container + else if ( + direction === uiGridCellNavConstants.direction.RIGHT && + // New col is first col (i.e. wrap around) + rowCol.col === focusableCols[0] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + !evt.shiftKey + ) { + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; + } + + // Scroll to the new cell, if it's not completely visible within the render container's viewport + grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () { + uiGridCtrl.cellNav.broadcastCellNav(rowCol, null, evt); + }); + + + evt.stopPropagation(); + evt.preventDefault(); + + return false; + } + }; + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + var usesAria = true; + + // Detect whether we are using ngAria + // (if ngAria module is not used then the stuff inside addAriaLiveRegion + // is not used and provides extra fluff) + try { + angular.module('ngAria'); + } + catch (err) { + usesAria = false; + } + + function addAriaLiveRegion() { + // Thanks to google docs for the inspiration behind how to do this + // XXX: Why is this entire mess nessasary? + // Because browsers take a lot of coercing to get them to read out live regions + // http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/ + var ariaNotifierDomElt = '
    ' + + ' ' + + '
    '; + + var ariaNotifier = $compile(ariaNotifierDomElt)($scope); + $elm.prepend(ariaNotifier); + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown, originEvt) { + /* + * If the cell nav event was because of a focus event then we don't want to + * change the notifier text. + * Reasoning: Voice Over fires a focus events when moving arround the grid. + * If the screen reader is handing the grid nav properly then we don't need to + * use the alert to notify the user of the movement. + * In all other cases we do want a notification event. + */ + if (originEvt && originEvt.type === 'focus') {return;} + + function setNotifyText(text) { + if (text === ariaNotifier.text().trim()) {return;} + ariaNotifier[0].style.clip = 'rect(0px,0px,0px,0px)'; + /* + * This is how google docs handles clearing the div. Seems to work better than setting the text of the div to '' + */ + ariaNotifier[0].innerHTML = ""; + ariaNotifier[0].style.visibility = 'hidden'; + ariaNotifier[0].style.visibility = 'visible'; + if (text !== '') { + ariaNotifier[0].style.clip = 'auto'; + /* + * The space after the text is something that google docs does. + */ + ariaNotifier[0].appendChild(document.createTextNode(text + " ")); + ariaNotifier[0].style.visibility = 'hidden'; + ariaNotifier[0].style.visibility = 'visible'; + } + } + + function getAppendedColumnHeaderText(col) { + return ', ' + i18nService.getSafeText('headerCell.aria.column') + ' ' + col.displayName; + } + + function getCellDisplayValue(currentRowColumn) { + var prefix = ''; + + if (currentRowColumn.col.field === 'selectionRowHeaderCol') { + // This is the case when the 'selection' feature is used in the grid and the user has moved + // to or inside of the left grid container which holds the checkboxes for selecting rows. + // This is necessary for Accessibility. Without this a screen reader cannot determine if the row + // is or is not currently selected. + prefix = (currentRowColumn.row.isSelected ? i18nService.getSafeText('search.aria.selected') : i18nService.getSafeText('search.aria.notSelected')) + ', '; + } + return prefix + grid.getCellDisplayValue(currentRowColumn.row, currentRowColumn.col); + } + + var values = []; + var currentSelection = grid.api.cellNav.getCurrentSelection(); + for (var i = 0; i < currentSelection.length; i++) { + var cellDisplayValue = getCellDisplayValue(currentSelection[i]) + getAppendedColumnHeaderText(currentSelection[i].col); + values.push(cellDisplayValue); + } + setNotifyText(values.toString()); + }); + } + // Only add the ngAria stuff it will be used + if (usesAria) { + addAriaLiveRegion(); + } + } + }; + } + }; + }]); + + module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile','uiGridCellNavConstants', + function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile, uiGridCellNavConstants) { + return { + replace: true, + priority: -99999, // this needs to run very last + require: ['^uiGrid', 'uiGridRenderContainer', '?^uiGridCellnav'], + scope: false, + compile: function () { + return { + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + renderContainerCtrl = controllers[1], + uiGridCellnavCtrl = controllers[2]; + + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = renderContainerCtrl.containerId; + + var grid = uiGridCtrl.grid; + + // run each time a render container is created + uiGridCellNavService.decorateRenderContainers(grid); + + // focusser only created for body + if (containerId !== 'body') { + return; + } + + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells) { + $elm.attr('aria-multiselectable', true); + } + else { + $elm.attr('aria-multiselectable', false); + } + + // add an element with no dimensions that can be used to set focus and capture keystrokes + var focuser = $compile('
    ')($scope); + $elm.append(focuser); + + focuser.on('focus', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (rowCol === null) { + rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null); + if (rowCol.row && rowCol.col) { + uiGridCtrl.cellNav.broadcastCellNav(rowCol); + } + } + }); + + uiGridCellnavCtrl.setAriaActivedescendant = function(id) { + $elm.attr('aria-activedescendant', id); + }; + + uiGridCellnavCtrl.removeAriaActivedescendant = function(id) { + if ($elm.attr('aria-activedescendant') === id) { + $elm.attr('aria-activedescendant', ''); + } + }; + + + uiGridCtrl.focus = function () { + gridUtil.focus.byElement(focuser[0]); + // allow for first time grid focus + }; + + var viewPortKeyDownWasRaisedForRowCol = null; + // Bind to keydown events in the render container + focuser.on('keydown', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + var raiseViewPortKeyDown = uiGridCtrl.grid.options.keyDownOverrides.some(function (override) { + return Object.keys(override).every( function (property) { + return override[property] === evt[property]; + }); + }); + var result = raiseViewPortKeyDown ? null : uiGridCtrl.cellNav.handleKeyDown(evt); + if (result === null) { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol, uiGridCtrl.cellNav.handleKeyDown); + viewPortKeyDownWasRaisedForRowCol = rowCol; + } + }); + // Bind to keypress events in the render container + // keypress events are needed by edit function so the key press + // that initiated an edit is not lost + // must fire the event in a timeout so the editor can + // initialize and subscribe to the event on another event loop + focuser.on('keypress', function (evt) { + if (viewPortKeyDownWasRaisedForRowCol) { + $timeout(function () { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol); + }, 4); + + viewPortKeyDownWasRaisedForRowCol = null; + } + }); + + $scope.$on('$destroy', function() { + // Remove all event handlers associated with this focuser. + focuser.off(); + }); + } + }; + } + }; + }]); + + module.directive('uiGridViewport', + function () { + return { + replace: true, + priority: -99999, // this needs to run very last + require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'], + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + }, + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + renderContainerCtrl = controllers[1]; + + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = renderContainerCtrl.containerId; + // no need to process for other containers + if (containerId !== 'body') { + return; + } + + var grid = uiGridCtrl.grid; + + grid.api.core.on.scrollBegin($scope, function () { + + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { + return; + } + + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; + } + + uiGridCtrl.cellNav.clearFocus(); + + }); + + grid.api.core.on.scrollEnd($scope, function (args) { + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { + return; + } + + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; + } + + uiGridCtrl.cellNav.broadcastCellNav(lastRowCol); + }); + + grid.api.cellNav.on.navigate($scope, function () { + // focus again because it can be lost + uiGridCtrl.focus(); + }); + } + }; + } + }; + }); + + /** + * @ngdoc directive + * @name ui.grid.cellNav.directive:uiGridCell + * @element div + * @restrict A + * @description Stacks on top of ui.grid.uiGridCell to provide cell navigation + */ + module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', + function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants, GridRowColumn) { + return { + priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell + restrict: 'A', + require: ['^uiGrid', '?^uiGridCellnav'], + scope: false, + link: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + uiGridCellnavCtrl = controllers[1]; + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + if (!$scope.col.colDef.allowCellFocus) { + return; + } + + // Convinience local variables + var grid = uiGridCtrl.grid; + $scope.focused = false; + + // Make this cell focusable but only with javascript/a mouse click + $elm.attr('tabindex', -1); + + // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused + $elm.find('div').on('click', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt); + + evt.stopPropagation(); + $scope.$apply(); + }); + + + /* + * XXX Hack for screen readers. + * This allows the grid to focus using only the screen reader cursor. + * Since the focus event doesn't include key press information we can't use it + * as our primary source of the event. + */ + $elm.on('mousedown', preventMouseDown); + + // turn on and off for edit events + if (uiGridCtrl.grid.api.edit) { + uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () { + $elm.off('mousedown', preventMouseDown); + }); + + uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); + + uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); + } + + // In case we created a new row, and we are the new created row by ngRepeat + // then this cell content might have been selected previously + refreshCellFocus(); + + function preventMouseDown(evt) { + // Prevents the foucus event from firing if the click event is already going to fire. + // If both events fire it will cause bouncing behavior. + evt.preventDefault(); + } + + // You can only focus on elements with a tabindex value + $elm.on('focus', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt); + evt.stopPropagation(); + $scope.$apply(); + }); + + // This event is fired for all cells. If the cell matches, then focus is set + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus); + + // Refresh cell focus when a new row id added to the grid + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) { + // Clear the focus if it's set to avoid the wrong cell getting focused during + // a short period of time (from now until $timeout function executed) + clearFocus(); + + $scope.$applyAsync(refreshCellFocus); + }, [uiGridConstants.dataChange.ROW]); + + function refreshCellFocus() { + var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) { + return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col); + }); + if (isFocused) { + setFocused(); + } else { + clearFocus(); + } + } + + function setFocused() { + if (!$scope.focused) { + var div = $elm.find('div'); + div.addClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', true); + uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id')); + $scope.focused = true; + } + } + + function clearFocus() { + if ($scope.focused) { + var div = $elm.find('div'); + div.removeClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', false); + uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id')); + $scope.focused = false; + } + } + + $scope.$on('$destroy', function () { + dataChangeDereg(); + + // .off withouth paramaters removes all handlers + $elm.find('div').off(); + $elm.off(); + }); + } + }; + }]); +})(); diff --git a/src/ui-grid.cellnav.min.js b/src/ui-grid.cellnav.min.js new file mode 100644 index 0000000000..e80917cac1 --- /dev/null +++ b/src/ui-grid.cellnav.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.cellNav",["ui.grid"]);e.constant("uiGridCellNavConstants",{FEATURE_NAME:"gridCellNav",CELL_NAV_EVENT:"cellNav",direction:{LEFT:0,RIGHT:1,UP:2,DOWN:3,PG_UP:4,PG_DOWN:5},EVENT_TYPE:{KEYDOWN:0,CLICK:1,CLEAR:2}}),e.factory("uiGridCellNavFactory",["gridUtil","uiGridConstants","uiGridCellNavConstants","GridRowColumn","$q",function(e,l,o,a,i){var n=function(e,l,i,o){this.rows=e.visibleRowCache,this.columns=l.visibleColumnCache,this.leftColumns=i?i.visibleColumnCache:[],this.rightColumns=o?o.visibleColumnCache:[],this.bodyContainer=e};return n.prototype.getFocusableCols=function(){return this.leftColumns.concat(this.columns,this.rightColumns).filter(function(e){return e.colDef.allowCellFocus})},n.prototype.getFocusableRows=function(){return this.rows.filter(function(e){return!1!==e.allowCellFocus})},n.prototype.getNextRowCol=function(e,l,i){switch(e){case o.direction.LEFT:return this.getRowColLeft(l,i);case o.direction.RIGHT:return this.getRowColRight(l,i);case o.direction.UP:return this.getRowColUp(l,i);case o.direction.DOWN:return this.getRowColDown(l,i);case o.direction.PG_UP:return this.getRowColPageUp(l,i);case o.direction.PG_DOWN:return this.getRowColPageDown(l,i)}},n.prototype.initializeSelection=function(){var e=this.getFocusableCols(),l=this.getFocusableRows();return 0===e.length||0===l.length?null:new a(l[0],e[0])},n.prototype.getRowColLeft=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=1);var r=0===n?i.length-1:n-1;return new a(n<=r?0===t?e:o[t-1]:e,i[r])},n.prototype.getRowColRight=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=n===i.length-1?0:n+1;return r<=n?t===o.length-1?new a(e,i[r]):new a(o[t+1],i[r]):new a(e,i[r])},n.prototype.getRowColDown=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);return-1===n&&(n=0),t===o.length-1?new a(e,i[n]):new a(o[t+1],i[n])},n.prototype.getRowColPageDown=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=this.bodyContainer.minRowsToRender();return t>=o.length-r?new a(o[o.length-1],i[n]):new a(o[t+r],i[n])},n.prototype.getRowColUp=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);return-1===n&&(n=0),new a(0===t?e:o[t-1],i[n])},n.prototype.getRowColPageUp=function(e,l){var i=this.getFocusableCols(),o=this.getFocusableRows(),n=i.indexOf(l),t=o.indexOf(e);-1===n&&(n=0);var r=this.bodyContainer.minRowsToRender();return new a(t-r<0?o[0]:o[t-r],i[n])},n}]),e.service("uiGridCellNavService",["gridUtil","uiGridConstants","uiGridCellNavConstants","$q","uiGridCellNavFactory","GridRowColumn","ScrollEvent",function(e,l,i,o,n,t,r){var a={initializeGrid:function(o){o.registerColumnBuilder(a.cellNavColumnBuilder),o.cellNav={},o.cellNav.lastRowCol=null,o.cellNav.focusedCells=[],a.defaultGridOptions(o.options);var e={events:{cellNav:{navigate:function(e,l){},viewPortKeyDown:function(e,l){},viewPortKeyPress:function(e,l){}}},methods:{cellNav:{scrollToFocus:function(e,l){return a.scrollToFocus(o,e,l)},getFocusedCell:function(){return o.cellNav.lastRowCol},getCurrentSelection:function(){return o.cellNav.focusedCells},rowColSelectIndex:function(e){for(var l=-1,i=0;i 
    ',v=r(n)(e),l.prepend(v),e.$on(d.CELL_NAV_EVENT,function(e,l,i,o){if(!o||"focus"!==o.type){for(var n,t,r,a,c=[],s=C.api.cellNav.getCurrentSelection(),d=0;d
    ')(e);l.append(s),s.on("focus",function(e){e.uiGridTargetRenderContainerId=a;var l=n.grid.api.cellNav.getFocusedCell();null===l&&(l=n.grid.renderContainers[a].cellNav.getNextRowCol(g.direction.DOWN,null,null)).row&&l.col&&n.cellNav.broadcastCellNav(l)}),r.setAriaActivedescendant=function(e){l.attr("aria-activedescendant",e)},r.removeAriaActivedescendant=function(e){l.attr("aria-activedescendant")===e&&l.attr("aria-activedescendant","")},n.focus=function(){v.focus.byElement(s[0])};var d=null;s.on("keydown",function(i){i.uiGridTargetRenderContainerId=a;var e=n.grid.api.cellNav.getFocusedCell();null===(n.grid.options.keyDownOverrides.some(function(l){return Object.keys(l).every(function(e){return l[e]===i[e]})})?null:n.cellNav.handleKeyDown(i))&&(n.grid.api.cellNav.raise.viewPortKeyDown(i,e,n.cellNav.handleKeyDown),d=e)}),s.on("keypress",function(e){d&&(u(function(){n.grid.api.cellNav.raise.viewPortKeyPress(e,d)},4),d=null)}),e.$on("$destroy",function(){s.off()})}}}}}}}]),e.directive("uiGridViewport",function(){return{replace:!0,priority:-99999,require:["^uiGrid","^uiGridRenderContainer","?^uiGridCellnav"],scope:!1,compile:function(){return{pre:function(e,l,i,o){},post:function(e,l,i,o){var n=o[0],t=o[1];if(n.grid.api.cellNav&&"body"===t.containerId){var r=n.grid;r.api.core.on.scrollBegin(e,function(){var e=n.grid.api.cellNav.getFocusedCell();null!==e&&t.colContainer.containsColumn(e.col)&&n.cellNav.clearFocus()}),r.api.core.on.scrollEnd(e,function(e){var l=n.grid.api.cellNav.getFocusedCell();null!==l&&t.colContainer.containsColumn(l.col)&&n.cellNav.broadcastCellNav(l)}),r.api.cellNav.on.navigate(e,function(){n.focus()})}}}}}}),e.directive("uiGridCell",["$timeout","$document","uiGridCellNavService","gridUtil","uiGridCellNavConstants","uiGridConstants","GridRowColumn",function(e,l,i,o,u,v,C){return{priority:-150,restrict:"A",require:["^uiGrid","?^uiGridCellnav"],scope:!1,link:function(i,l,e,o){var n=o[0],t=o[1];if(n.grid.api.cellNav&&i.col.colDef.allowCellFocus){var r=n.grid;i.focused=!1,l.attr("tabindex",-1),l.find("div").on("click",function(e){n.cellNav.broadcastCellNav(new C(i.row,i.col),e.ctrlKey||e.metaKey,e),e.stopPropagation(),i.$apply()}),l.on("mousedown",c),n.grid.api.edit&&(n.grid.api.edit.on.beginCellEdit(i,function(){l.off("mousedown",c)}),n.grid.api.edit.on.afterCellEdit(i,function(){l.on("mousedown",c)}),n.grid.api.edit.on.cancelCellEdit(i,function(){l.on("mousedown",c)})),s(),l.on("focus",function(e){n.cellNav.broadcastCellNav(new C(i.row,i.col),!1,e),e.stopPropagation(),i.$apply()}),i.$on(u.CELL_NAV_EVENT,s);var a=n.grid.registerDataChangeCallback(function(e){d(),i.$applyAsync(s)},[v.dataChange.ROW]);i.$on("$destroy",function(){a(),l.find("div").off(),l.off()})}function c(e){e.preventDefault()}function s(){r.cellNav.focusedCells.some(function(e,l){return e.row===i.row&&e.col===i.col})?function(){if(!i.focused){var e=l.find("div");e.addClass("ui-grid-cell-focus"),l.attr("aria-selected",!0),t.setAriaActivedescendant(l.attr("id")),i.focused=!0}}():d()}function d(){i.focused&&(l.find("div").removeClass("ui-grid-cell-focus"),l.attr("aria-selected",!1),t.removeAriaActivedescendant(l.attr("id")),i.focused=!1)}}}}])}(); \ No newline at end of file diff --git a/src/ui-grid.core.js b/src/ui-grid.core.js new file mode 100644 index 0000000000..38681c0c47 --- /dev/null +++ b/src/ui-grid.core.js @@ -0,0 +1,12726 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + + angular.module('ui.grid.i18n', []); + angular.module('ui.grid', ['ui.grid.i18n']); +})(); + +(function () { + 'use strict'; + + /** + * @ngdoc object + * @name ui.grid.service:uiGridConstants + * @description Constants for use across many grid features + * + */ + + + angular.module('ui.grid').constant('uiGridConstants', { + LOG_DEBUG_MESSAGES: true, + LOG_WARN_MESSAGES: true, + LOG_ERROR_MESSAGES: true, + CUSTOM_FILTERS: /CUSTOM_FILTERS/g, + COL_FIELD: /COL_FIELD/g, + MODEL_COL_FIELD: /MODEL_COL_FIELD/g, + TOOLTIP: /title=\"TOOLTIP\"/g, + DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g, + TEMPLATE_REGEXP: /<.+>/, + FUNC_REGEXP: /(\([^)]*\))?$/, + DOT_REGEXP: /\./g, + APOS_REGEXP: /'/g, + BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/, + COL_CLASS_PREFIX: 'ui-grid-col', + ENTITY_BINDING: '$$this', + events: { + GRID_SCROLL: 'uiGridScroll', + COLUMN_MENU_SHOWN: 'uiGridColMenuShown', + ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged + COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick' + }, + // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html + keymap: { + TAB: 9, + STRG: 17, + CAPSLOCK: 20, + CTRL: 17, + CTRLRIGHT: 18, + CTRLR: 18, + SHIFT: 16, + RETURN: 13, + ENTER: 13, + BACKSPACE: 8, + BCKSP: 8, + ALT: 18, + ALTR: 17, + ALTRIGHT: 17, + SPACE: 32, + WIN: 91, + MAC: 91, + FN: null, + PG_UP: 33, + PG_DOWN: 34, + UP: 38, + DOWN: 40, + LEFT: 37, + RIGHT: 39, + ESC: 27, + DEL: 46, + F1: 112, + F2: 113, + F3: 114, + F4: 115, + F5: 116, + F6: 117, + F7: 118, + F8: 119, + F9: 120, + F10: 121, + F11: 122, + F12: 123 + }, + /** + * @ngdoc object + * @name ASC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + ASC: 'asc', + /** + * @ngdoc object + * @name DESC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + DESC: 'desc', + + + /** + * @ngdoc object + * @name filter + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter} + * to configure filtering on the column + * + * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify + * one of the built-in conditions. + * + * Available `condition` options are: + * - `uiGridConstants.filter.STARTS_WITH` + * - `uiGridConstants.filter.ENDS_WITH` + * - `uiGridConstants.filter.CONTAINS` + * - `uiGridConstants.filter.GREATER_THAN` + * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL` + * - `uiGridConstants.filter.LESS_THAN` + * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL` + * - `uiGridConstants.filter.NOT_EQUAL` + * + * + * Available `type` options are: + * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field + * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field + */ + filter: { + STARTS_WITH: 2, + ENDS_WITH: 4, + EXACT: 8, + CONTAINS: 16, + GREATER_THAN: 32, + GREATER_THAN_OR_EQUAL: 64, + LESS_THAN: 128, + LESS_THAN_OR_EQUAL: 256, + NOT_EQUAL: 512, + SELECT: 'select', + INPUT: 'input' + }, + + /** + * @ngdoc object + * @name aggregationTypes + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType} + * to specify the type of built-in aggregation the column should use. + * + * Available options are: + * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value + * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value + * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value + */ + aggregationTypes: { + sum: 2, + count: 4, + avg: 8, + min: 16, + max: 32 + }, + + /** + * @ngdoc array + * @name CURRENCY_SYMBOLS + * @propertyOf ui.grid.service:uiGridConstants + * @description A list of all presently circulating currency symbols that was copied from + * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols + * + * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols. + */ + CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден', + 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu', + 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв', + 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q', + 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/', + 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'], + + /** + * @ngdoc object + * @name scrollDirection + * @propertyOf ui.grid.service:uiGridConstants + * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection}, + * to indicate the direction the grid is currently scrolling in + * + * Available options are: + * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up + * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down + * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left + * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right + * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default + */ + scrollDirection: { + UP: 'up', + DOWN: 'down', + LEFT: 'left', + RIGHT: 'right', + NONE: 'none' + + }, + + /** + * @ngdoc object + * @name dataChange + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange}, + * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks}, + * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback} + * to specify the type of the event(s). + * + * Available options are: + * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events. + * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited + * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed + * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified + * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified + */ + dataChange: { + ALL: 'all', + EDIT: 'edit', + ROW: 'row', + COLUMN: 'column', + OPTIONS: 'options' + }, + + /** + * @ngdoc object + * @name scrollbars + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar} + * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar} + * to specify the scrollbar policy for that direction. + * + * Available options are: + * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction + * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction + * - `uiGridConstants.scrollbars.WHEN_NEEDED` - shows scrollbars in this direction when needed + */ + + scrollbars: { + NEVER: 0, + ALWAYS: 1, + WHEN_NEEDED: 2 + } + }); + +})(); + +angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) { + return { + priority: 0, + scope: false, + require: '?^uiGrid', + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + function compileTemplate() { + var compiledElementFn = $scope.col.compiledElementFn; + + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + } + + // If the grid controller is present, use it to get the compiled cell template function + if (uiGridCtrl && $scope.col.compiledElementFn) { + compileTemplate(); + } + + // No controller, compile the element manually (for unit tests) + else { + if ( uiGridCtrl && !$scope.col.compiledElementFn ) { + $scope.col.getCompiledElementFn() + .then(function (compiledElementFn) { + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + }).catch(angular.noop); + } + else { + var html = $scope.col.cellTemplate + .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field)) + .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + var cellElement = $compile(html)($scope); + $elm.append(cellElement); + } + } + }, + post: function($scope, $elm) { + var initColClass = $scope.col.getColClass(false), + classAdded; + + $elm.addClass(initColClass); + + function updateClass( grid ) { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.cellClass)) { + classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.cellClass; + } + contents.addClass(classAdded); + } + + if ($scope.col.cellClass) { + updateClass(); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]); + + // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise + // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things + function cellChangeFunction( n, o ) { + if ( n !== o ) { + if ( classAdded || $scope.col.cellClass ) { + updateClass(); + } + + // See if the column's internal class has changed + var newColClass = $scope.col.getColClass(false); + + if (newColClass !== initColClass) { + $elm.removeClass(initColClass); + $elm.addClass(newColClass); + initColClass = newColClass; + } + } + } + + // TODO(c0bra): Turn this into a deep array watch + var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction ); + + function deregisterFunction() { + dataChangeDereg(); + rowWatchDereg(); + } + + $scope.$on('$destroy', deregisterFunction); + $elm.on('$destroy', deregisterFunction); + } + }; + } + }; +}]); + +(function() { + +angular.module('ui.grid') +.service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil', +function ( i18nService, uiGridConstants, gridUtil ) { +/** + * @ngdoc service + * @name ui.grid.service:uiGridColumnMenuService + * + * @description Services for working with column menus, factored out + * to make the code easier to understand + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name initialize + * @description Sets defaults, puts a reference to the $scope on + * the uiGridController + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {controller} uiGridCtrl the uiGridController for the grid + * we're on + * + */ + initialize: function( $scope, uiGridCtrl ) { + $scope.grid = uiGridCtrl.grid; + + // Store a reference to this link/controller in the main uiGrid controller + // to allow showMenu later + uiGridCtrl.columnMenuScope = $scope; + + // Save whether we're shown or not so the columns can check + $scope.menuShown = false; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name setColMenuItemWatch + * @description Setup a watch on $scope.col.menuItems, and update + * menuItems based on this. $scope.col needs to be set by the column + * before calling the menu. + * @param {$scope} $scope the $scope from the uiGridColumnMenu + */ + setColMenuItemWatch: function ( $scope ) { + var deregFunction = $scope.$watch('col.menuItems', function (n) { + if (typeof(n) !== 'undefined' && n && angular.isArray(n)) { + n.forEach(function (item) { + if (typeof(item.context) === 'undefined' || !item.context) { + item.context = {}; + } + item.context.col = $scope.col; + }); + + $scope.menuItems = $scope.defaultMenuItems.concat(n); + } + else { + $scope.menuItems = $scope.defaultMenuItems; + } + }); + + $scope.$on( '$destroy', deregFunction ); + }, + + getGridOption: function( $scope, option ) { + return typeof($scope.grid) !== 'undefined' && $scope.grid && $scope.grid.options && $scope.grid.options[option]; + }, + + /** + * @ngdoc boolean + * @name enableSorting + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When enabled, this setting adds sort + * widgets to the column header, allowing sorting of the data in the individual column. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name sortable + * @description determines whether this column is sortable + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + sortable: function( $scope ) { + return Boolean( this.getGridOption($scope, 'enableSorting') && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name isActiveSort + * @description determines whether the requested sort direction is current active, to + * allow highlighting in the menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {string} direction the direction that we'd have selected for us to be active + * + */ + isActiveSort: function( $scope, direction ) { + return Boolean(typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name suppressRemoveSort + * @description determines whether we should suppress the removeSort option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + suppressRemoveSort: function( $scope ) { + return Boolean($scope.col && $scope.col.suppressRemoveSort); + }, + + + /** + * @ngdoc boolean + * @name enableHiding + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column + * using the column menu or the grid menu. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name hideable + * @description determines whether a column can be hidden, by checking the enableHiding columnDef option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + hideable: function( $scope ) { + return Boolean( + (this.getGridOption($scope, 'enableHiding') && + typeof($scope.col) !== 'undefined' && $scope.col && + ($scope.col.colDef && $scope.col.colDef.enableHiding !== false || !$scope.col.colDef)) || + (!this.getGridOption($scope, 'enableHiding') && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding) + ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getDefaultMenuItems + * @description returns the default menu items for a column menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + getDefaultMenuItems: function( $scope ) { + return [ + { + title: function() {return i18nService.getSafeText('sort.ascending');}, + icon: 'ui-grid-icon-sort-alt-up', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.ASC); + }, + shown: function () { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.ASC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.descending');}, + icon: 'ui-grid-icon-sort-alt-down', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.DESC); + }, + shown: function() { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.DESC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.remove');}, + icon: 'ui-grid-icon-cancel', + action: function ($event) { + $event.stopPropagation(); + $scope.unsortColumn(); + }, + shown: function() { + return service.sortable( $scope ) && + typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null && + !service.suppressRemoveSort( $scope ); + } + }, + { + title: function() {return i18nService.getSafeText('column.hide');}, + icon: 'ui-grid-icon-cancel', + shown: function() { + return service.hideable( $scope ); + }, + action: function ($event) { + $event.stopPropagation(); + $scope.hideColumn(); + } + } + ]; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getColumnElementPosition + * @description gets the position information needed to place the column + * menu below the column header + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + * @returns {hash} containing left, top, offset, height, width + * + */ + getColumnElementPosition: function( $scope, column, $columnElement ) { + var positionData = {}; + + positionData.left = $columnElement[0].offsetLeft; + positionData.top = $columnElement[0].offsetTop; + positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft; + + // Get the grid scrollLeft + positionData.offset = 0; + if (column.grid.options.offsetLeft) { + positionData.offset = column.grid.options.offsetLeft; + } + + positionData.height = gridUtil.elementHeight($columnElement, true); + positionData.width = gridUtil.elementWidth($columnElement, true); + + return positionData; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name repositionMenu + * @description Reposition the menu below the new column. If the menu has no child nodes + * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again + * later to fix it + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {hash} positionData a hash containing left, top, offset, height, width + * @param {element} $elm the column menu element that we want to reposition + * @param {element} $columnElement the column element that we want to reposition underneath + * + */ + repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) { + var menu = $elm[0].querySelectorAll('.ui-grid-menu'); + + // It's possible that the render container of the column we're attaching to is + // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft + // between the render container and the grid + var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container'), + renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left, + containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft; + + // repositionMenu is now always called after it's visible in the DOM, + // allowing us to simply get the width every time the menu is opened + var myWidth = gridUtil.elementWidth(menu, true), + paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10); + + if ( menu.length !== 0 ) { + var mid = menu[0].querySelectorAll('.ui-grid-menu-mid'); + + if ( mid.length !== 0 ) { + // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side + // Get the column menu right padding + paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10); + $scope.lastMenuPaddingRight = paddingRight; + column.lastMenuPaddingRight = paddingRight; + } + } + + var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight; + + if (left < positionData.offset + myWidth) { + left = Math.max(positionData.left - containerScrollLeft + positionData.parentLeft - paddingRight + myWidth, positionData.offset + myWidth); + } + + $elm.css('left', left + 'px'); + $elm.css('top', (positionData.top + positionData.height) + 'px'); + } + }; + return service; +}]) + + +.directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document', +function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) { +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridColumnMenu + * @description Provides the column menu framework, leverages uiGridMenu underneath + * + */ + + return { + priority: 0, + scope: true, + require: '^uiGrid', + templateUrl: 'ui-grid/uiGridColumnMenu', + replace: true, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridColumnMenuService.initialize( $scope, uiGridCtrl ); + + $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope ); + + // Set the menu items for use with the column menu. The user can later add additional items via the watch + $scope.menuItems = $scope.defaultMenuItems; + uiGridColumnMenuService.setColMenuItemWatch( $scope ); + + function updateCurrentColStatus(menuShown) { + if ($scope.col) { + $scope.col.menuShown = menuShown; + } + } + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name showMenu + * @description Shows the column menu. If the menu is already displayed it + * calls the menu to ask it to hide (it will animate), then it repositions the menu + * to the right place whilst hidden (it will make an assumption on menu width), + * then it asks the menu to show (it will animate), then it repositions the menu again + * once we can calculate it's size. + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + */ + $scope.showMenu = function(column, $columnElement, event) { + // Update the menu status for the current column + updateCurrentColStatus(false); + // Swap to this column + $scope.col = column; + updateCurrentColStatus(true); + + // Get the position information for the column element + var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement ); + + if ($scope.menuShown) { + // we want to hide, then reposition, then show, but we want to wait for animations + // we set a variable, and then rely on the menu-hidden event to call the reposition and show + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.hideThenShow = true; + + $scope.$broadcast('hide-menu', { originalEvent: event }); + } else { + $scope.menuShown = true; + + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.$broadcast('show-menu', { originalEvent: event }); + } + }; + + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name hideMenu + * @description Hides the column menu. + * @param {boolean} broadcastTrigger true if we were triggered by a broadcast + * from the menu itself - in which case don't broadcast again as we'll get + * an infinite loop + */ + $scope.hideMenu = function( broadcastTrigger ) { + $scope.menuShown = false; + updateCurrentColStatus(false); + if ( !broadcastTrigger ) { + $scope.$broadcast('hide-menu'); + } + }; + + + $scope.$on('menu-hidden', function() { + var menuItems = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0]; + + $elm[0].removeAttribute('style'); + + if ( $scope.hideThenShow ) { + delete $scope.hideThenShow; + + $scope.$broadcast('show-menu'); + + $scope.menuShown = true; + } else { + $scope.hideMenu( true ); + + if ($scope.col && $scope.col.visible) { + // Focus on the menu button + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false) + .catch(angular.noop); + } + } + + if (menuItems) { + menuItems.onkeydown = null; + angular.forEach(menuItems.children, function removeHandlers(item) { + item.onkeydown = null; + }); + } + }); + + $scope.$on('menu-shown', function() { + $timeout(function() { + uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); + + var hasVisibleMenuItems = $scope.menuItems.some(function (menuItem) { + return menuItem.shown(); + }); + + // automatically set the focus to the first button element in the now open menu. + if (hasVisibleMenuItems) { + gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true) + .catch(angular.noop); + } + + delete $scope.colElementPosition; + delete $scope.columnElement; + addKeydownHandlersToMenu(); + }); + }); + + + /* Column methods */ + $scope.sortColumn = function (event, dir) { + event.stopPropagation(); + + $scope.grid.sortColumn($scope.col, dir, true) + .then(function () { + $scope.grid.refresh(); + $scope.hideMenu(); + }).catch(angular.noop); + }; + + $scope.unsortColumn = function () { + $scope.col.unsort(); + + $scope.grid.refresh(); + $scope.hideMenu(); + }; + + function addKeydownHandlersToMenu() { + var menu = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0], + menuItems, + visibleMenuItems = []; + + if (menu) { + menu.onkeydown = function closeMenu(event) { + if (event.keyCode === uiGridConstants.keymap.ESC) { + event.preventDefault(); + $scope.hideMenu(); + } + }; + + menuItems = menu.querySelectorAll('.ui-grid-menu-item:not(.ng-hide)'); + angular.forEach(menuItems, function filterVisibleItems(item) { + if (item.offsetParent !== null) { + this.push(item); + } + }, visibleMenuItems); + + if (visibleMenuItems.length) { + if (visibleMenuItems.length === 1) { + visibleMenuItems[0].onkeydown = function singleItemHandler(event) { + circularFocusHandler(event, true); + }; + } else { + visibleMenuItems[0].onkeydown = function firstItemHandler(event) { + circularFocusHandler(event, false, event.shiftKey, visibleMenuItems.length - 1); + }; + visibleMenuItems[visibleMenuItems.length - 1].onkeydown = function lastItemHandler(event) { + circularFocusHandler(event, false, !event.shiftKey, 0); + }; + } + } + } + + function circularFocusHandler(event, isSingleItem, shiftKeyStatus, index) { + if (event.keyCode === uiGridConstants.keymap.TAB) { + if (isSingleItem) { + event.preventDefault(); + } else if (shiftKeyStatus) { + event.preventDefault(); + visibleMenuItems[index].focus(); + } + } + } + } + + // Since we are hiding this column the default hide action will fail so we need to focus somewhere else. + var setFocusOnHideColumn = function() { + $timeout(function() { + // Get the UID of the first + var focusToGridMenu = function() { + return gridUtil.focus.byId('grid-menu', $scope.grid); + }; + + var thisIndex; + $scope.grid.columns.some(function(element, index) { + if (angular.equals(element, $scope.col)) { + thisIndex = index; + return true; + } + }); + + var previousVisibleCol; + // Try and find the next lower or nearest column to focus on + $scope.grid.columns.some(function(element, index) { + if (!element.visible) { + return false; + } // This columns index is below the current column index + else if ( index < thisIndex) { + previousVisibleCol = element; + } // This elements index is above this column index and we haven't found one that is lower + else if ( index > thisIndex && !previousVisibleCol) { + // This is the next best thing + previousVisibleCol = element; + // We've found one so use it. + return true; + } // We've reached an element with an index above this column and the previousVisibleCol variable has been set + else if (index > thisIndex && previousVisibleCol) { + // We are done. + return true; + } + }); + // If found then focus on it + if (previousVisibleCol) { + var colClass = previousVisibleCol.getColClass(); + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason) { + if (reason !== 'canceled') { // If this is canceled then don't perform the action + // The fallback action is to focus on the grid menu + return focusToGridMenu(); + } + }).catch(angular.noop); + } else { + // Fallback action to focus on the grid menu + focusToGridMenu(); + } + }); + }; + + $scope.hideColumn = function () { + $scope.col.colDef.visible = false; + $scope.col.visible = false; + + $scope.grid.queueGridRefresh(); + $scope.hideMenu(); + $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col ); + + // We are hiding so the default action of focusing on the button that opened this menu will fail. + setFocusOnHideColumn(); + }; + }, + + controller: ['$scope', function ($scope) { + var self = this; + + $scope.$watch('menuItems', function (n) { + self.menuItems = n; + }); + }] + }; +}]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) { + + return { + compile: function() { + return { + pre: function ($scope, $elm) { + $scope.col.updateFilters = function( filterable ) { + $elm.children().remove(); + if ( filterable ) { + var template = $scope.col.filterHeaderTemplate; + if (template === undefined && $scope.col.providedFilterHeaderTemplate !== '') { + if ($scope.col.filterHeaderTemplatePromise) { + $scope.col.filterHeaderTemplatePromise.then(function () { + template = $scope.col.filterHeaderTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + } + }; + + $scope.$on( '$destroy', function() { + delete $scope.col.filterable; + delete $scope.col.updateFilters; + }); + }, + post: function ($scope, $elm) { + $scope.aria = i18nService.getSafeText('headerCell.aria'); + $scope.removeFilter = function(colFilter, index) { + colFilter.term = null; + // Set the focus to the filter input after the action disables the button + gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index); + }; + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile', + function ($timeout, gridUtil, uiGridConstants, $compile) { + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + replace: true, + require: '^uiGrid', + compile: function compile() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.footerCellTemplate; + + if (template === undefined && $scope.col.providedFooterCellTemplate !== '') { + if ($scope.col.footerCellTemplatePromise) { + $scope.col.footerCellTemplatePromise.then(function () { + template = $scope.col.footerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // $elm.addClass($scope.col.getColClass(false)); + $scope.grid = uiGridCtrl.grid; + + var initColClass = $scope.col.getColClass(false); + + $elm.addClass(initColClass); + + // apply any footerCellClass + var classAdded; + + var updateClass = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.footerCellClass)) { + classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.footerCellClass; + } + contents.addClass(classAdded); + }; + + if ($scope.col.footerCellClass) { + updateClass(); + } + + $scope.col.updateAggregationValue(); + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]); + + // listen for visible rows change and update aggregation values + $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); + $scope.grid.api.core.on.rowsRendered( $scope, updateClass ); + $scope.$on( '$destroy', dataChangeDereg ); + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) { + + return { + restrict: 'EA', + replace: true, + // priority: 1000, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function ($elm, $attrs) { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + containerCtrl.footer = $elm; + + var footerTemplate = $scope.grid.options.footerTemplate; + gridUtil.getTemplate(footerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.append(newElm); + + if (containerCtrl) { + // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }).catch(angular.noop); + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-footer link'); + + var grid = uiGridCtrl.grid; + + // Don't animate footer cells + gridUtil.disableAnimations($elm); + + containerCtrl.footer = $elm; + + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }; + } + }; + }]); + +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', + function($templateCache, $compile, uiGridConstants, gridUtil) { + return { + restrict: 'EA', + replace: true, + require: '^uiGrid', + scope: true, + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + $scope.grid = uiGridCtrl.grid; + + var footerTemplate = $scope.grid.options.gridFooterTemplate; + + gridUtil.getTemplate(footerTemplate) + .then(function(contents) { + var template = angular.element(contents), + newElm = $compile(template)($scope); + + $elm.append(newElm); + }).catch(angular.noop); + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', '$rootScope', + function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService, $rootScope) { + // Do stuff after mouse has been down this many ms on the header cell + var mousedownTimeout = 500, + changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa + + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + require: ['^uiGrid', '^uiGridRenderContainer'], + replace: true, + compile: function() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.headerCellTemplate; + if (template === undefined && $scope.col.providedHeaderCellTemplate !== '') { + if ($scope.col.headerCellTemplatePromise) { + $scope.col.headerCellTemplatePromise.then(function () { + template = $scope.col.headerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var renderContainerCtrl = controllers[1]; + + $scope.i18n = { + headerCell: i18nService.getSafeText('headerCell'), + sort: i18nService.getSafeText('sort') + }; + $scope.isSortPriorityVisible = function() { + // show sort priority if column is sorted and there is at least one other sorted column + return $scope.col && $scope.col.sort && angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index) { + return angular.isNumber(element.sort.priority) && element !== $scope.col; + }); + }; + $scope.getSortDirectionAriaLabel = function() { + var col = $scope.col; + // Trying to recreate this sort of thing but it was getting messy having it in the template. + // Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending': 'none')}}. + // {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''} + var label = col.sort && col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort && col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none); + + if ($scope.isSortPriorityVisible()) { + label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1); + } + return label; + }; + + $scope.grid = uiGridCtrl.grid; + + $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId]; + + var initColClass = $scope.col.getColClass(false); + $elm.addClass(initColClass); + + // Hide the menu by default + $scope.menuShown = false; + $scope.col.menuShown = false; + + // Put asc and desc sort directions in scope + $scope.asc = uiGridConstants.ASC; + $scope.desc = uiGridConstants.DESC; + + // Store a reference to menu element + var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); + + + // apply any headerCellClass + var classAdded, + previousMouseX; + + // filter watchers + var filterDeregisters = []; + + + /* + * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart). + * Once we have a down event, we need to work out whether we have a click, a drag, or a + * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so + * we ignore it. A hold would open the menu. + * + * So, on down event, we put in place handlers for move and up events, and a timer. If the + * timer expires before we see a move or up, then we have a long press and hence a column menu open. + * If the up happens before the timer, then we have a click, and we sort if the column is sortable. + * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature + * will handle it. + * + * To deal with touch enabled devices that also have mice, we only create our handlers when + * we get the down event, and we create the corresponding handlers - if we're touchstart then + * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup. + * + * We also suppress the click action whilst this is happening - otherwise after the mouseup there + * will be a click event and that can cause the column menu to close + * + */ + $scope.downFn = function( event ) { + event.stopPropagation(); + + if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { + event = event.originalEvent; + } + + // Don't show the menu if it's not the left button + if (event.button && event.button !== 0) { + return; + } + previousMouseX = event.pageX; + + $scope.mousedownStartTime = (new Date()).getTime(); + $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout); + + $scope.mousedownTimeout.then(function () { + if ( $scope.colMenu ) { + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); + } + }).catch(angular.noop); + + uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name}); + + $scope.offAllEvents(); + if ( event.type === 'touchstart') { + $document.on('touchend', $scope.upFn); + $document.on('touchmove', $scope.moveFn); + } else if ( event.type === 'mousedown' ) { + $document.on('mouseup', $scope.upFn); + $document.on('mousemove', $scope.moveFn); + } + }; + + $scope.upFn = function( event ) { + event.stopPropagation(); + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + + var mousedownEndTime = (new Date()).getTime(); + var mousedownTime = mousedownEndTime - $scope.mousedownStartTime; + + if (mousedownTime > mousedownTimeout) { + // long click, handled above with mousedown + } + else { + // short click + if ( $scope.sortable ) { + $scope.handleClick(event); + } + } + }; + + $scope.handleKeyDown = function(event) { + if (event.keyCode === 32 || event.keyCode === 13) { + event.preventDefault(); + $scope.handleClick(event); + } + }; + + $scope.moveFn = function( event ) { + // Chrome is known to fire some bogus move events. + var changeValue = event.pageX - previousMouseX; + if ( changeValue === 0 ) { return; } + + // we're a move, so do nothing and leave for column move (if enabled) to take over + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + }; + + $scope.clickFn = function ( event ) { + event.stopPropagation(); + $contentsElm.off('click', $scope.clickFn); + }; + + + $scope.offAllEvents = function() { + $contentsElm.off('touchstart', $scope.downFn); + $contentsElm.off('mousedown', $scope.downFn); + + $document.off('touchend', $scope.upFn); + $document.off('mouseup', $scope.upFn); + + $document.off('touchmove', $scope.moveFn); + $document.off('mousemove', $scope.moveFn); + + $contentsElm.off('click', $scope.clickFn); + }; + + $scope.onDownEvents = function( type ) { + // If there is a previous event, then wait a while before + // activating the other mode - i.e. if the last event was a touch event then + // don't enable mouse events for a wee while (500ms or so) + // Avoids problems with devices that emulate mouse events when you have touch events + + switch (type) { + case 'touchmove': + case 'touchend': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $timeout(function() { + $contentsElm.on('mousedown', $scope.downFn); + }, changeModeTimeout); + break; + case 'mousemove': + case 'mouseup': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('mousedown', $scope.downFn); + $timeout(function() { + $contentsElm.on('touchstart', $scope.downFn); + }, changeModeTimeout); + break; + default: + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $contentsElm.on('mousedown', $scope.downFn); + } + }; + + var setFilter = function (updateFilters) { + if ( updateFilters ) { + if ( typeof($scope.col.updateFilters) !== 'undefined' ) { + $scope.col.updateFilters($scope.col.filterable); + } + + // if column is filterable add a filter watcher + if ($scope.col.filterable) { + $scope.col.filters.forEach( function(filter, i) { + filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { + if (n !== o) { + uiGridCtrl.grid.api.core.raise.filterChanged( $scope.col ); + uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + uiGridCtrl.grid.queueGridRefresh(); + } + })); + }); + $scope.$on('$destroy', function() { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + }); + } else { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + } + } + }; + + var updateHeaderOptions = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.headerCellClass)) { + classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.headerCellClass; + } + contents.addClass(classAdded); + + $scope.$applyAsync(function() { + var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ? + $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body']; + $scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu && + $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ]; + }); + + // Figure out whether this column is sortable or not + $scope.sortable = Boolean($scope.col.enableSorting); + + // Figure out whether this column is filterable or not + var oldFilterable = $scope.col.filterable; + $scope.col.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); + + setFilter(oldFilterable !== $scope.col.filterable); + + // figure out whether we support column menus + $scope.colMenu = ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && + $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false); + + /** + * @ngdoc property + * @name enableColumnMenu + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description if column menus are enabled, controls the column menus for this specific + * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus + * using this option. If gridOptions.enableColumnMenus === false then you get no column + * menus irrespective of the value of this option ). Defaults to true. + * + * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS: + * + *
    +               *  .ui-grid-column-menu-button {
    +               *    display: block;
    +               *  }
    +               * 
    + */ + /** + * @ngdoc property + * @name enableColumnMenus + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description Override for column menus everywhere - if set to false then you get no + * column menus. Defaults to true. + * + */ + + $scope.offAllEvents(); + + if ($scope.sortable || $scope.colMenu) { + $scope.onDownEvents(); + + $scope.$on('$destroy', function () { + $scope.offAllEvents(); + }); + } + }; + + updateHeaderOptions(); + + if ($scope.col.filterContainer === 'columnMenu' && $scope.col.filterable) { + $rootScope.$on('menu-shown', function() { + $scope.$applyAsync(function () { + setFilter($scope.col.filterable); + }); + }); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]); + + $scope.$on( '$destroy', dataChangeDereg ); + + $scope.handleClick = function(event) { + // If the shift key is being held down, add this column to the sort + // Sort this column then rebuild the grid's rows + uiGridCtrl.grid.sortColumn($scope.col, event.shiftKey) + .then(function () { + if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); } + uiGridCtrl.grid.refresh(); + }).catch(angular.noop); + }; + + $scope.headerCellArrowKeyDown = function(event) { + if (event.keyCode === uiGridConstants.keymap.SPACE || event.keyCode === uiGridConstants.keymap.ENTER) { + event.preventDefault(); + $scope.toggleMenu(event); + } + }; + + $scope.toggleMenu = function(event) { + event.stopPropagation(); + + // If the menu is already showing and we're the column the menu is on + if (uiGridCtrl.columnMenuScope.menuShown && uiGridCtrl.columnMenuScope.col === $scope.col) { + // ... hide it + uiGridCtrl.columnMenuScope.hideMenu(); + } + // If the menu is NOT showing or is showing in a different column + else { + // ... show it on our column + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm); + } + }; + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent', + function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) { + var defaultTemplate = 'ui-grid/ui-grid-header', + emptyTemplate = 'ui-grid/ui-grid-no-header'; + + return { + restrict: 'EA', + replace: true, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function() { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + updateHeaderReferences(); + + var headerTemplate; + if (!$scope.grid.options.showHeader) { + headerTemplate = emptyTemplate; + } + else { + headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate; + } + + gridUtil.getTemplate(headerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.replaceWith(newElm); + + // And update $elm to be the new element + $elm = newElm; + + updateHeaderReferences(); + + if (containerCtrl) { + // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + + + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + angular.element(headerViewport).on('scroll', scrollHandler); + $scope.$on('$destroy', function () { + angular.element(headerViewport).off('scroll', scrollHandler); + }); + } + } + + $scope.grid.queueRefresh(); + }).catch(angular.noop); + + function updateHeaderReferences() { + containerCtrl.header = containerCtrl.colContainer.header = $elm; + + var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas'); + + if (headerCanvases.length > 0) { + containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0]; + } + else { + containerCtrl.headerCanvas = null; + } + } + + function scrollHandler() { + if (uiGridCtrl.grid.isScrollingHorizontally) { + return; + } + var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid); + var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + uiGridCtrl.grid.scrollContainers(null, scrollEvent); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-header link'); + + var grid = uiGridCtrl.grid; + + // Don't animate header cells + gridUtil.disableAnimations($elm); + + function updateColumnWidths() { + // this styleBuilder always runs after the renderContainer, so we can rely on the column widths + // already being populated correctly + + var columnCache = containerCtrl.colContainer.visibleColumnCache; + + // Build the CSS + // uiGridCtrl.grid.columns.forEach(function (column) { + var ret = ''; + var canvasWidth = 0; + columnCache.forEach(function (column) { + ret = ret + column.getColClassDefinition(); + canvasWidth += column.drawnWidth; + }); + + containerCtrl.colContainer.canvasWidth = canvasWidth; + + // Return the styles back to buildStyles which pops them into the `customStyles` scope variable + return ret; + } + + containerCtrl.header = $elm; + + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + } + + // todo: remove this if by injecting gridCtrl into unit tests + if (uiGridCtrl) { + uiGridCtrl.grid.registerStyleComputation({ + priority: 15, + func: updateColumnWidths + }); + } + } + }; + } + }; + }]); +})(); + +(function() { + +angular.module('ui.grid') +.service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) { + /** + * @ngdoc service + * @name ui.grid.uiGridGridMenuService + * + * @description Methods for working with the grid menu + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name initialize + * @description Sets up the gridMenu. Most importantly, sets our + * scope onto the grid object as grid.gridMenuScope, allowing us + * to operate when passed only the grid. Second most importantly, + * we register the 'addToGridMenu' and 'removeFromGridMenu' methods + * on the core api. + * @param {$scope} $scope the scope of this gridMenu + * @param {Grid} grid the grid to which this gridMenu is associated + */ + initialize: function( $scope, grid ) { + grid.gridMenuScope = $scope; + $scope.grid = grid; + $scope.registeredMenuItems = []; + + // not certain this is needed, but would be bad to create a memory leak + $scope.$on('$destroy', function() { + if ( $scope.grid && $scope.grid.gridMenuScope ) { + $scope.grid.gridMenuScope = null; + } + if ( $scope.grid ) { + $scope.grid = null; + } + if ( $scope.registeredMenuItems ) { + $scope.registeredMenuItems = null; + } + }); + + $scope.registeredMenuItems = []; + + /** + * @ngdoc function + * @name addToGridMenu + * @methodOf ui.grid.api:PublicApi + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} items menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu ); + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.api:PublicApi + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu ); + }, + + + /** + * @ngdoc function + * @name addToGridMenu + * @propertyOf ui.grid.uiGridGridMenuService + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} menuItems menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + addToGridMenu: function( grid, menuItems ) { + if ( !angular.isArray( menuItems ) ) { + gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items'); + } else { + if ( grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : []; + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems ); + } else { + gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid'); + } + } + }, + + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.uiGridGridMenuService + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found. If there is no gridMenuScope or registeredMenuItems + * then do nothing silently - the desired result is those menu items not be present and they + * aren't. + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + removeFromGridMenu: function( grid, id ) { + var foundIndex = -1; + + if ( grid && grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) { + if ( value.id === id ) { + if (foundIndex > -1) { + gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' ); + } else { + + foundIndex = index; + } + } + }); + } + + if ( foundIndex > -1 ) { + grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 ); + } + }, + + + /** + * @ngdoc array + * @name gridMenuCustomItems + * @propertyOf ui.grid.class:GridOptions + * @description (optional) An array of menu items that should be added to + * the gridMenu. Follow the format documented in the tutorial for column + * menu customisation. The context provided to the action function will + * include context.grid. An alternative if working with dynamic menus is to use the + * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles + * some of the management of items for you. + * + */ + /** + * @ngdoc boolean + * @name gridMenuShowHideColumns + * @propertyOf ui.grid.class:GridOptions + * @description true by default, whether the grid menu should allow hide/show + * of columns + * + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name getMenuItems + * @description Decides the menu items to show in the menu. This is a + * combination of: + * + * - the default menu items that are always included, + * - any menu items that have been provided through the addMenuItem api. These + * are typically added by features within the grid + * - any menu items included in grid.options.gridMenuCustomItems. These can be + * changed dynamically, as they're always recalculated whenever we show the + * menu + * @param {$scope} $scope the scope of this gridMenu, from which we can find all + * the information that we need + * @returns {Array} an array of menu items that can be shown + */ + getMenuItems: function( $scope ) { + var menuItems = [ + // this is where we add any menu items we want to always include + ]; + + if ( $scope.grid.options.gridMenuCustomItems ) { + if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ) { + gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not'); + } else { + menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems ); + } + } + + var clearFilters = [{ + title: i18nService.getSafeText('gridMenu.clearAllFilters'), + action: function ($event) { + $scope.grid.clearAllFilters(); + }, + shown: function() { + return $scope.grid.options.enableFiltering; + }, + order: 100 + }]; + menuItems = menuItems.concat( clearFilters ); + + menuItems = menuItems.concat( $scope.registeredMenuItems ); + + if ( $scope.grid.options.gridMenuShowHideColumns !== false ) { + menuItems = menuItems.concat( service.showHideColumns( $scope ) ); + } + + menuItems.sort(function(a, b) { + return a.order - b.order; + }); + + return menuItems; + }, + + + /** + * @ngdoc array + * @name gridMenuTitleFilter + * @propertyOf ui.grid.class:GridOptions + * @description (optional) A function that takes a title string + * (usually the col.displayName), and converts it into a display value. The function + * must return either a string or a promise. + * + * Used for internationalization of the grid menu column names - for angular-translate + * you can pass $translate as the function, for i18nService you can pass getSafeText as the + * function + * @example + *
    +     *   gridOptions = {
    +     *     gridMenuTitleFilter: $translate
    +     *   }
    +     * 
    + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name showHideColumns + * @description Adds two menu items for each of the columns in columnDefs. One + * menu item for hide, one menu item for show. Each is visible when appropriate + * (show when column is not visible, hide when column is visible). Each toggles + * the visible property on the columnDef using toggleColumnVisibility + * @param {$scope} $scope of a gridMenu, which contains a reference to the grid + */ + showHideColumns: function( $scope ) { + var showHideColumns = []; + if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) { + return showHideColumns; + } + + function isColumnVisible(colDef) { + return colDef.visible === true || colDef.visible === undefined; + } + + function getColumnIcon(colDef) { + return isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel'; + } + + $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; }; + + $scope.grid.options.columnDefs.forEach( function( colDef, index ) { + if ( $scope.grid.options.enableHiding !== false && colDef.enableHiding !== false || colDef.enableHiding ) { + // add hide menu item - shows an OK icon as we only show when column is already visible + var menuItem = { + icon: getColumnIcon(colDef), + action: function($event) { + $event.stopPropagation(); + + service.toggleColumnVisibility( this.context.gridCol ); + + if ($event.target && $event.target.firstChild) { + if (angular.element($event.target)[0].nodeName === 'I') { + $event.target.className = getColumnIcon(this.context.gridCol.colDef); + } + else { + $event.target.firstChild.className = getColumnIcon(this.context.gridCol.colDef); + } + } + }, + shown: function() { + return this.context.gridCol.colDef.enableHiding !== false; + }, + context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) }, + leaveOpen: true, + order: 301 + index + }; + service.setMenuItemTitle( menuItem, colDef, $scope.grid ); + showHideColumns.push( menuItem ); + } + }); + + // add header for columns + if ( showHideColumns.length ) { + showHideColumns.unshift({ + title: i18nService.getSafeText('gridMenu.columns'), + order: 300, + templateUrl: 'ui-grid/ui-grid-menu-header-item' + }); + } + + return showHideColumns; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name setMenuItemTitle + * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu + * item if it returns a string, otherwise waiting for the promise to resolve or reject then + * putting the result into the title + * @param {object} menuItem the menuItem we want to put the title on + * @param {object} colDef the colDef from which we can get displayName, name or field + * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter + * + */ + setMenuItemTitle: function( menuItem, colDef, grid ) { + var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field ); + + if ( typeof(title) === 'string' ) { + menuItem.title = title; + } else if ( title.then ) { + // must be a promise + menuItem.title = ""; + title.then( function( successValue ) { + menuItem.title = successValue; + }, function( errorValue ) { + menuItem.title = errorValue; + }).catch(angular.noop); + } else { + gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config'); + menuItem.title = 'badconfig'; + } + }, + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name toggleColumnVisibility + * @description Toggles the visibility of an individual column. Expects to be + * provided a context that has on it a gridColumn, which is the column that + * we'll operate upon. We change the visibility, and refresh the grid as appropriate + * @param {GridColumn} gridCol the column that we want to toggle + * + */ + toggleColumnVisibility: function( gridCol ) { + gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined ); + + gridCol.grid.refresh(); + gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol ); + } + }; + + return service; +}]) + +.directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService', +function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) { + + return { + priority: 0, + scope: true, + require: ['^uiGrid'], + templateUrl: 'ui-grid/ui-grid-menu-button', + replace: true, + + link: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + + // For the aria label + $scope.i18n = { + aria: i18nService.getSafeText('gridMenu.aria') + }; + + uiGridGridMenuService.initialize($scope, uiGridCtrl.grid); + + $scope.shown = false; + + $scope.toggleOnKeydown = function(event) { + if ( + event.keyCode === uiGridConstants.keymap.ENTER || + event.keyCode === uiGridConstants.keymap.SPACE || + (event.keyCode === uiGridConstants.keymap.ESC && $scope.shown) + ) { + $scope.toggleMenu(); + } + }; + + $scope.toggleMenu = function () { + if ( $scope.shown ) { + $scope.$broadcast('hide-menu'); + $scope.shown = false; + } else { + $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope ); + $scope.$broadcast('show-menu'); + $scope.shown = true; + } + }; + + $scope.$on('menu-hidden', function() { + $scope.shown = false; + gridUtil.focus.bySelector($elm, '.ui-grid-icon-container'); + }); + } + }; +}]); +})(); + +(function() { + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridMenu + * @element style + * @restrict A + * + * @description + * Allows us to interpolate expressions in ` + I am in a box. +
    + + + xit('should apply the right class to the element', function () { + element(by.css('.blah')).getCssValue('border-top-width') + .then(function(c) { + expect(c).toContain('1px'); + }); + }); + + + */ + + + angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) { + return { + link: function($scope, $elm) { + var interpolateFn = $interpolate($elm.text(), true); + + if (interpolateFn) { + $scope.$watch(interpolateFn, function(value) { + $elm.text(value); + }); + } + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridViewport', ['gridUtil', 'ScrollEvent', + function(gridUtil, ScrollEvent) { + return { + replace: true, + scope: {}, + controllerAs: 'Viewport', + templateUrl: 'ui-grid/uiGridViewport', + require: ['^uiGrid', '^uiGridRenderContainer'], + link: function($scope, $elm, $attrs, controllers) { + // gridUtil.logDebug('viewport post-link'); + + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.containerCtrl = containerCtrl; + + var rowContainer = containerCtrl.rowContainer; + var colContainer = containerCtrl.colContainer; + + var grid = uiGridCtrl.grid; + + $scope.grid = uiGridCtrl.grid; + + // Put the containers in scope so we can get rows and columns from them + $scope.rowContainer = containerCtrl.rowContainer; + $scope.colContainer = containerCtrl.colContainer; + + // Register this viewport with its container + containerCtrl.viewport = $elm; + + /** + * @ngdoc function + * @name customScroller + * @methodOf ui.grid.class:GridOptions + * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default. + * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers + * as this allows you to do that. + * + * + *
    Example
    + *
    +           *   $scope.gridOptions = {
    +           *       customScroller: function myScrolling(uiGridViewport, scrollHandler) {
    +           *           uiGridViewport.on('scroll', function myScrollingOverride(event) {
    +           *               // Do something here
    +           *
    +           *               scrollHandler(event);
    +           *           });
    +           *       }
    +           *   };
    +           * 
    + * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid). + * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid). + */ + if (grid && grid.options && grid.options.customScroller) { + grid.options.customScroller($elm, scrollHandler); + } else { + $elm.on('scroll', scrollHandler); + } + + var ignoreScroll = false; + + function scrollHandler() { + var newScrollTop = $elm[0].scrollTop; + var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid); + + var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop); + var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + scrollEvent.newScrollTop = newScrollTop; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + if ( vertScrollPercentage > -1 ) { + scrollEvent.y = { percentage: vertScrollPercentage }; + } + + grid.scrollContainers($scope.$parent.containerId, scrollEvent); + } + + if ($scope.$parent.bindScrollVertical) { + grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll); + } + + if ($scope.$parent.bindScrollHorizontal) { + grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter); + } + + function syncVerticalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + $elm[0].scrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport); + } + + function syncHorizontalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + + function syncHorizontalHeader(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.headerViewport) { + containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + function syncHorizontalFooter(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.footerViewport) { + containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); + }, + controller: ['$scope', function ($scope) { + this.rowStyle = function () { + var rowContainer = $scope.rowContainer; + var colContainer = $scope.colContainer; + + var styles = {}; + + if (rowContainer.currentTopRow !== 0) { + // top offset based on hidden rows count + var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)"; + + styles['transform'] = translateY; + styles['-webkit-transform'] = translateY; + styles['-ms-transform'] = translateY; + } + + if (colContainer.currentFirstColumn !== 0) { + if (colContainer.grid.isRTL()) { + styles['margin-right'] = colContainer.columnOffset + 'px'; + } + else { + styles['margin-left'] = colContainer.columnOffset + 'px'; + } + } + + return styles; + }; + }] + }; + } + ]); + +})(); + +(function() { + angular.module('ui.grid') + .directive('uiGridVisible', function uiGridVisibleAction() { + return function($scope, $elm, $attr) { + $scope.$watch($attr.uiGridVisible, function(visible) { + $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible'); + }); + }; + }); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants', + 'gridClassFactory', '$parse', '$compile', + function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants, + gridClassFactory, $parse, $compile) { + // gridUtil.logDebug('ui-grid controller'); + var self = this; + var deregFunctions = []; + + self.grid = gridClassFactory.createGrid($scope.uiGrid); + + // assign $scope.$parent if appScope not already assigned + self.grid.appScope = self.grid.appScope || $scope.$parent; + + $elm.addClass('grid' + self.grid.id); + self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl'; + + + // angular.extend(self.grid.options, ); + + // all properties of grid are available on scope + $scope.grid = self.grid; + + if ($attrs.uiGridColumns) { + deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) { + self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value; + self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + + self.grid.refreshCanvas(true); + }).catch(angular.noop); + }) ); + } + + // prevents an error from being thrown when the array is not defined yet and fastWatch is on + function getSize(array) { + return array ? array.length : 0; + } + + // if fastWatch is set we watch only the length and the reference, not every individual object + if (self.grid.options.fastWatch) { + self.uiGrid = $scope.uiGrid; + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { + if ( self.grid.appScope[$scope.uiGrid.data] ) { + return self.grid.appScope[$scope.uiGrid.data].length; + } else { + return undefined; + } + }, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function() { dataWatchFunction($scope.uiGrid.data); }) ); + } + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function() { columnDefsWatchFunction($scope.uiGrid.columnDefs); }) ); + } else { + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + } + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + } + + + function columnDefsWatchFunction(n, o) { + if (n && n !== o) { + self.grid.options.columnDefs = $scope.uiGrid.columnDefs; + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, { + orderByColumnDefs: true, + preCompileCellTemplates: true + }); + } + } + + var mostRecentData; + + function dataWatchFunction(newData) { + // gridUtil.logDebug('dataWatch fired'); + var promises = []; + + if ( self.grid.options.fastWatch ) { + if (angular.isString($scope.uiGrid.data)) { + newData = self.grid.appScope.$eval($scope.uiGrid.data); + } else { + newData = $scope.uiGrid.data; + } + } + + mostRecentData = newData; + + if (newData) { + // columns length is greater than the number of row header columns, which don't count because they're created automatically + var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0); + + if ( + // If we have no columns + !hasColumns && + // ... and we don't have a ui-grid-columns attribute, which would define columns for us + !$attrs.uiGridColumns && + // ... and we have no pre-defined columns + self.grid.options.columnDefs.length === 0 && + // ... but we DO have data + newData.length > 0 + ) { + // ... then build the column definitions from the data that we have + self.grid.buildColumnDefsFromData(newData); + } + + // If we haven't built columns before and either have some columns defined or some data defined + if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) { + // Build the column set, then pre-compile the column cell templates + promises.push(self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + }).catch(angular.noop)); + } + + $q.all(promises).then(function() { + // use most recent data, rather than the potentially outdated data passed into watcher handler + self.grid.modifyRows(mostRecentData) + .then(function () { + // if (self.viewport) { + self.grid.redrawInPlace(true); + // } + + $scope.$evalAsync(function() { + self.grid.refreshCanvas(true); + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW); + }); + }).catch(angular.noop); + }).catch(angular.noop); + } + } + + var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() { + self.grid.refreshCanvas(true); + }); + + $scope.$on('$destroy', function() { + deregFunctions.forEach( function( deregFn ) { deregFn(); }); + styleWatchDereg(); + }); + + self.fireEvent = function(eventName, args) { + args = args || {}; + + // Add the grid to the event arguments if it's not there + if (angular.isUndefined(args.grid)) { + args.grid = self.grid; + } + + $scope.$broadcast(eventName, args); + }; + + self.innerCompile = function innerCompile(elm) { + $compile(elm)($scope); + }; + }]); + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGrid + * @element div + * @restrict EA + * @param {Object} uiGrid Options for the grid to use + * + * @description Create a very basic grid. + * + * @example + + + var app = angular.module('app', ['ui.grid']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + }]); + + +
    +
    +
    +
    +
    + */ +angular.module('ui.grid').directive('uiGrid', uiGridDirective); + +uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants']; +function uiGridDirective($window, gridUtil, uiGridConstants) { + return { + templateUrl: 'ui-grid/ui-grid', + scope: { + uiGrid: '=' + }, + replace: true, + transclude: true, + controller: 'uiGridController', + compile: function () { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + // Initialize scrollbars (TODO: move to controller??) + uiGridCtrl.scrollbars = []; + grid.element = $elm; + + + // See if the grid has a rendered width, if not, wait a bit and try again + var sizeCheckInterval = 100; // ms + var maxSizeChecks = 20; // 2 seconds total + var sizeChecks = 0; + + // Setup (event listeners) the grid + setup(); + + // And initialize it + init(); + + // Mark rendering complete so API events can happen + grid.renderingComplete(); + + // If the grid doesn't have size currently, wait for a bit to see if it gets size + checkSize(); + + /*-- Methods --*/ + + function checkSize() { + // If the grid has no width and we haven't checked more than times, check again in milliseconds + if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) { + setTimeout(checkSize, sizeCheckInterval); + sizeChecks++; + } else { + $scope.$applyAsync(init); + } + } + + // Setup event listeners and watchers + function setup() { + var deregisterLeftWatcher, deregisterRightWatcher; + + // Bind to window resize events + angular.element($window).on('resize', gridResize); + + // Unbind from window resize events when the grid is destroyed + $elm.on('$destroy', function () { + angular.element($window).off('resize', gridResize); + deregisterLeftWatcher(); + deregisterRightWatcher(); + }); + + // If we add a left container after render, we need to watch and react + deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + + // If we add a right container after render, we need to watch and react + deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + } + + // Initialize the directive + function init() { + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + + // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from + grid.canvasWidth = uiGridCtrl.grid.gridWidth; + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows + if (grid.gridHeight - grid.scrollbarHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) { + autoAdjustHeight(); + } + + // Run initial canvas refresh + grid.refreshCanvas(true); + } + + // Set the grid's height ourselves in the case that its height would be unusably small + function autoAdjustHeight() { + // Figure out the new height + var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight; + var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0; + var footerHeight = grid.calcFooterHeight(); + + var scrollbarHeight = 0; + if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) { + scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + var maxNumberOfFilters = 0; + // Calculates the maximum number of filters in the columns + angular.forEach(grid.options.columnDefs, function(col) { + if (col.hasOwnProperty('filter')) { + if (maxNumberOfFilters < 1) { + maxNumberOfFilters = 1; + } + } + else if (col.hasOwnProperty('filters')) { + if (maxNumberOfFilters < col.filters.length) { + maxNumberOfFilters = col.filters.length; + } + } + }); + + if (grid.options.enableFiltering && !maxNumberOfFilters) { + var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) { + return col.enableFiltering === false; + }); + + if (!allColumnsHaveFilteringTurnedOff) { + maxNumberOfFilters = 1; + } + } + + var filterHeight = maxNumberOfFilters * headerHeight; + + var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight; + + $elm.css('height', newHeight + 'px'); + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + } + + // Resize the grid on window resize events + function gridResize() { + if (!gridUtil.isVisible($elm)) { + return; + } + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + grid.refreshCanvas(true); + } + } + }; + } + }; +} +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) { + return { + restrict: 'EA', + replace: true, + template: '
    ' + + '
    ' + + '
    ', + scope: { + side: '=uiGridPinnedContainer' + }, + require: '^uiGrid', + compile: function compile() { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link'); + + var grid = uiGridCtrl.grid; + + var myWidth = 0; + + $elm.addClass('ui-grid-pinned-container-' + $scope.side); + + // Monkey-patch the viewport width function + if ($scope.side === 'left' || $scope.side === 'right') { + grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth; + } + + function monkeyPatchedGetViewportWidth() { + /*jshint validthis: true */ + var self = this; + + var viewportWidth = 0; + self.visibleColumnCache.forEach(function (column) { + viewportWidth += column.drawnWidth; + }); + + var adjustment = self.getViewportAdjustment(); + + viewportWidth = viewportWidth + adjustment.width; + + return viewportWidth; + } + + function updateContainerWidth() { + if ($scope.side === 'left' || $scope.side === 'right') { + var cols = grid.renderContainers[$scope.side].visibleColumnCache; + var width = 0; + for (var i = 0; i < cols.length; i++) { + var col = cols[i]; + width += col.drawnWidth || col.width || 0; + } + + return width; + } + } + + function updateContainerDimensions() { + var ret = ''; + + // Column containers + if ($scope.side === 'left' || $scope.side === 'right') { + myWidth = updateContainerWidth(); + + // gridUtil.logDebug('myWidth', myWidth); + + // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it + $elm.attr('style', null); + + // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; + + ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } '; + } + + return ret; + } + + grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { + myWidth = updateContainerWidth(); + + // Subtract our own width + adjustment.width -= myWidth; + adjustment.side = $scope.side; + + return adjustment; + }); + + // Register style computation to adjust for columns in `side`'s render container + grid.registerStyleComputation({ + priority: 15, + func: updateContainerDimensions + }); + } + }; + } + }; + }]); +})(); + +(function () { + angular.module('ui.grid').config(['$provide', function($provide) { + $provide.decorator('i18nService', ['$delegate', function($delegate) { + $delegate.add('en', { + headerCell: { + aria: { + defaultFilterLabel: 'Filter for column', + removeFilter: 'Remove Filter', + columnMenuButtonLabel: 'Column Menu', + column: 'Column' + }, + priority: 'Priority:', + filterLabel: "Filter for column: " + }, + aggregate: { + label: 'items' + }, + groupPanel: { + description: 'Drag a column header here and drop it to group by that column.' + }, + search: { + aria: { + selected: 'Row selected', + notSelected: 'Row not selected' + }, + placeholder: 'Search...', + showingItems: 'Showing Items:', + selectedItems: 'Selected Items:', + totalItems: 'Total Items:', + size: 'Page Size:', + first: 'First Page', + next: 'Next Page', + previous: 'Previous Page', + last: 'Last Page' + }, + selection: { + aria: { + row: 'Row' + }, + selectAll: 'Select All', + displayName: 'Row Selection Checkbox' + }, + menu: { + text: 'Choose Columns:' + }, + sort: { + ascending: 'Sort Ascending', + descending: 'Sort Descending', + none: 'Sort None', + remove: 'Remove Sort' + }, + column: { + hide: 'Hide Column' + }, + aggregation: { + count: 'total rows: ', + sum: 'total: ', + avg: 'avg: ', + min: 'min: ', + max: 'max: ' + }, + pinning: { + pinLeft: 'Pin Left', + pinRight: 'Pin Right', + unpin: 'Unpin' + }, + columnMenu: { + close: 'Close' + }, + gridMenu: { + aria: { + buttonLabel: 'Grid Menu' + }, + columns: 'Columns:', + importerTitle: 'Import file', + exporterAllAsCsv: 'Export all data as csv', + exporterVisibleAsCsv: 'Export visible data as csv', + exporterSelectedAsCsv: 'Export selected data as csv', + exporterAllAsPdf: 'Export all data as pdf', + exporterVisibleAsPdf: 'Export visible data as pdf', + exporterSelectedAsPdf: 'Export selected data as pdf', + exporterAllAsExcel: 'Export all data as excel', + exporterVisibleAsExcel: 'Export visible data as excel', + exporterSelectedAsExcel: 'Export selected data as excel', + clearAllFilters: 'Clear all filters' + }, + importer: { + noHeaders: 'Column names were unable to be derived, does the file have a header?', + noObjects: 'Objects were not able to be derived, was there data in the file other than headers?', + invalidCsv: 'File was unable to be processed, is it valid CSV?', + invalidJson: 'File was unable to be processed, is it valid Json?', + jsonNotArray: 'Imported json file must contain an array, aborting.' + }, + pagination: { + aria: { + pageToFirst: 'Page to first', + pageBack: 'Page back', + pageSelected: 'Selected page', + pageForward: 'Page forward', + pageToLast: 'Page to last' + }, + sizes: 'items per page', + totalItems: 'items', + through: 'through', + of: 'of' + }, + grouping: { + group: 'Group', + ungroup: 'Ungroup', + aggregate_count: 'Agg: Count', + aggregate_sum: 'Agg: Sum', + aggregate_max: 'Agg: Max', + aggregate_min: 'Agg: Min', + aggregate_avg: 'Agg: Avg', + aggregate_remove: 'Agg: Remove' + }, + validate: { + error: 'Error:', + minLength: 'Value should be at least THRESHOLD characters long.', + maxLength: 'Value should be at most THRESHOLD characters long.', + required: 'A value is needed.' + } + }); + return $delegate; + }]); + }]); +})(); + +(function() { + +angular.module('ui.grid') +.factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent', + function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) { + + /** + * @ngdoc object + * @name ui.grid.api:PublicApi + * @description Public Api for the core grid features + * + */ + + /** + * @ngdoc function + * @name ui.grid.class:Grid + * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in + * this prototype. One instance of Grid is created per Grid directive instance. + * @param {object} options Object map of options to pass into the grid. An 'id' property is expected. + */ + var Grid = function Grid(options) { + var self = this; + // Get the id out of the options, then remove it + if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) { + if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) { + throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.'); + } + } + else { + throw new Error('No ID provided. An ID must be given when creating a grid.'); + } + + self.id = options.id; + delete options.id; + + // Get default options + self.options = GridOptions.initialize( options ); + + /** + * @ngdoc object + * @name appScope + * @propertyOf ui.grid.class:Grid + * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller + *
    + * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference + */ + self.appScope = self.options.appScopeProvider; + + self.headerHeight = self.options.headerRowHeight; + + + /** + * @ngdoc object + * @name footerHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total footer height gridFooter + columnFooter + */ + self.footerHeight = self.calcFooterHeight(); + + + /** + * @ngdoc object + * @name columnFooterHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total column footer height + */ + self.columnFooterHeight = self.calcColumnFooterHeight(); + + self.rtl = false; + self.gridHeight = 0; + self.gridWidth = 0; + self.columnBuilders = []; + self.rowBuilders = []; + self.rowsProcessors = []; + self.columnsProcessors = []; + self.styleComputations = []; + self.viewportAdjusters = []; + self.rowHeaderColumns = []; + self.dataChangeCallbacks = {}; + self.verticalScrollSyncCallBackFns = {}; + self.horizontalScrollSyncCallBackFns = {}; + + // self.visibleRowCache = []; + + // Set of 'render' containers for self grid, which can render sets of rows + self.renderContainers = {}; + + // Create a + self.renderContainers.body = new GridRenderContainer('body', self); + + self.cellValueGetterCache = {}; + + // Cached function to use with custom row templates + self.getRowTemplateFn = null; + + + // representation of the rows on the grid. + // these are wrapped references to the actual data rows (options.data) + self.rows = []; + + // represents the columns on the grid + self.columns = []; + + /** + * @ngdoc boolean + * @name isScrollingVertically + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling vertically. Set to false via debounced method + */ + self.isScrollingVertically = false; + + /** + * @ngdoc boolean + * @name isScrollingHorizontally + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling horizontally. Set to false via debounced method + */ + self.isScrollingHorizontally = false; + + /** + * @ngdoc property + * @name scrollDirection + * @propertyOf ui.grid.class:Grid + * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection} + * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling. + * Set to NONE via debounced method + */ + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + + // if true, grid will not respond to any scroll events + self.disableScrolling = false; + + + function vertical (scrollEvent) { + self.isScrollingVertically = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce); + var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0); + + function horizontal (scrollEvent) { + self.isScrollingHorizontally = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce); + var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0); + + + /** + * @ngdoc function + * @name flagScrollingVertically + * @methodOf ui.grid.class:Grid + * @description sets isScrollingVertically to true and sets it to false in a debounced function + */ + self.flagScrollingVertically = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingVertically = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedVerticalMinDelay(scrollEvent); + } + else { + debouncedVertical(scrollEvent); + } + }; + + /** + * @ngdoc function + * @name flagScrollingHorizontally + * @methodOf ui.grid.class:Grid + * @description sets isScrollingHorizontally to true and sets it to false in a debounced function + */ + self.flagScrollingHorizontally = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingHorizontally = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedHorizontalMinDelay(scrollEvent); + } + else { + debouncedHorizontal(scrollEvent); + } + }; + + self.scrollbarHeight = 0; + self.scrollbarWidth = 0; + if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarWidth = gridUtil.getScrollbarWidth(); + } + + self.api = new GridApi(self); + + /** + * @ngdoc function + * @name refresh + * @methodOf ui.grid.api:PublicApi + * @description Refresh the rendered grid on screen. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + * If you only want to resize the grid, not regenerate all the rows + * and columns, you should consider directly calling refreshCanvas instead. + * + * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed + */ + self.api.registerMethod( 'core', 'refresh', this.refresh ); + + /** + * @ngdoc function + * @name queueGridRefresh + * @methodOf ui.grid.api:PublicApi + * @description Request a refresh of the rendered grid on screen, if multiple + * calls to queueGridRefresh are made within a digest cycle only one will execute. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + */ + self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh ); + + /** + * @ngdoc function + * @name refreshRows + * @methodOf ui.grid.api:PublicApi + * @description Runs only the rowProcessors, columns remain as they were. + * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'refreshRows', this.refreshRows ); + + /** + * @ngdoc function + * @name queueRefresh + * @methodOf ui.grid.api:PublicApi + * @description Requests execution of refreshCanvas, if multiple requests are made + * during a digest cycle only one will run. RefreshCanvas updates the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh ); + + /** + * @ngdoc function + * @name handleWindowResize + * @methodOf ui.grid.api:PublicApi + * @description Trigger a grid resize, normally this would be picked + * up by a watch on window size, but in some circumstances it is necessary + * to call this manually + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize ); + + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.api:PublicApi + * @description adds a row header column to the grid + * @param {object} column def + * @param {number} order Determines order of header column on grid. Lower order means header + * is positioned to the left of higher order headers + * + */ + self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn ); + + /** + * @ngdoc function + * @name scrollToIfNecessary + * @methodOf ui.grid.api:PublicApi + * @description Scrolls the grid to make a certain row and column combo visible, + * in the case that it is not completely visible on the screen already. + * @param {GridRow} gridRow row to make visible + * @param {GridColumn} gridCol column to make visible + * @returns {promise} a promise that is resolved when scrolling is complete + * + */ + self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} ); + + /** + * @ngdoc function + * @name scrollTo + * @methodOf ui.grid.api:PublicApi + * @description Scroll the grid such that the specified + * row and column is in view + * @param {object} rowEntity gridOptions.data[] array instance to make visible + * @param {object} colDef to make visible + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} ); + + /** + * @ngdoc function + * @name registerRowsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "rows processor" function. When the rows are updated, + * the grid calls each registered "rows processor", which has a chance + * to alter the set of rows (sorting, etc) as long as the count is not + * modified. + * + * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated rows list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier. + * + * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100, + * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor ); + + /** + * @ngdoc function + * @name registerColumnsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "columns processor" function. When the columns are updated, + * the grid calls each registered "columns processor", which has a chance + * to alter the set of columns as long as the count is not + * modified. + * + * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated columns list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier. + * + * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor ); + + /** + * @ngdoc function + * @name sortHandleNulls + * @methodOf ui.grid.api:PublicApi + * @description A null handling method that can be used when building custom sort + * functions + * @example + *
    +     *   mySortFn = function(a, b) {
    +     *   var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
    +     *   if ( nulls !== null ) {
    +     *     return nulls;
    +     *   } else {
    +     *     // your code for sorting here
    +     *   };
    +     * 
    + * @param {object} a sort value a + * @param {object} b sort value b + * @returns {number} null if there were no nulls/undefineds, otherwise returns + * a sort value that should be passed back from the sort function + * + */ + self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls ); + + /** + * @ngdoc function + * @name sortChanged + * @methodOf ui.grid.api:PublicApi + * @description The sort criteria on one or more columns has + * changed. Provides as parameters the grid and the output of + * getColumnSorting, which is an array of gridColumns + * that have sorting on them, sorted in priority order. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of + * columns with sorts on them, in priority order. + * + * @example + *
    +     *      gridApi.core.on.sortChanged( $scope, function(grid, sortColumns) {
    +     *        // do something
    +     *      });
    +     * 
    + */ + self.api.registerEvent( 'core', 'sortChanged' ); + + /** + * @ngdoc function + * @name columnVisibilityChanged + * @methodOf ui.grid.api:PublicApi + * @description The visibility of a column has changed, + * the column itself is passed out as a parameter of the event. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed. + * + * @example + *
    +     *      gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
    +     *        // do something
    +     *      } );
    +     * 
    + */ + self.api.registerEvent( 'core', 'columnVisibilityChanged' ); + + /** + * @ngdoc method + * @name notifyDataChange + * @methodOf ui.grid.api:PublicApi + * @description Notify the grid that a data or config change has occurred, + * where that change isn't something the grid was otherwise noticing. This + * might be particularly relevant where you've changed values within the data + * and you'd like cell classes to be re-evaluated, or changed config within + * the columnDef and you'd like headerCellClasses to be re-evaluated. + * @param {string} type one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS), which tells us which refreshes to fire. + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange ); + + /** + * @ngdoc method + * @name clearAllFilters + * @methodOf ui.grid.api:PublicApi + * @description Clears all filters and optionally refreshes the visible rows. + * @param {object} refreshRows Defaults to true. + * @param {object} clearConditions Defaults to false. + * @param {object} clearFlags Defaults to false. + * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing. + */ + self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters); + + self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]); + self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]); + self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]); + + self.registerStyleComputation({ + priority: 10, + func: self.getFooterStyles + }); + }; + + Grid.prototype.calcFooterHeight = function () { + if (!this.hasFooter()) { + return 0; + } + + var height = 0; + if (this.options.showGridFooter) { + height += this.options.gridFooterHeight; + } + + height += this.calcColumnFooterHeight(); + + return height; + }; + + Grid.prototype.calcColumnFooterHeight = function () { + var height = 0; + + if (this.options.showColumnFooter) { + height += this.options.columnFooterHeight; + } + + return height; + }; + + Grid.prototype.getFooterStyles = function () { + var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }'; + style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }'; + return style; + }; + + Grid.prototype.hasFooter = function () { + return this.options.showGridFooter || this.options.showColumnFooter; + }; + + /** + * @ngdoc function + * @name isRTL + * @methodOf ui.grid.class:Grid + * @description Returns true if grid is RightToLeft + */ + Grid.prototype.isRTL = function () { + return this.rtl; + }; + + + /** + * @ngdoc function + * @name registerColumnBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates columns from column definitions, the columnbuilders will be called to add + * additional properties to the column. + * @param {function(colDef, col, gridOptions)} columnBuilder function to be called + */ + Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) { + this.columnBuilders.push(columnBuilder); + }; + + /** + * @ngdoc function + * @name buildColumnDefsFromData + * @methodOf ui.grid.class:Grid + * @description Populates columnDefs from the provided data + * @param {function(colDef, col, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.buildColumnDefsFromData = function (dataRows) { + this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties); + }; + + /** + * @ngdoc function + * @name registerRowBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add + * additional properties to the row. + * @param {function(row, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) { + this.rowBuilders.push(rowBuilder); + }; + + /** + * @ngdoc function + * @name registerDataChangeCallback + * @methodOf ui.grid.class:Grid + * @description When a data change occurs, the data change callbacks of the specified type + * will be called. The rules are: + * + * - when the data watch fires, that is considered a ROW change (the data watch only notices + * added or removed rows) + * - when the api is called to inform us of a change, the declared type of that change is used + * - when a cell edit completes, the EDIT callbacks are triggered + * - when the columnDef watch fires, the COLUMN callbacks are triggered + * - when the options watch fires, the OPTIONS callbacks are triggered + * + * For a given event: + * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks + * - ROW calls ROW and ALL callbacks + * - EDIT calls EDIT and ALL callbacks + * - COLUMN calls COLUMN and ALL callbacks + * - OPTIONS calls OPTIONS and ALL callbacks + * + * @param {function(grid)} callback function to be called + * @param {array} types the types of data change you want to be informed of. Values from + * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL + * @returns {function} deregister function - a function that can be called to deregister this callback + */ + Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) { + var self = this, + uid = gridUtil.nextUid(); + + if ( !types ) { + types = [uiGridConstants.dataChange.ALL]; + } + if ( !Array.isArray(types)) { + gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types ); + } + this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this: _this }; + + return function() { + delete self.dataChangeCallbacks[uid]; + }; + }; + + /** + * @ngdoc function + * @name callDataChangeCallbacks + * @methodOf ui.grid.class:Grid + * @description Calls the callbacks based on the type of data change that + * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the + * event type is matching, or if the type is ALL. + * @param {string} type the type of event that occurred - one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS) + */ + Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) { + angular.forEach( this.dataChangeCallbacks, function( callback, uid ) { + if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 || + callback.types.indexOf( type ) !== -1 || + type === uiGridConstants.dataChange.ALL ) { + if (callback._this) { + callback.callback.apply(callback._this, this, options); + } + else { + callback.callback(this, options); + } + } + }, this); + }; + + /** + * @ngdoc function + * @name notifyDataChange + * @methodOf ui.grid.class:Grid + * @description Notifies us that a data change has occurred, used in the public + * api for users to tell us when they've changed data or some other event that + * our watches cannot pick up + * @param {string} type the type of event that occurred - one of the + * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS) + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + Grid.prototype.notifyDataChange = function notifyDataChange(type) { + var constants = uiGridConstants.dataChange; + + if ( type === constants.ALL || + type === constants.COLUMN || + type === constants.EDIT || + type === constants.ROW || + type === constants.OPTIONS ) { + this.callDataChangeCallbacks( type ); + } + else { + gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type); + } + }; + + /** + * @ngdoc function + * @name columnRefreshCallback + * @methodOf ui.grid.class:Grid + * @description refreshes the grid when a column refresh + * is notified, which triggers handling of the visible flag. + * This is called on uiGridConstants.dataChange.COLUMN, and is + * registered as a dataChangeCallback in grid.js + * @param {object} grid The grid object. + * @param {object} options Any options passed into the callback. + */ + Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options) { + grid.buildColumns(options); + grid.queueGridRefresh(); + }; + + /** + * @ngdoc function + * @name processRowsCallback + * @methodOf ui.grid.class:Grid + * @description calls the row processors, specifically + * intended to reset the sorting when an edit is called, + * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT + * @param {object} grid The grid object. + */ + Grid.prototype.processRowsCallback = function processRowsCallback( grid ) { + grid.queueGridRefresh(); + }; + + + /** + * @ngdoc function + * @name updateFooterHeightCallback + * @methodOf ui.grid.class:Grid + * @description recalculates the footer height, + * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS + * @param {object} grid The grid object. + */ + Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ) { + grid.footerHeight = grid.calcFooterHeight(); + grid.columnFooterHeight = grid.calcColumnFooterHeight(); + }; + + + /** + * @ngdoc function + * @name getColumn + * @methodOf ui.grid.class:Grid + * @description returns a grid column for the column name + * @param {string} name column name + */ + Grid.prototype.getColumn = function getColumn(name) { + var columns = this.columns.filter(function (column) { + return column.colDef.name === name; + }); + + return columns.length > 0 ? columns[0] : null; + }; + + /** + * @ngdoc function + * @name getColDef + * @methodOf ui.grid.class:Grid + * @description returns a grid colDef for the column name + * @param {string} name column.field + */ + Grid.prototype.getColDef = function getColDef(name) { + var colDefs = this.options.columnDefs.filter(function (colDef) { + return colDef.name === name; + }); + return colDefs.length > 0 ? colDefs[0] : null; + }; + + /** + * @ngdoc function + * @name assignTypes + * @methodOf ui.grid.class:Grid + * @description uses the first row of data to assign colDef.type for any types not defined. + */ + /** + * @ngdoc property + * @name type + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description the type of the column, used in sorting. If not provided then the + * grid will guess the type. Add this only if the grid guessing is not to your + * satisfaction. One of: + * - 'string' + * - 'boolean' + * - 'number' + * - 'date' + * - 'object' + * - 'numberStr' + * Note that if you choose date, your dates should be in a javascript date type + * + */ + Grid.prototype.assignTypes = function() { + var self = this; + + self.options.columnDefs.forEach(function (colDef, index) { + // Assign colDef type if not specified + if (!colDef.type) { + var col = new GridColumn(colDef, index, self); + var firstRow = self.rows.length > 0 ? self.rows[0] : null; + if (firstRow) { + colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col)); + } + else { + colDef.type = 'string'; + } + } + }); + }; + + + /** + * @ngdoc function + * @name isRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description returns true if the column is a row Header + * @param {object} column column + */ + Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) { + return this.rowHeaderColumns.indexOf(column) !== -1; + }; + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description adds a row header column to the grid + * @param {object} colDef Column definition object. + * @param {float} order Number that indicates where the column should be placed in the grid. + * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve + * performance of the grid during initial load. + */ + Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) { + var self = this; + + // default order + if (order === undefined) { + order = 0; + } + + var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self); + rowHeaderCol.isRowHeader = true; + if (self.isRTL()) { + self.createRightContainer(); + rowHeaderCol.renderContainer = 'right'; + } + else { + self.createLeftContainer(); + rowHeaderCol.renderContainer = 'left'; + } + + // relies on the default column builder being first in array, as it is instantiated + // as part of grid creation + self.columnBuilders[0](colDef,rowHeaderCol,self.options) + .then(function() { + rowHeaderCol.enableFiltering = false; + rowHeaderCol.enableSorting = false; + rowHeaderCol.enableHiding = false; + rowHeaderCol.headerPriority = order; + self.rowHeaderColumns.push(rowHeaderCol); + self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) { + return a.headerPriority - b.headerPriority; + }); + + if (!stopColumnBuild) { + self.buildColumns() + .then(function() { + self.preCompileCellTemplates(); + self.queueGridRefresh(); + }).catch(angular.noop); + } + }).catch(angular.noop); + }; + + /** + * @ngdoc function + * @name getOnlyDataColumns + * @methodOf ui.grid.class:Grid + * @description returns all columns except for rowHeader columns + */ + Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() { + var self = this, + cols = []; + + self.columns.forEach(function (col) { + if (self.rowHeaderColumns.indexOf(col) === -1) { + cols.push(col); + } + }); + return cols; + }; + + /** + * @ngdoc function + * @name buildColumns + * @methodOf ui.grid.class:Grid + * @description creates GridColumn objects from the columnDefinition. Calls each registered + * columnBuilder to further process the column + * @param {object} opts An object contains options to use when building columns + * + * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions. + * + * @returns {Promise} a promise to load any needed column resources + */ + Grid.prototype.buildColumns = function buildColumns(opts) { + var options = { + orderByColumnDefs: false + }; + + angular.extend(options, opts); + + // gridUtil.logDebug('buildColumns'); + var self = this; + var builderPromises = []; + var headerOffset = self.rowHeaderColumns.length; + var i; + + // Remove any columns for which a columnDef cannot be found + // Deliberately don't use forEach, as it doesn't like splice being called in the middle + // Also don't cache columns.length, as it will change during this operation + for (i = 0; i < self.columns.length; i++) { + if (!self.getColDef(self.columns[i].name)) { + self.columns.splice(i, 1); + i--; + } + } + + // add row header columns to the grid columns array _after_ columns without columnDefs have been removed + // rowHeaderColumns is ordered by priority so insert in reverse + for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) { + self.columns.unshift(self.rowHeaderColumns[j]); + } + + // look at each column def, and update column properties to match. If the column def + // doesn't have a column, then splice in a new gridCol + self.options.columnDefs.forEach(function (colDef, index) { + self.preprocessColDef(colDef); + var col = self.getColumn(colDef.name); + + if (!col) { + col = new GridColumn(colDef, gridUtil.nextUid(), self); + self.columns.splice(index + headerOffset, 0, col); + } + else { + // tell updateColumnDef that the column was pre-existing + col.updateColumnDef(colDef, false); + } + + self.columnBuilders.forEach(function (builder) { + builderPromises.push(builder.call(self, colDef, col, self.options)); + }); + }); + + /*** Reorder columns if necessary ***/ + if (!!options.orderByColumnDefs) { + // Create a shallow copy of the columns as a cache + var columnCache = self.columns.slice(0); + + // We need to allow for the "row headers" when mapping from the column defs array to the columns array + // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0] + + // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then + // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result + var len = Math.min(self.options.columnDefs.length, self.columns.length); + for (i = 0; i < len; i++) { + // If the column at this index has a different name than the column at the same index in the column defs... + if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) { + // Replace the one in the cache with the appropriate column + columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name); + } + else { + // Otherwise just copy over the one from the initial columns + columnCache[i + headerOffset] = self.columns[i + headerOffset]; + } + } + + // Empty out the columns array, non-destructively + self.columns.length = 0; + + // And splice in the updated, ordered columns from the cache + Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache)); + } + + return $q.all(builderPromises).then(function() { + if (self.rows.length > 0) { + self.assignTypes(); + } + if (options.preCompileCellTemplates) { + self.preCompileCellTemplates(); + } + }).catch(angular.noop); + }; + + Grid.prototype.preCompileCellTemplate = function(col) { + var self = this; + var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col)); + html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + col.compiledElementFn = $compile(html); + + if (col.compiledElementFnDefer) { + col.compiledElementFnDefer.resolve(col.compiledElementFn); + } + }; + +/** + * @ngdoc function + * @name preCompileCellTemplates + * @methodOf ui.grid.class:Grid + * @description precompiles all cell templates + */ + Grid.prototype.preCompileCellTemplates = function() { + var self = this; + self.columns.forEach(function (col) { + if ( col.cellTemplate ) { + self.preCompileCellTemplate( col ); + } else if ( col.cellTemplatePromise ) { + col.cellTemplatePromise.then( function() { + self.preCompileCellTemplate( col ); + }).catch(angular.noop); + } + }); + }; + + /** + * @ngdoc function + * @name getGridQualifiedColField + * @methodOf ui.grid.class:Grid + * @description Returns the $parse-able accessor for a column within its $scope + * @param {GridColumn} col col object + */ + Grid.prototype.getQualifiedColField = function (col) { + var base = 'row.entity'; + if ( col.field === uiGridConstants.ENTITY_BINDING ) { + return base; + } + return gridUtil.preEval(base + '.' + col.field); + }; + + /** + * @ngdoc function + * @name createLeftContainer + * @methodOf ui.grid.class:Grid + * @description creates the left render container if it doesn't already exist + */ + Grid.prototype.createLeftContainer = function() { + if (!this.hasLeftContainer()) { + this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name createRightContainer + * @methodOf ui.grid.class:Grid + * @description creates the right render container if it doesn't already exist + */ + Grid.prototype.createRightContainer = function() { + if (!this.hasRightContainer()) { + this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name hasLeftContainer + * @methodOf ui.grid.class:Grid + * @description returns true if leftContainer exists + */ + Grid.prototype.hasLeftContainer = function() { + return this.renderContainers.left !== undefined; + }; + + /** + * @ngdoc function + * @name hasRightContainer + * @methodOf ui.grid.class:Grid + * @description returns true if rightContainer exists + */ + Grid.prototype.hasRightContainer = function() { + return this.renderContainers.right !== undefined; + }; + + + /** + * undocumented function + * @name preprocessColDef + * @methodOf ui.grid.class:Grid + * @description defaults the name property from field to maintain backwards compatibility with 2.x + * validates that name or field is present + */ + Grid.prototype.preprocessColDef = function preprocessColDef(colDef) { + var self = this; + + if (!colDef.field && !colDef.name) { + throw new Error('colDef.name or colDef.field property is required'); + } + + // maintain backwards compatibility with 2.x + // field was required in 2.x. now name is required + if (colDef.name === undefined && colDef.field !== undefined) { + // See if the column name already exists: + var newName = colDef.field, + counter = 2; + while (self.getColumn(newName)) { + newName = colDef.field + counter.toString(); + counter++; + } + colDef.name = newName; + } + }; + + // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters + Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) { + var self = this; + + var t = []; + for (var i = 0; i < n.length; i++) { + var nV = nAccessor ? n[i][nAccessor] : n[i]; + + var found = false; + for (var j = 0; j < o.length; j++) { + var oV = oAccessor ? o[j][oAccessor] : o[j]; + if (self.options.rowEquality(nV, oV)) { + found = true; + break; + } + } + if (!found) { + t.push(nV); + } + } + + return t; + }; + + /** + * @ngdoc function + * @name getRow + * @methodOf ui.grid.class:Grid + * @description returns the GridRow that contains the rowEntity + * @param {object} rowEntity the gridOptions.data array element instance + * @param {array} lookInRows [optional] the rows to look in - if not provided then + * looks in grid.rows + */ + Grid.prototype.getRow = function getRow(rowEntity, lookInRows) { + var self = this; + + lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows; + + var rows = lookInRows.filter(function (row) { + return self.options.rowEquality(row.entity, rowEntity); + }); + return rows.length > 0 ? rows[0] : null; + }; + + + /** + * @ngdoc function + * @name modifyRows + * @methodOf ui.grid.class:Grid + * @description creates or removes GridRow objects from the newRawData array. Calls each registered + * rowBuilder to further process the row + * @param {array} newRawData Modified set of data + * + * This method aims to achieve three things: + * 1. the resulting rows array is in the same order as the newRawData, we'll call + * rowsProcessors immediately after to sort the data anyway + * 2. if we have row hashing available, we try to use the rowHash to find the row + * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected + * + * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates + * the newRows and newHash + * + * ``` + * newRawData.forEach newEntity + * if (hashing enabled) + * check oldHash for newEntity + * else + * look for old row directly in oldRows + * if !oldRowFound // must be a new row + * create newRow + * append to the newRows and add to newHash + * run the processors + * ``` + * + * Rows are identified using the hashKey if configured. If not configured, then rows + * are identified using the gridOptions.rowEquality function + * + * This method is useful when trying to select rows immediately after loading data without + * using a $timeout/$interval, e.g.: + * + * $scope.gridOptions.data = someData; + * $scope.gridApi.grid.modifyRows($scope.gridOptions.data); + * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); + * + * OR to persist row selection after data update (e.g. rows selected, new data loaded, want + * originally selected rows to be re-selected)) + */ + Grid.prototype.modifyRows = function modifyRows(newRawData) { + var self = this; + var oldRows = self.rows.slice(0); + var oldRowHash = self.rowHashMap || self.createRowHashMap(); + var allRowsSelected = true; + self.rowHashMap = self.createRowHashMap(); + self.rows.length = 0; + + newRawData.forEach( function( newEntity, i ) { + var newRow, oldRow; + + if ( self.options.enableRowHashing ) { + // if hashing is enabled, then this row will be in the hash if we already know about it + oldRow = oldRowHash.get( newEntity ); + } else { + // otherwise, manually search the oldRows to see if we can find this row + oldRow = self.getRow(newEntity, oldRows); + } + + // update newRow to have an entity + if ( oldRow ) { + newRow = oldRow; + newRow.entity = newEntity; + } + + // if we didn't find the row, it must be new, so create it + if ( !newRow ) { + newRow = self.processRowBuilders(new GridRow(newEntity, i, self)); + } + + self.rows.push( newRow ); + self.rowHashMap.put( newEntity, newRow ); + if (!newRow.isSelected) { + allRowsSelected = false; + } + }); + + if (self.selection && self.rows.length) { + self.selection.selectAll = allRowsSelected; + } + + self.assignTypes(); + + var p1 = $q.when(self.processRowsProcessors(self.rows)) + .then(function (renderableRows) { + return self.setVisibleRows(renderableRows); + }).catch(angular.noop); + + var p2 = $q.when(self.processColumnsProcessors(self.columns)) + .then(function (renderableColumns) { + return self.setVisibleColumns(renderableColumns); + }).catch(angular.noop); + + return $q.all([p1, p2]); + }; + + + /** + * Private Undocumented Method + * @name addRows + * @methodOf ui.grid.class:Grid + * @description adds the newRawData array of rows to the grid and calls all registered + * rowBuilders. this keyword will reference the grid + */ + Grid.prototype.addRows = function addRows(newRawData) { + var self = this, + existingRowCount = self.rows.length; + + for (var i = 0; i < newRawData.length; i++) { + var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self)); + + if (self.options.enableRowHashing) { + var found = self.rowHashMap.get(newRow.entity); + if (found) { + found.row = newRow; + } + } + + self.rows.push(newRow); + } + }; + + /** + * @ngdoc function + * @name processRowBuilders + * @methodOf ui.grid.class:Grid + * @description processes all RowBuilders for the gridRow + * @param {GridRow} gridRow reference to gridRow + * @returns {GridRow} the gridRow with all additional behavior added + */ + Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) { + var self = this; + + self.rowBuilders.forEach(function (builder) { + builder.call(self, gridRow, self.options); + }); + + return gridRow; + }; + + /** + * @ngdoc function + * @name registerStyleComputation + * @methodOf ui.grid.class:Grid + * @description registered a styleComputation function + * + * If the function returns a value it will be appended into the grid's `
    " + ); + + + $templateCache.put('ui-grid/uiGridCell', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/uiGridColumnMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridFooterCell', + "
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    " + ); + + + $templateCache.put('ui-grid/uiGridHeaderCell', + "
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
     
    " + ); + + + $templateCache.put('ui-grid/uiGridMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridMenuItem', + "" + ); + + + $templateCache.put('ui-grid/uiGridRenderContainer', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridViewport', + "
    " + ); + +}]); diff --git a/src/ui-grid.core.min.js b/src/ui-grid.core.min.js new file mode 100644 index 0000000000..66b22f2720 --- /dev/null +++ b/src/ui-grid.core.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";angular.module("ui.grid.i18n",[]),angular.module("ui.grid",["ui.grid.i18n"])}(),function(){"use strict";angular.module("ui.grid").constant("uiGridConstants",{LOG_DEBUG_MESSAGES:!0,LOG_WARN_MESSAGES:!0,LOG_ERROR_MESSAGES:!0,CUSTOM_FILTERS:/CUSTOM_FILTERS/g,COL_FIELD:/COL_FIELD/g,MODEL_COL_FIELD:/MODEL_COL_FIELD/g,TOOLTIP:/title=\"TOOLTIP\"/g,DISPLAY_CELL_TEMPLATE:/DISPLAY_CELL_TEMPLATE/g,TEMPLATE_REGEXP:/<.+>/,FUNC_REGEXP:/(\([^)]*\))?$/,DOT_REGEXP:/\./g,APOS_REGEXP:/'/g,BRACKET_REGEXP:/^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,COL_CLASS_PREFIX:"ui-grid-col",ENTITY_BINDING:"$$this",events:{GRID_SCROLL:"uiGridScroll",COLUMN_MENU_SHOWN:"uiGridColMenuShown",ITEM_DRAGGING:"uiGridItemDragStart",COLUMN_HEADER_CLICK:"uiGridColumnHeaderClick"},keymap:{TAB:9,STRG:17,CAPSLOCK:20,CTRL:17,CTRLRIGHT:18,CTRLR:18,SHIFT:16,RETURN:13,ENTER:13,BACKSPACE:8,BCKSP:8,ALT:18,ALTR:17,ALTRIGHT:17,SPACE:32,WIN:91,MAC:91,FN:null,PG_UP:33,PG_DOWN:34,UP:38,DOWN:40,LEFT:37,RIGHT:39,ESC:27,DEL:46,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123},ASC:"asc",DESC:"desc",filter:{STARTS_WITH:2,ENDS_WITH:4,EXACT:8,CONTAINS:16,GREATER_THAN:32,GREATER_THAN_OR_EQUAL:64,LESS_THAN:128,LESS_THAN_OR_EQUAL:256,NOT_EQUAL:512,SELECT:"select",INPUT:"input"},aggregationTypes:{sum:2,count:4,avg:8,min:16,max:32},CURRENCY_SYMBOLS:["¤","؋","Ar","Ƀ","฿","B/.","Br","Bs.","Bs.F.","GH₵","¢","c","Ch.","₡","C$","D","ден","دج",".د.ب","د.ع","JD","د.ك","ل.د","дин","د.ت","د.م.","د.إ","Db","$","₫","Esc","€","ƒ","Ft","FBu","FCFA","CFA","Fr","FRw","G","gr","₲","h","₴","₭","Kč","kr","kn","MK","ZK","Kz","K","L","Le","лв","E","lp","M","KM","MT","₥","Nfk","₦","Nu.","UM","T$","MOP$","₱","Pt.","£","ج.م.","LL","LS","P","Q","q","R","R$","ر.ع.","ر.ق","ر.س","៛","RM","p","Rf.","₹","₨","SRe","Rp","₪","Ksh","Sh.So.","USh","S/","SDR","сом","৳\t","WS$","₮","VT","₩","¥","zł"],scrollDirection:{UP:"up",DOWN:"down",LEFT:"left",RIGHT:"right",NONE:"none"},dataChange:{ALL:"all",EDIT:"edit",ROW:"row",COLUMN:"column",OPTIONS:"options"},scrollbars:{NEVER:0,ALWAYS:1,WHEN_NEEDED:2}})}(),angular.module("ui.grid").directive("uiGridCell",["$compile","$parse","gridUtil","uiGridConstants",function(l,e,a,s){return{priority:0,scope:!1,require:"?^uiGrid",compile:function(){return{pre:function(t,r,e,i){if(i&&t.col.compiledElementFn)(0,t.col.compiledElementFn)(t,function(e,t){r.append(e)});else if(i&&!t.col.compiledElementFn)t.col.getCompiledElementFn().then(function(e){e(t,function(e,t){r.append(e)})}).catch(angular.noop);else{var n=t.col.cellTemplate.replace(s.MODEL_COL_FIELD,"row.entity."+a.preEval(t.col.field)).replace(s.COL_FIELD,"grid.getCellValue(row, col)"),o=l(n)(t);r.append(o)}},post:function(i,n){var o,l=i.col.getColClass(!1);function a(e){var t=n;o&&(t.removeClass(o),o=null),o=angular.isFunction(i.col.cellClass)?i.col.cellClass(i.grid,i.row,i.col,i.rowRenderIndex,i.colRenderIndex):i.col.cellClass,t.addClass(o)}n.addClass(l),i.col.cellClass&&a();var e=i.grid.registerDataChangeCallback(a,[s.dataChange.COLUMN,s.dataChange.EDIT]);var t=i.$watch("row",function(e,t){if(e!==t){(o||i.col.cellClass)&&a();var r=i.col.getColClass(!1);r!==l&&(n.removeClass(l),n.addClass(r),l=r)}});function r(){e(),t()}i.$on("$destroy",r),n.on("$destroy",r)}}}}}]),angular.module("ui.grid").service("uiGridColumnMenuService",["i18nService","uiGridConstants","gridUtil",function(e,r,g){var i={initialize:function(e,t){e.grid=t.grid,(t.columnMenuScope=e).menuShown=!1},setColMenuItemWatch:function(t){var e=t.$watch("col.menuItems",function(e){void 0!==e&&e&&angular.isArray(e)?(e.forEach(function(e){void 0!==e.context&&e.context||(e.context={}),e.context.col=t.col}),t.menuItems=t.defaultMenuItems.concat(e)):t.menuItems=t.defaultMenuItems});t.$on("$destroy",e)},getGridOption:function(e,t){return void 0!==e.grid&&e.grid&&e.grid.options&&e.grid.options[t]},sortable:function(e){return Boolean(this.getGridOption(e,"enableSorting")&&void 0!==e.col&&e.col&&e.col.enableSorting)},isActiveSort:function(e,t){return Boolean(void 0!==e.col&&void 0!==e.col.sort&&void 0!==e.col.sort.direction&&e.col.sort.direction===t)},suppressRemoveSort:function(e){return Boolean(e.col&&e.col.suppressRemoveSort)},hideable:function(e){return Boolean(this.getGridOption(e,"enableHiding")&&void 0!==e.col&&e.col&&(e.col.colDef&&!1!==e.col.colDef.enableHiding||!e.col.colDef)||!this.getGridOption(e,"enableHiding")&&e.col&&e.col.colDef&&e.col.colDef.enableHiding)},getDefaultMenuItems:function(t){return[{title:function(){return e.getSafeText("sort.ascending")},icon:"ui-grid-icon-sort-alt-up",action:function(e){e.stopPropagation(),t.sortColumn(e,r.ASC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.ASC)}},{title:function(){return e.getSafeText("sort.descending")},icon:"ui-grid-icon-sort-alt-down",action:function(e){e.stopPropagation(),t.sortColumn(e,r.DESC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.DESC)}},{title:function(){return e.getSafeText("sort.remove")},icon:"ui-grid-icon-cancel",action:function(e){e.stopPropagation(),t.unsortColumn()},shown:function(){return i.sortable(t)&&void 0!==t.col&&void 0!==t.col.sort&&void 0!==t.col.sort.direction&&null!==t.col.sort.direction&&!i.suppressRemoveSort(t)}},{title:function(){return e.getSafeText("column.hide")},icon:"ui-grid-icon-cancel",shown:function(){return i.hideable(t)},action:function(e){e.stopPropagation(),t.hideColumn()}}]},getColumnElementPosition:function(e,t,r){var i={};return i.left=r[0].offsetLeft,i.top=r[0].offsetTop,i.parentLeft=r[0].offsetParent.offsetLeft,i.offset=0,t.grid.options.offsetLeft&&(i.offset=t.grid.options.offsetLeft),i.height=g.elementHeight(r,!0),i.width=g.elementWidth(r,!0),i},repositionMenu:function(e,t,r,i,n){var o=i[0].querySelectorAll(".ui-grid-menu"),l=g.closestElm(n,".ui-grid-render-container"),a=l.getBoundingClientRect().left-e.grid.element[0].getBoundingClientRect().left,s=l.querySelectorAll(".ui-grid-viewport")[0].scrollLeft,c=g.elementWidth(o,!0),u=t.lastMenuPaddingRight?t.lastMenuPaddingRight:e.lastMenuPaddingRight?e.lastMenuPaddingRight:10;0!==o.length&&0!==o[0].querySelectorAll(".ui-grid-menu-mid").length&&(u=parseInt(g.getStyles(angular.element(o)[0]).paddingRight,10),e.lastMenuPaddingRight=u,t.lastMenuPaddingRight=u);var d=r.left+a-s+r.parentLeft+r.width+u;d(u.grid.rowHeaderColumns?u.grid.rowHeaderColumns.length:0);!r&&!n.uiGridColumns&&0===u.grid.options.columnDefs.length&&0
    ',scope:{side:"=uiGridPinnedContainer"},require:"^uiGrid",compile:function(){return{post:function(n,t,e,r){var o=r.grid,i=0;function l(){if("left"===n.side||"right"===n.side){for(var e=o.renderContainers[n.side].visibleColumnCache,t=0,r=0;r=t&&(t=e.sort.priority+1)}),t},e.prototype.resetColumnSorting=function(t){this.columns.forEach(function(e){e===t||e.suppressRemoveSort||(e.sort={})})},e.prototype.getColumnSorting=function(){var t=[];return this.columns.slice(0).sort(h.prioritySort).forEach(function(e){e.sort&&void 0!==e.sort.direction&&e.sort.direction&&(e.sort.direction===s.ASC||e.sort.direction===s.DESC)&&t.push(e)}),t},e.prototype.sortColumn=function(e,t,r){var i=this,n=null;if(void 0===e||!e)throw new Error("No column parameter provided");if("boolean"==typeof t?r=t:n=t,!r||i.options&&i.options.suppressMultiSort?(i.resetColumnSorting(e),e.sort.priority=void 0,e.sort.priority=i.getNextColumnSortPriority()):void 0===e.sort.priority&&(e.sort.priority=i.getNextColumnSortPriority()),n)e.sort.direction=n;else{var o=e.sortDirectionCycle.indexOf(e.sort&&e.sort.direction?e.sort.direction:null);o=(o+1)%e.sortDirectionCycle.length,e.colDef&&e.suppressRemoveSort&&!e.sortDirectionCycle[o]&&(o=(o+1)%e.sortDirectionCycle.length),e.sortDirectionCycle[o]?e.sort.direction=e.sortDirectionCycle[o]:l(e,i)}return i.api.core.raise.sortChanged(i,i.getColumnSorting()),S.when(e)};var l=function(t,e){e.columns.forEach(function(e){e.sort&&void 0!==e.sort.priority&&e.sort.priority>t.sort.priority&&(e.sort.priority-=1)}),t.sort={}};function a(e,t){return e||0Math.ceil(s)&&(u=h-s+r.renderContainers.body.prevScrollTop,i.y=T(u+r.options.rowHeight,g,r.renderContainers.body.prevScrolltopPercentage))}if(null!==t){for(var p=o.indexOf(t),f=r.renderContainers.body.getCanvasWidth()-r.renderContainers.body.getViewportWidth(),m=0,v=0;vt&&(e.sort.priority-=1)}),this.sort={},this.grid.api.core.raise.sortChanged(this.grid,this.grid.getColumnSorting())},t.prototype.getColClass=function(e){var t=u.COL_CLASS_PREFIX+this.uid;return e?"."+t:t},t.prototype.isPinnedLeft=function(){return"left"===this.renderContainer},t.prototype.isPinnedRight=function(){return"right"===this.renderContainer},t.prototype.getColClassDefinition=function(){return" .grid"+this.grid.id+" "+this.getColClass(!0)+" { min-width: "+this.drawnWidth+"px; max-width: "+this.drawnWidth+"px; }"},t.prototype.getRenderContainer=function(){var e=this.renderContainer;return null!==e&&""!==e&&void 0!==e||(e="body"),this.grid.renderContainers[e]},t.prototype.showColumn=function(){this.colDef.visible=!0},t.prototype.getAggregationText=function(){if(this.colDef.aggregationHideLabel)return"";if(this.colDef.aggregationLabel)return this.colDef.aggregationLabel;switch(this.colDef.aggregationType){case u.aggregationTypes.count:return e.getSafeText("aggregation.count");case u.aggregationTypes.sum:return e.getSafeText("aggregation.sum");case u.aggregationTypes.avg:return e.getSafeText("aggregation.avg");case u.aggregationTypes.min:return e.getSafeText("aggregation.min");case u.aggregationTypes.max:return e.getSafeText("aggregation.max");default:return""}},t.prototype.getCellTemplate=function(){return this.cellTemplatePromise},t.prototype.getCompiledElementFn=function(){return this.compiledElementFnDefer.promise},t}]),angular.module("ui.grid").factory("GridOptions",["gridUtil","uiGridConstants",function(t,r){return{initialize:function(e){return e.onRegisterApi=e.onRegisterApi||angular.noop(),e.data=e.data||[],e.columnDefs=e.columnDefs||[],e.excludeProperties=e.excludeProperties||["$$hashKey"],e.enableRowHashing=!1!==e.enableRowHashing,e.rowIdentity=e.rowIdentity||function(e){return t.hashKey(e)},e.getRowIdentity=e.getRowIdentity||function(e){return e.$$hashKey},e.flatEntityAccess=!0===e.flatEntityAccess,e.showHeader=void 0===e.showHeader||e.showHeader,e.showHeader?e.headerRowHeight=void 0!==e.headerRowHeight?e.headerRowHeight:30:e.headerRowHeight=0,"string"==typeof e.rowHeight?e.rowHeight=parseInt(e.rowHeight)||30:e.rowHeight=e.rowHeight||30,e.minRowsToShow=void 0!==e.minRowsToShow?e.minRowsToShow:10,e.showGridFooter=!0===e.showGridFooter,e.showColumnFooter=!0===e.showColumnFooter,e.columnFooterHeight=void 0!==e.columnFooterHeight?e.columnFooterHeight:30,e.gridFooterHeight=void 0!==e.gridFooterHeight?e.gridFooterHeight:30,e.columnWidth=void 0!==e.columnWidth?e.columnWidth:50,e.maxVisibleColumnCount=void 0!==e.maxVisibleColumnCount?e.maxVisibleColumnCount:200,e.virtualizationThreshold=void 0!==e.virtualizationThreshold?e.virtualizationThreshold:20,e.columnVirtualizationThreshold=void 0!==e.columnVirtualizationThreshold?e.columnVirtualizationThreshold:10,e.excessRows=void 0!==e.excessRows?e.excessRows:4,e.scrollThreshold=void 0!==e.scrollThreshold?e.scrollThreshold:4,e.excessColumns=void 0!==e.excessColumns?e.excessColumns:4,e.aggregationCalcThrottle=void 0!==e.aggregationCalcThrottle?e.aggregationCalcThrottle:500,e.wheelScrollThrottle=void 0!==e.wheelScrollThrottle?e.wheelScrollThrottle:70,e.scrollDebounce=void 0!==e.scrollDebounce?e.scrollDebounce:300,e.enableHiding=!1!==e.enableHiding,e.enableSorting=!1!==e.enableSorting,e.suppressMultiSort=!0===e.suppressMultiSort,e.enableFiltering=!0===e.enableFiltering,e.filterContainer=void 0!==e.filterContainer?e.filterContainer:"headerCell",e.enableColumnMenus=!1!==e.enableColumnMenus,e.enableVerticalScrollbar=void 0!==e.enableVerticalScrollbar?e.enableVerticalScrollbar:r.scrollbars.ALWAYS,e.enableHorizontalScrollbar=void 0!==e.enableHorizontalScrollbar?e.enableHorizontalScrollbar:r.scrollbars.ALWAYS,e.enableMinHeightCheck=!1!==e.enableMinHeightCheck,e.minimumColumnSize=void 0!==e.minimumColumnSize?e.minimumColumnSize:30,e.rowEquality=e.rowEquality||function(e,t){return e===t},e.headerTemplate=e.headerTemplate||null,e.footerTemplate=e.footerTemplate||"ui-grid/ui-grid-footer",e.gridFooterTemplate=e.gridFooterTemplate||"ui-grid/ui-grid-grid-footer",e.rowTemplate=e.rowTemplate||"ui-grid/ui-grid-row",e.gridMenuTemplate=e.gridMenuTemplate||"ui-grid/uiGridMenu",e.menuButtonTemplate=e.menuButtonTemplate||"ui-grid/ui-grid-menu-button",e.menuItemTemplate=e.menuItemTemplate||"ui-grid/uiGridMenuItem",e.appScopeProvider=e.appScopeProvider||null,e}}}]),angular.module("ui.grid").factory("GridRenderContainer",["gridUtil","uiGridConstants",function(y,n){function e(e,t,r){var i=this;i.name=e,i.grid=t,i.visibleRowCache=[],i.visibleColumnCache=[],i.renderedRows=[],i.renderedColumns=[],i.prevScrollTop=0,i.prevScrolltopPercentage=0,i.prevRowScrollIndex=0,i.prevScrollLeft=0,i.prevScrollleftPercentage=0,i.prevColumnScrollIndex=0,i.columnStyles="",i.viewportAdjusters=[],i.hasHScrollbar=!1,i.hasVScrollbar=!1,i.canvasHeightShouldUpdate=!0,i.$$canvasHeight=0,r&&angular.isObject(r)&&angular.extend(i,r),t.registerStyleComputation({priority:5,func:function(){return i.updateColumnWidths(),i.columnStyles}})}return e.prototype.reset=function(){this.visibleColumnCache.length=0,this.visibleRowCache.length=0,this.renderedRows.length=0,this.renderedColumns.length=0},e.prototype.containsColumn=function(e){return-1!==this.visibleColumnCache.indexOf(e)},e.prototype.minRowsToRender=function(){for(var e=0,t=0,r=this.getViewportHeight(),i=this.visibleRowCache.length-1;ti.grid.options.virtualizationThreshold){if(null!=e){if(!i.grid.suppressParentScrollDown&&i.prevScrollTope&&a>i.prevRowScrollIndex-i.grid.options.scrollThreshold&&at.grid.options.columnVirtualizationThreshold&&t.getCanvasWidth()>t.getViewportWidth())l=[Math.max(0,o-t.grid.options.excessColumns),Math.min(i.length,o+r+t.grid.options.excessColumns)];else{var a=t.visibleColumnCache.length;l=[0,Math.max(a,r+t.grid.options.excessColumns)]}t.updateViewableColumnRange(l),t.prevColumnScrollIndex=o},e.prototype.getLeftIndex=function(e){for(var t=0,r=0;re.maxWidth&&(t=e.maxWidth),te.maxWidth&&(t=e.maxWidth),te.minWidth&&0e.offsetWidth)},e.prototype.getViewportStyle=function(){var e=this,t={},r={};return r[n.scrollbars.ALWAYS]="scroll",r[n.scrollbars.WHEN_NEEDED]="auto",e.hasHScrollbar=!1,e.hasVScrollbar=!1,e.grid.disableScrolling?(t["overflow-x"]="hidden",t["overflow-y"]="hidden"):("body"===e.name?(e.hasHScrollbar=e.grid.options.enableHorizontalScrollbar!==n.scrollbars.NEVER,e.grid.isRTL()?e.grid.hasLeftContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER):e.grid.hasRightContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER)):"left"===e.name?e.hasVScrollbar=!!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER:e.hasVScrollbar=!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER,t["overflow-x"]=e.hasHScrollbar?r[e.grid.options.enableHorizontalScrollbar]:"hidden",t["overflow-y"]=e.hasVScrollbar?r[e.grid.options.enableVerticalScrollbar]:"hidden"),t},e}]),angular.module("ui.grid").factory("GridRow",["gridUtil","uiGridConstants",function(i,t){function e(e,t,r){this.grid=r,this.entity=e,this.index=t,this.uid=i.nextUid(),this.visible=!0,this.isSelected=!1,this.$$height=r.options.rowHeight}return Object.defineProperty(e.prototype,"height",{get:function(){return this.$$height},set:function(e){e!==this.$$height&&(this.grid.updateCanvasHeight(),this.$$height=e)}}),e.prototype.getQualifiedColField=function(e){return"row."+this.getEntityQualifiedColField(e)},e.prototype.getEntityQualifiedColField=function(e){return e.field===t.ENTITY_BINDING?"entity":i.preEval("entity."+e.field)},e.prototype.setRowInvisible=function(e){e&&e.setThisRowInvisible&&e.setThisRowInvisible("user")},e.prototype.clearRowInvisible=function(e){e&&e.clearThisRowInvisible&&e.clearThisRowInvisible("user")},e.prototype.setThisRowInvisible=function(e,t){this.invisibleReason||(this.invisibleReason={}),this.invisibleReason[e]=!0,this.evaluateRowVisibility(t)},e.prototype.clearThisRowInvisible=function(e,t){void 0!==this.invisibleReason&&delete this.invisibleReason[e],this.evaluateRowVisibility(t)},e.prototype.evaluateRowVisibility=function(e){var r=!0;void 0!==this.invisibleReason&&angular.forEach(this.invisibleReason,function(e,t){e&&(r=!1)}),void 0!==this.visible&&this.visible===r||(this.visible=r,e||(this.grid.queueGridRefresh(),this.grid.api.core.raise.rowsVisibleChanged(this)))},e}]),function(){"use strict";angular.module("ui.grid").factory("GridRowColumn",["$parse","$filter",function(e,t){var r=function e(t,r){if(!(this instanceof e))throw"Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";this.row=t,this.col=r};return r.prototype.getIntersectionValueRaw=function(){return e(this.row.getEntityQualifiedColField(this.col))(this.row)},r}])}(),angular.module("ui.grid").factory("ScrollEvent",["gridUtil",function(l){function e(e,t,r,i){var n=this;if(!e)throw new Error("grid argument is required");n.grid=e,n.source=i,n.withDelay=!0,n.sourceRowContainer=t,n.sourceColContainer=r,n.newScrollLeft=null,n.newScrollTop=null,n.x=null,n.y=null,n.verticalScrollLength=-9999999,n.horizontalScrollLength=-999999,n.fireThrottledScrollingEvent=l.throttle(function(e){n.grid.scrollContainers(e,n)},n.grid.options.wheelScrollThrottle,{trailing:!0})}return e.prototype.getNewScrollLeft=function(e,t){var r=this;if(r.newScrollLeft)return r.newScrollLeft;var i,n=e.getCanvasWidth()-e.getViewportWidth(),o=l.normalizeScrollLeft(t,r.grid);if(void 0!==r.x.percentage&&void 0!==r.x.percentage)i=r.x.percentage;else{if(void 0===r.x.pixels||void 0===r.x.pixels)throw new Error("No percentage or pixel value provided for scroll event X axis");i=r.x.percentage=(o+r.x.pixels)/n}return Math.max(0,i*n)},e.prototype.getNewScrollTop=function(e,t){var r=this;if(r.newScrollTop)return r.newScrollTop;var i,n=e.getVerticalScrollLength(),o=t[0].scrollTop;if(void 0!==r.y.percentage&&void 0!==r.y.percentage)i=r.y.percentage;else{if(void 0===r.y.pixels||void 0===r.y.pixels)throw new Error("No percentage or pixel value provided for scroll event Y axis");i=r.y.percentage=(o+r.y.pixels)/n}return Math.max(0,i*n)},e.prototype.atTop=function(e){return this.y&&(0===this.y.percentage||this.verticalScrollLength<0)&&0===e},e.prototype.atBottom=function(e){return this.y&&(1===this.y.percentage||0===this.verticalScrollLength)&&0
    ')[0],r="reverse";return document.body.appendChild(t),0
     
     
    '),e.put("ui-grid/ui-grid-footer",''),e.put("ui-grid/ui-grid-grid-footer",''),e.put("ui-grid/ui-grid-header",'
    \x3c!-- theader --\x3e
    '),e.put("ui-grid/ui-grid-menu-button",'
     
    '),e.put("ui-grid/ui-grid-menu-header-item",'
  • '),e.put("ui-grid/ui-grid-no-header",'
    '),e.put("ui-grid/ui-grid-row","
    "),e.put("ui-grid/ui-grid",'
    \x3c!-- TODO (c0bra): add "scoped" attr here, eventually? --\x3e
    '),e.put("ui-grid/uiGridCell",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),e.put("ui-grid/uiGridColumnMenu",'
    \x3c!--
    \n
    \n
      \n
      \n
    • Sort Ascending
    • \n
    • Sort Descending
    • \n
    • Remove Sort
    • \n
      \n
    \n
    \n
    --\x3e
    '),e.put("ui-grid/uiGridFooterCell",'
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    '),e.put("ui-grid/uiGridHeaderCell",'
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
    '),e.put("ui-grid/uiGridMenu",'
    '),e.put("ui-grid/uiGridMenuItem",''),e.put("ui-grid/uiGridRenderContainer","
    \x3c!-- All of these dom elements are replaced in place --\x3e
    "),e.put("ui-grid/uiGridViewport",'
    \x3c!-- tbody --\x3e
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.css b/src/ui-grid.css new file mode 100644 index 0000000000..6754d5a835 --- /dev/null +++ b/src/ui-grid.css @@ -0,0 +1,1414 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ +.ui-grid { + border: 1px solid #d4d4d4; + box-sizing: content-box; + -webkit-border-radius: 0px; + -moz-border-radius: 0px; + border-radius: 0px; + -webkit-transform: translateZ(0); + -moz-transform: translateZ(0); + -o-transform: translateZ(0); + -ms-transform: translateZ(0); + transform: translateZ(0); +} +.ui-grid-vertical-bar { + position: absolute; + right: 0; + width: 0; +} +.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar, +.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-scrollbar-placeholder { + background-color: transparent; +} +.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-header-cell:last-child .ui-grid-vertical-bar { + right: -1px; + width: 1px; + background-color: #d4d4d4; +} +.ui-grid-clearfix:before, +.ui-grid-clearfix:after { + content: ""; + display: table; +} +.ui-grid-clearfix:after { + clear: both; +} +.ui-grid-invisible { + visibility: hidden; +} +.ui-grid-contents-wrapper { + position: relative; + height: 100%; + width: 100%; +} +.ui-grid-sr-only { + position: absolute; + width: 1px; + height: 1px; + margin: -1px; + padding: 0; + overflow: hidden; + clip: rect(0, 0, 0, 0); + border: 0; +} +.ui-grid-icon-button { + background-color: transparent; + border: none; + padding: 0; +} +.clickable { + cursor: pointer; +} +.ui-grid-top-panel-background { + background-color: #f3f3f3; +} +.ui-grid-header { + border-bottom: 1px solid #d4d4d4; + box-sizing: border-box; +} +.ui-grid-top-panel { + position: relative; + overflow: hidden; + font-weight: bold; + background-color: #f3f3f3; + -webkit-border-top-right-radius: -1px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: -1px; + -moz-border-radius-topright: -1px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: -1px; + border-top-right-radius: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: -1px; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-header-viewport { + overflow: hidden; +} +.ui-grid-header-canvas:before, +.ui-grid-header-canvas:after { + content: ""; + display: -ms-flexbox; + display: flex; + line-height: 0; +} +.ui-grid-header-canvas:after { + clear: both; +} +.ui-grid-header-cell-wrapper { + position: relative; + display: -ms-flexbox; + display: flex; + box-sizing: border-box; + height: 100%; + width: 100%; +} +.ui-grid-header-cell-row { + display: -ms-flexbox; + display: flex; + -ms-flex-direction: row; + flex-direction: row; + -ms-flex-wrap: wrap; + flex-wrap: wrap; +} +.ui-grid-header-cell { + position: relative; + box-sizing: border-box; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + width: 0; +} +.ui-grid-header-cell:last-child { + border-right: 0; +} +.ui-grid-header-cell .sortable { + cursor: pointer; +} +.ui-grid-header-cell .ui-grid-sort-priority-number { + margin-left: -8px; +} +/* Fixes IE word-wrap if needed on header cells */ +.ui-grid-header-cell > div { + -ms-flex-basis: 100%; + flex-basis: 100%; +} +.ui-grid-header .ui-grid-vertical-bar { + top: 0; + bottom: 0; +} +.ui-grid-column-menu-button { + position: absolute; + right: 1px; + top: 0; +} +.ui-grid-column-menu-button .ui-grid-icon-angle-down { + vertical-align: sub; +} +.ui-grid-header-cell-last-col .ui-grid-cell-contents, +.ui-grid-header-cell-last-col .ui-grid-filter-container, +.ui-grid-header-cell-last-col .ui-grid-column-menu-button, +.ui-grid-header-cell-last-col + .ui-grid-column-resizer.right { + margin-right: 13px; +} +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-cell-contents, +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-filter-container, +.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-column-menu-button, +.ui-grid-render-container-right .ui-grid-header-cell-last-col + .ui-grid-column-resizer.right { + margin-right: 28px; +} +.ui-grid-column-menu { + position: absolute; +} +/* Slide up/down animations */ +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transition: all 0.04s linear; + -moz-transition: all 0.04s linear; + -o-transition: all 0.04s linear; + transition: all 0.04s linear; + display: block !important; +} +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transform: translateY(-100%); + -moz-transform: translateY(-100%); + -o-transform: translateY(-100%); + -ms-transform: translateY(-100%); + transform: translateY(-100%); +} +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active { + -webkit-transform: translateY(0); + -moz-transform: translateY(0); + -o-transform: translateY(0); + -ms-transform: translateY(0); + transform: translateY(0); +} +/* Slide up/down animations */ +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transition: all 0.04s linear; + -moz-transition: all 0.04s linear; + -o-transition: all 0.04s linear; + transition: all 0.04s linear; + display: block !important; +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove { + -webkit-transform: translateY(-100%); + -moz-transform: translateY(-100%); + -o-transform: translateY(-100%); + -ms-transform: translateY(-100%); + transform: translateY(-100%); +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add, +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active { + -webkit-transform: translateY(0); + -moz-transform: translateY(0); + -o-transform: translateY(0); + -ms-transform: translateY(0); + transform: translateY(0); +} +.ui-grid-filter-container { + padding: 4px 10px; + position: relative; +} +.ui-grid-filter-container .ui-grid-filter-button { + position: absolute; + top: 0; + bottom: 0; + right: 0; +} +.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"] { + position: absolute; + top: 50%; + line-height: 32px; + margin-top: -16px; + right: 10px; + opacity: 0.66; +} +.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]:hover { + opacity: 1; +} +.ui-grid-filter-container .ui-grid-filter-button-select { + position: absolute; + top: 0; + bottom: 0; + right: 0; +} +.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"] { + position: absolute; + top: 50%; + line-height: 32px; + margin-top: -16px; + right: 0px; + opacity: 0.66; +} +.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]:hover { + opacity: 1; +} +input[type="text"].ui-grid-filter-input { + box-sizing: border-box; + padding: 0 18px 0 0; + margin: 0; + width: 100%; + border: 1px solid #d4d4d4; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +input[type="text"].ui-grid-filter-input:hover { + border: 1px solid #d4d4d4; +} +select.ui-grid-filter-select { + padding: 0; + margin: 0; + border: 0; + width: 90%; + border: 1px solid #d4d4d4; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +select.ui-grid-filter-select:hover { + border: 1px solid #d4d4d4; +} +.ui-grid-filter-cancel-button-hidden select.ui-grid-filter-select { + width: 100%; +} +.ui-grid-render-container { + position: inherit; + -webkit-border-top-right-radius: 0; + -webkit-border-bottom-right-radius: 0px; + -webkit-border-bottom-left-radius: 0px; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0; + -moz-border-radius-bottomright: 0px; + -moz-border-radius-bottomleft: 0px; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0; + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-render-container:focus { + outline: none; +} +.ui-grid-viewport { + min-height: 20px; + position: relative; + overflow-y: scroll; + -webkit-overflow-scrolling: touch; +} +.ui-grid-viewport:focus { + outline: none !important; +} +.ui-grid-canvas { + position: relative; + padding-top: 1px; + min-height: 1px; +} +.ui-grid-row { + clear: both; +} +.ui-grid-row:nth-child(odd) .ui-grid-cell { + background-color: #fdfdfd; +} +.ui-grid-row:nth-child(even) .ui-grid-cell { + background-color: #f3f3f3; +} +.ui-grid-row:last-child .ui-grid-cell { + border-bottom-color: #d4d4d4; + border-bottom-style: solid; +} +.ui-grid-row:hover > [ui-grid-row] > .ui-grid-cell:hover .ui-grid-cell, +.ui-grid-row:nth-child(odd):hover .ui-grid-cell, +.ui-grid-row:nth-child(even):hover .ui-grid-cell { + background-color: #d5eaee; +} +.ui-grid-no-row-overlay { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + margin: 10%; + background-color: #f3f3f3; + -webkit-border-top-right-radius: 0px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: 0; + border-top-right-radius: 0px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; + border: 1px solid #d4d4d4; + font-size: 2em; + text-align: center; +} +.ui-grid-no-row-overlay > * { + position: absolute; + display: table; + margin: auto 0; + width: 100%; + top: 0; + bottom: 0; + left: 0; + right: 0; + opacity: 0.66; +} +.ui-grid-cell { + overflow: hidden; + float: left; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + box-sizing: border-box; +} +.ui-grid-cell:last-child { + border-right: 0; +} +.ui-grid-cell-contents { + padding: 5px; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + white-space: nowrap; + -ms-text-overflow: ellipsis; + -o-text-overflow: ellipsis; + text-overflow: ellipsis; + overflow: hidden; + height: 100%; +} +.ui-grid-cell-contents-hidden { + visibility: hidden; + width: 0; + height: 0; + display: none; +} +.ui-grid-row .ui-grid-cell.ui-grid-row-header-cell { + background-color: #F0F0EE; + border-bottom: solid 1px #d4d4d4; +} +.ui-grid-cell-empty { + display: inline-block; + width: 10px; + height: 10px; +} +.ui-grid-footer-info { + padding: 5px 10px; +} +.ui-grid-footer-panel-background { + background-color: #f3f3f3; +} +.ui-grid-footer-panel { + position: relative; + border-bottom: 1px solid #d4d4d4; + border-top: 1px solid #d4d4d4; + overflow: hidden; + font-weight: bold; + background-color: #f3f3f3; + -webkit-border-top-right-radius: -1px; + -webkit-border-bottom-right-radius: 0; + -webkit-border-bottom-left-radius: 0; + -webkit-border-top-left-radius: -1px; + -moz-border-radius-topright: -1px; + -moz-border-radius-bottomright: 0; + -moz-border-radius-bottomleft: 0; + -moz-border-radius-topleft: -1px; + border-top-right-radius: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + border-top-left-radius: -1px; + -moz-background-clip: padding-box; + -webkit-background-clip: padding-box; + background-clip: padding-box; +} +.ui-grid-grid-footer { + float: left; + width: 100%; +} +.ui-grid-footer-viewport, +.ui-grid-footer-canvas { + height: 100%; +} +.ui-grid-footer-viewport { + overflow: hidden; +} +.ui-grid-footer-canvas { + position: relative; +} +.ui-grid-footer-canvas:before, +.ui-grid-footer-canvas:after { + content: ""; + display: table; + line-height: 0; +} +.ui-grid-footer-canvas:after { + clear: both; +} +.ui-grid-footer-cell-wrapper { + position: relative; + display: table; + box-sizing: border-box; + height: 100%; +} +.ui-grid-footer-cell-row { + display: table-row; +} +.ui-grid-footer-cell { + overflow: hidden; + background-color: inherit; + border-right: 1px solid; + border-color: #d4d4d4; + box-sizing: border-box; + display: table-cell; +} +.ui-grid-footer-cell:last-child { + border-right: 0; +} +.ui-grid-menu-button { + z-index: 2; + position: absolute; + right: 0; + top: 0; + background: #f3f3f3; + border: 0; + border-left: 1px solid #d4d4d4; + border-bottom: 1px solid #d4d4d4; + cursor: pointer; + height: 32px; + font-weight: normal; +} +.ui-grid-menu-button .ui-grid-icon-container { + margin-top: 5px; + margin-left: 2px; +} +.ui-grid-menu-button .ui-grid-menu { + right: 0; +} +.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid { + overflow: scroll; +} +.ui-grid-menu { + overflow: hidden; + max-width: 320px; + z-index: 2; + position: absolute; + right: 100%; + padding: 0 10px 20px 10px; + cursor: pointer; + box-sizing: border-box; +} +.ui-grid-menu-item { + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.ui-grid-menu .ui-grid-menu-inner { + background: #fff; + border: 1px solid #d4d4d4; + position: relative; + white-space: nowrap; + -webkit-border-radius: 0px; + -moz-border-radius: 0px; + border-radius: 0px; +} +.ui-grid-menu .ui-grid-menu-inner ul { + margin: 0; + padding: 0; + list-style-type: none; +} +.ui-grid-menu .ui-grid-menu-inner ul li { + padding: 0; +} +.ui-grid-menu .ui-grid-menu-inner ul li .ui-grid-menu-item { + color: #000; + min-width: 100%; + padding: 8px; + text-align: left; + background: transparent; + border: none; + cursor: default; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item { + cursor: pointer; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:hover, +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:focus { + background-color: #b3c4c7; +} +.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item.ui-grid-menu-item-active { + background-color: #9cb2b6; +} +.ui-grid-menu .ui-grid-menu-inner ul li:not(:last-child) > .ui-grid-menu-item { + border-bottom: 1px solid #d4d4d4; +} +.ui-grid-sortarrow { + right: 5px; + position: absolute; + width: 20px; + top: 0; + bottom: 0; + background-position: center; +} +.ui-grid-sortarrow.down { + -webkit-transform: rotate(180deg); + -moz-transform: rotate(180deg); + -o-transform: rotate(180deg); + -ms-transform: rotate(180deg); + transform: rotate(180deg); +} +@font-face { + font-family: 'ui-grid'; + src: url('fonts/ui-grid.eot'); + src: url('fonts/ui-grid.eot#iefix') format('embedded-opentype'), url('fonts/ui-grid.woff') format('woff'), url('fonts/ui-grid.ttf') format('truetype'), url('fonts/ui-grid.svg?#ui-grid') format('svg'); + font-weight: normal; + font-style: normal; +} +/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */ +/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */ +/* +@media screen and (-webkit-min-device-pixel-ratio:0) { + @font-face { + font-family: 'ui-grid'; + src: url('@{font-path}ui-grid.svg?12312827#ui-grid') format('svg'); + } +} +*/ +[class^="ui-grid-icon"]:before, +[class*=" ui-grid-icon"]:before { + font-family: "ui-grid"; + font-style: normal; + font-weight: normal; + speak: none; + display: inline-block; + text-decoration: inherit; + width: 1em; + margin-right: 0.2em; + text-align: center; + /* opacity: .8; */ + /* For safety - reset parent styles, that can break glyph codes*/ + font-variant: normal; + text-transform: none; + /* fix buttons height, for twitter bootstrap */ + line-height: 1em; + /* Animation center compensation - margins should be symmetric */ + /* remove if not needed */ + margin-left: 0.2em; + /* you can be more comfortable with increased icons size */ + /* font-size: 120%; */ + /* Uncomment for 3D effect */ + /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */ +} +.ui-grid-icon-blank::before { + width: 1em; + content: ' '; +} +.ui-grid-icon-plus-squared:before { + content: '\c350'; +} +.ui-grid-icon-minus-squared:before { + content: '\c351'; +} +.ui-grid-icon-search:before { + content: '\c352'; +} +.ui-grid-icon-cancel:before { + content: '\c353'; +} +.ui-grid-icon-info-circled:before { + content: '\c354'; +} +.ui-grid-icon-lock:before { + content: '\c355'; +} +.ui-grid-icon-lock-open:before { + content: '\c356'; +} +.ui-grid-icon-pencil:before { + content: '\c357'; +} +.ui-grid-icon-down-dir:before { + content: '\c358'; +} +.ui-grid-icon-up-dir:before { + content: '\c359'; +} +.ui-grid-icon-left-dir:before { + content: '\c35a'; +} +.ui-grid-icon-right-dir:before { + content: '\c35b'; +} +.ui-grid-icon-left-open:before { + content: '\c35c'; +} +.ui-grid-icon-right-open:before { + content: '\c35d'; +} +.ui-grid-icon-angle-down:before { + content: '\c35e'; +} +.ui-grid-icon-filter:before { + content: '\c35f'; +} +.ui-grid-icon-sort-alt-up:before { + content: '\c360'; +} +.ui-grid-icon-sort-alt-down:before { + content: '\c361'; +} +.ui-grid-icon-ok:before { + content: '\c362'; +} +.ui-grid-icon-menu:before { + content: '\c363'; +} +.ui-grid-icon-indent-left:before { + content: '\e800'; +} +.ui-grid-icon-indent-right:before { + content: '\e801'; +} +.ui-grid-icon-spin5:before { + content: '\ea61'; +} +/* +* RTL Styles +*/ +.ui-grid[dir=rtl] .ui-grid-header-cell, +.ui-grid[dir=rtl] .ui-grid-footer-cell, +.ui-grid[dir=rtl] .ui-grid-cell { + float: right !important; +} +.ui-grid[dir=rtl] .ui-grid-column-menu-button { + position: absolute; + left: 1px; + top: 0; + right: inherit; +} +.ui-grid[dir=rtl] .ui-grid-cell:first-child, +.ui-grid[dir=rtl] .ui-grid-header-cell:first-child, +.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child { + border-right: 0; +} +.ui-grid[dir=rtl] .ui-grid-cell:last-child, +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child { + border-right: 1px solid #d4d4d4; + border-left: 0; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:first-child .ui-grid-vertical-bar, +.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child .ui-grid-vertical-bar, +.ui-grid[dir=rtl] .ui-grid-cell:first-child .ui-grid-vertical-bar { + width: 0; +} +.ui-grid[dir=rtl] .ui-grid-menu-button { + z-index: 2; + position: absolute; + left: 0; + right: auto; + background: #f3f3f3; + border: 1px solid #d4d4d4; + cursor: pointer; + min-height: 27px; + font-weight: normal; +} +.ui-grid[dir=rtl] .ui-grid-menu-button .ui-grid-menu { + left: 0; + right: auto; +} +.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button { + right: initial; + left: 0; +} +.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"] { + right: initial; + left: 10px; +} +/* + Animation example, for spinners +*/ +.ui-grid-animate-spin { + -moz-animation: ui-grid-spin 2s infinite linear; + -o-animation: ui-grid-spin 2s infinite linear; + -webkit-animation: ui-grid-spin 2s infinite linear; + animation: ui-grid-spin 2s infinite linear; + display: inline-block; +} +@-moz-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-webkit-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-o-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@-ms-keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@keyframes ui-grid-spin { + 0% { + -moz-transform: rotate(0deg); + -o-transform: rotate(0deg); + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + 100% { + -moz-transform: rotate(359deg); + -o-transform: rotate(359deg); + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} + +.ui-grid-cell-focus { + outline: 0; + background-color: #b3c4c7; +} +.ui-grid-focuser { + position: absolute; + left: 0; + top: 0; + z-index: -1; + width: 100%; + height: 100%; +} +.ui-grid-focuser:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-offscreen { + display: block; + position: absolute; + left: -10000px; + top: -10000px; + clip: rect(0px, 0px, 0px, 0px); +} + +.ui-grid-cell input { + border-radius: inherit; + padding: 0; + width: 100%; + color: inherit; + height: auto; + font: inherit; + outline: none; +} +.ui-grid-cell input:focus { + color: inherit; + outline: none; +} +.ui-grid-cell input[type="checkbox"] { + margin: 9px 0 0 6px; + width: auto; +} +.ui-grid-cell input.ng-invalid { + border: 1px solid #fc8f8f; +} +.ui-grid-cell input.ng-valid { + border: 1px solid #d4d4d4; +} + +.ui-grid-viewport .ui-grid-empty-base-layer-container { + position: absolute; + overflow: hidden; + pointer-events: none; + z-index: -1; +} + +.expandableRow .ui-grid-row:nth-child(odd) .ui-grid-cell { + background-color: #fdfdfd; +} +.expandableRow .ui-grid-row:nth-child(even) .ui-grid-cell { + background-color: #f3f3f3; +} +.ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell { + pointer-events: none; +} +.ui-grid-expandable-buttons-cell i { + pointer-events: all; +} +.scrollFiller { + float: left; + border: 1px solid #d4d4d4; +} + + +.ui-grid-tree-header-row { + font-weight: bold !important; +} + + +.movingColumn { + position: absolute; + top: 0; + border: 1px solid #d4d4d4; + box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.2); +} +.movingColumn .ui-grid-icon-angle-down { + display: none; +} + +/* This file contains variable declarations (do not remove this line) */ +/*-- VARIABLES (DO NOT REMOVE THESE COMMENTS) --*/ +/** +* @section Grid styles +*/ +/** +* @section Header styles +*/ +/** @description Colors for header gradient */ +/** +* @section Grid body styles +*/ +/** @description Colors used for row alternation */ +/** +* @section Grid Menu colors +*/ +/** +* @section Sort arrow colors +*/ +/** +* @section Scrollbar styles +*/ +/** +* @section font library path +*/ +/*-- END VARIABLES (DO NOT REMOVE THESE COMMENTS) --*/ +/*--------------------------------------------------- + LESS Elements 0.9 + --------------------------------------------------- + A set of useful LESS mixins + More info at: http://lesselements.com + ---------------------------------------------------*/ +.ui-grid-pager-panel { + display: flex; + justify-content: space-between; + align-items: center; + position: absolute; + left: 0; + bottom: 0; + width: 100%; + padding-top: 3px; + padding-bottom: 3px; + box-sizing: content-box; +} +.ui-grid-pager-container { + float: left; +} +.ui-grid-pager-control { + padding: 5px 0; + display: flex; + flex-flow: row nowrap; + align-items: center; + margin-right: 10px; + margin-left: 10px; + min-width: 135px; + float: left; +} +.ui-grid-pager-control button, +.ui-grid-pager-control span, +.ui-grid-pager-control input { + margin-right: 4px; +} +.ui-grid-pager-control button { + height: 25px; + min-width: 26px; + display: inline-block; + margin-bottom: 0; + font-weight: normal; + text-align: center; + vertical-align: middle; + touch-action: manipulation; + cursor: pointer; + background: #f3f3f3; + border: 1px solid #ccc; + white-space: nowrap; + padding: 6px 12px; + font-size: 14px; + line-height: 1.42857143; + border-radius: 4px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + color: #eee; +} +.ui-grid-pager-control button:hover { + border-color: #adadad; + text-decoration: none; +} +.ui-grid-pager-control button:focus { + border-color: #8c8c8c; + text-decoration: none; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; +} +.ui-grid-pager-control button:active { + border-color: #adadad; + outline: 0; + -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); + box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); +} +.ui-grid-pager-control button:active:focus { + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; +} +.ui-grid-pager-control button:active:hover, +.ui-grid-pager-control button:active:focus { + background-color: #c8c8c8; + border-color: #8c8c8c; +} +.ui-grid-pager-control button:hover, +.ui-grid-pager-control button:focus, +.ui-grid-pager-control button:active { + color: #eee; + background: #dadada; +} +.ui-grid-pager-control button[disabled] { + cursor: not-allowed; + opacity: 0.65; + filter: alpha(opacity=65); + -webkit-box-shadow: none; + box-shadow: none; +} +.ui-grid-pager-control button[disabled]:hover, +.ui-grid-pager-control button[disabled]:focus { + background-color: #f3f3f3; + border-color: #ccc; +} +.ui-grid-pager-control input { + display: inline; + height: 26px; + width: 50px; + vertical-align: top; + color: #555555; + background: #fff; + border: 1px solid #ccc; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + -o-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + padding: 5px 10px; + font-size: 12px; + line-height: 1.5; + border-radius: 3px; +} +.ui-grid-pager-control input:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-pager-control input[disabled], +.ui-grid-pager-control input[readonly], +.ui-grid-pager-control input::-moz-placeholder { + opacity: 1; +} +.ui-grid-pager-control input::-moz-placeholder, +.ui-grid-pager-control input:-ms-input-placeholder, +.ui-grid-pager-control input::-webkit-input-placeholder { + color: #999; +} +.ui-grid-pager-control input::-ms-expand { + border: 0; + background-color: transparent; +} +.ui-grid-pager-control input[disabled], +.ui-grid-pager-control input[readonly] { + background-color: #eeeeee; +} +.ui-grid-pager-control input[disabled] { + cursor: not-allowed; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number { + vertical-align: bottom; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number > * { + vertical-align: bottom; +} +.ui-grid-pager-control .ui-grid-pager-max-pages-number abbr { + border-bottom: none; + text-decoration: none; +} +.ui-grid-pager-control .first-bar { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-left: -3px; +} +.ui-grid-pager-control .first-bar-rtl { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-right: -7px; +} +.ui-grid-pager-control .first-triangle { + width: 0; + height: 0; + border-style: solid; + border-width: 5px 8.7px 5px 0; + border-color: transparent #4d4d4d transparent transparent; + margin-left: 2px; +} +.ui-grid-pager-control .next-triangle { + margin-left: 1px; +} +.ui-grid-pager-control .prev-triangle { + margin-left: 0; +} +.ui-grid-pager-control .last-triangle { + width: 0; + height: 0; + border-style: solid; + border-width: 5px 0 5px 8.7px; + border-color: transparent transparent transparent #4d4d4d; + margin-left: -1px; +} +.ui-grid-pager-control .last-bar { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-left: 1px; +} +.ui-grid-pager-control .last-bar-rtl { + width: 10px; + border-left: 2px solid #4d4d4d; + margin-top: -6px; + height: 12px; + margin-right: -11px; +} +.ui-grid-pager-row-count-picker { + float: left; + padding: 5px 10px; +} +.ui-grid-pager-row-count-picker select { + color: #555555; + background: #fff; + border: 1px solid #ccc; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + -o-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s; + padding: 5px 10px; + font-size: 12px; + line-height: 1.5; + border-radius: 3px; + height: 25px; + width: 67px; + display: inline; + vertical-align: middle; +} +.ui-grid-pager-row-count-picker select:focus { + border-color: #66afe9; + outline: 0; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} +.ui-grid-pager-row-count-picker select[disabled], +.ui-grid-pager-row-count-picker select[readonly], +.ui-grid-pager-row-count-picker select::-moz-placeholder { + opacity: 1; +} +.ui-grid-pager-row-count-picker select::-moz-placeholder, +.ui-grid-pager-row-count-picker select:-ms-input-placeholder, +.ui-grid-pager-row-count-picker select::-webkit-input-placeholder { + color: #999; +} +.ui-grid-pager-row-count-picker select::-ms-expand { + border: 0; + background-color: transparent; +} +.ui-grid-pager-row-count-picker select[disabled], +.ui-grid-pager-row-count-picker select[readonly] { + background-color: #eeeeee; +} +.ui-grid-pager-row-count-picker select[disabled] { + cursor: not-allowed; +} +.ui-grid-pager-row-count-picker .ui-grid-pager-row-count-label { + margin-top: 3px; +} +.ui-grid-pager-count-container { + float: right; + margin-top: 4px; + min-width: 50px; +} +.ui-grid-pager-count-container .ui-grid-pager-count { + margin-right: 10px; + margin-left: 10px; + float: right; +} +.ui-grid-pager-count-container .ui-grid-pager-count abbr { + border-bottom: none; + text-decoration: none; +} + +.ui-grid-pinned-container { + position: absolute; + display: inline; + top: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left { + float: left; + left: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right { + float: right; + right: 0; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child { + box-sizing: border-box; + border-right: 1px solid; + border-width: 1px; + border-right-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:last-child { + box-sizing: border-box; + border-right: 1px solid; + border-width: 1px; + border-right-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar, +.ui-grid-pinned-container .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child .ui-grid-vertical-bar { + right: -1px; + width: 1px; + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:first-child { + box-sizing: border-box; + border-left: 1px solid; + border-width: 1px; + border-left-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:first-child { + box-sizing: border-box; + border-left: 1px solid; + border-width: 1px; + border-left-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar, +.ui-grid-pinned-container .ui-grid-cell:not(:first-child) .ui-grid-vertical-bar { + width: 1px; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar { + background-color: #d4d4d4; +} +.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar { + background-color: #aeaeae; +} +.ui-grid-pinned-container.ui-grid-pinned-container-first .ui-grid-header-cell:first-child .ui-grid-vertical-bar { + left: -1px; + width: 1px; + background-color: #aeaeae; +} + +.ui-grid-column-resizer { + top: 0; + bottom: 0; + width: 5px; + position: absolute; + cursor: col-resize; +} +.ui-grid-column-resizer.left { + left: 0; +} +.ui-grid-column-resizer.right { + right: 0; +} +.ui-grid-header-cell:last-child .ui-grid-column-resizer.right { + border-right: 1px solid #d4d4d4; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.right { + border-right: 0; +} +.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.left { + border-left: 1px solid #d4d4d4; +} +.ui-grid.column-resizing { + cursor: col-resize; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} +.ui-grid.column-resizing .ui-grid-resize-overlay { + position: absolute; + top: 0; + height: 100%; + width: 1px; + background-color: #aeaeae; +} + +.ui-grid-row-saving .ui-grid-cell { + color: #848484 !important; +} +.ui-grid-row-dirty .ui-grid-cell { + color: #610B38; +} +.ui-grid-row-error .ui-grid-cell { + color: #FF0000 !important; +} + +.ui-grid-row.ui-grid-row-selected > [ui-grid-row] > .ui-grid-cell { + background-color: #C9DDE1; +} +.ui-grid-disable-selection { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + cursor: default; +} +.ui-grid-selection-row-header-buttons { + display: flex; + align-items: center; + height: 100%; + cursor: pointer; +} +.ui-grid-selection-row-header-buttons::before { + opacity: 0.1; +} +.ui-grid-selection-row-header-buttons.ui-grid-row-selected::before, +.ui-grid-selection-row-header-buttons.ui-grid-all-selected::before { + opacity: 1; +} + +.ui-grid-tree-row-header-buttons.ui-grid-tree-header { + cursor: pointer; + opacity: 1; +} + +.ui-grid-tree-header-row { + font-weight: bold !important; +} +.ui-grid-tree-header-row .ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell { + pointer-events: all; +} + +.ui-grid-cell-contents.invalid { + border: 1px solid #fc8f8f; +} diff --git a/src/ui-grid.edit.js b/src/ui-grid.edit.js new file mode 100644 index 0000000000..ed7c1c394b --- /dev/null +++ b/src/ui-grid.edit.js @@ -0,0 +1,1324 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.edit + * @description + * + * # ui.grid.edit + * + * + * + * This module provides cell editing capability to ui.grid. The goal was to emulate keying data in a spreadsheet via + * a keyboard. + *
    + *
    + * To really get the full spreadsheet-like data entry, the ui.grid.cellNav module should be used. This will allow the + * user to key data and then tab, arrow, or enter to the cells beside or below. + * + *
    + */ + + var module = angular.module('ui.grid.edit', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.edit.constant:uiGridEditConstants + * + * @description constants available in edit module + */ + module.constant('uiGridEditConstants', { + EDITABLE_CELL_TEMPLATE: /EDITABLE_CELL_TEMPLATE/g, + // must be lowercase because template bulder converts to lower + EDITABLE_CELL_DIRECTIVE: /editable_cell_directive/g, + events: { + BEGIN_CELL_EDIT: 'uiGridEventBeginCellEdit', + END_CELL_EDIT: 'uiGridEventEndCellEdit', + CANCEL_CELL_EDIT: 'uiGridEventCancelCellEdit' + } + }); + + /** + * @ngdoc service + * @name ui.grid.edit.service:uiGridEditService + * + * @description Services for editing features + */ + module.service('uiGridEditService', ['$q', 'uiGridConstants', 'gridUtil', + function ($q, uiGridConstants, gridUtil) { + + var service = { + + initializeGrid: function (grid) { + + service.defaultGridOptions(grid.options); + + grid.registerColumnBuilder(service.editColumnBuilder); + grid.edit = {}; + + /** + * @ngdoc object + * @name ui.grid.edit.api:PublicApi + * + * @description Public Api for edit feature + */ + var publicApi = { + events: { + edit: { + /** + * @ngdoc event + * @name afterCellEdit + * @eventOf ui.grid.edit.api:PublicApi + * @description raised when cell editing is complete + *
    +                 *      gridApi.edit.on.afterCellEdit(scope,function(rowEntity, colDef) {})
    +                 * 
    + * @param {object} rowEntity the options.data element that was edited + * @param {object} colDef the column that was edited + * @param {object} newValue new value + * @param {object} oldValue old value + */ + afterCellEdit: function (rowEntity, colDef, newValue, oldValue) { + }, + /** + * @ngdoc event + * @name beginCellEdit + * @eventOf ui.grid.edit.api:PublicApi + * @description raised when cell editing starts on a cell + *
    +                 *      gridApi.edit.on.beginCellEdit(scope,function(rowEntity, colDef) {})
    +                 * 
    + * @param {object} rowEntity the options.data element that was edited + * @param {object} colDef the column that was edited + * @param {object} triggerEvent the event that triggered the edit. Useful to prevent losing keystrokes on some + * complex editors + */ + beginCellEdit: function (rowEntity, colDef, triggerEvent) { + }, + /** + * @ngdoc event + * @name cancelCellEdit + * @eventOf ui.grid.edit.api:PublicApi + * @description raised when cell editing is cancelled on a cell + *
    +                 *      gridApi.edit.on.cancelCellEdit(scope,function(rowEntity, colDef) {})
    +                 * 
    + * @param {object} rowEntity the options.data element that was edited + * @param {object} colDef the column that was edited + */ + cancelCellEdit: function (rowEntity, colDef) { + } + } + }, + methods: { + edit: { } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + // grid.api.registerMethodsFromObject(publicApi.methods); + }, + + defaultGridOptions: function (gridOptions) { + + /** + * @ngdoc object + * @name ui.grid.edit.api:GridOptions + * + * @description Options for configuring the edit feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enableCellEdit + * @propertyOf ui.grid.edit.api:GridOptions + * @description If defined, sets the default value for the editable flag on each individual colDefs + * if their individual enableCellEdit configuration is not defined. Defaults to undefined. + */ + + /** + * @ngdoc object + * @name cellEditableCondition + * @propertyOf ui.grid.edit.api:GridOptions + * @description If specified, either a value or function to be used by all columns before editing. + * If false, then editing of cell is not allowed. + * @example + *
    +           *  function($scope, triggerEvent) {
    +           *    //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
    +           *    return true;
    +           *  }
    +           *  
    + */ + gridOptions.cellEditableCondition = gridOptions.cellEditableCondition === undefined ? true : gridOptions.cellEditableCondition; + + /** + * @ngdoc object + * @name editableCellTemplate + * @propertyOf ui.grid.edit.api:GridOptions + * @description If specified, cellTemplate to use as the editor for all columns. + *
    defaults to 'ui-grid/cellTextEditor' + */ + + /** + * @ngdoc object + * @name enableCellEditOnFocus + * @propertyOf ui.grid.edit.api:GridOptions + * @description If true, then editor is invoked as soon as cell receives focus. Default false. + *
    _requires cellNav feature and the edit feature to be enabled_ + */ + // enableCellEditOnFocus can only be used if cellnav module is used + gridOptions.enableCellEditOnFocus = gridOptions.enableCellEditOnFocus === undefined ? false : gridOptions.enableCellEditOnFocus; + }, + + /** + * @ngdoc service + * @name editColumnBuilder + * @methodOf ui.grid.edit.service:uiGridEditService + * @description columnBuilder function that adds edit properties to grid column + * @returns {promise} promise that will load any needed templates when resolved + */ + editColumnBuilder: function (colDef, col, gridOptions) { + + var promises = []; + + /** + * @ngdoc object + * @name ui.grid.edit.api:ColumnDef + * + * @description Column Definition for edit feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name enableCellEdit + * @propertyOf ui.grid.edit.api:ColumnDef + * @description enable editing on column + */ + colDef.enableCellEdit = colDef.enableCellEdit === undefined ? (gridOptions.enableCellEdit === undefined ? + (colDef.type !== 'object') : gridOptions.enableCellEdit) : colDef.enableCellEdit; + + /** + * @ngdoc object + * @name cellEditableCondition + * @propertyOf ui.grid.edit.api:ColumnDef + * @description If specified, either a value or function evaluated before editing cell. If falsy, then editing of cell is not allowed. + * @example + *
    +           *  function($scope, triggerEvent) {
    +           *    //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
    +           *    return true;
    +           *  }
    +           *  
    + */ + colDef.cellEditableCondition = colDef.cellEditableCondition === undefined ? gridOptions.cellEditableCondition : colDef.cellEditableCondition; + + /** + * @ngdoc object + * @name editableCellTemplate + * @propertyOf ui.grid.edit.api:ColumnDef + * @description cell template to be used when editing this column. Can be Url or text template + *
    Defaults to gridOptions.editableCellTemplate + */ + if (colDef.enableCellEdit) { + colDef.editableCellTemplate = colDef.editableCellTemplate || gridOptions.editableCellTemplate || 'ui-grid/cellEditor'; + + promises.push(gridUtil.getTemplate(colDef.editableCellTemplate) + .then( + function (template) { + col.editableCellTemplate = template; + }, + function (res) { + // Todo handle response error here? + throw new Error("Couldn't fetch/use colDef.editableCellTemplate '" + colDef.editableCellTemplate + "'"); + })); + } + + /** + * @ngdoc object + * @name enableCellEditOnFocus + * @propertyOf ui.grid.edit.api:ColumnDef + * @requires ui.grid.cellNav + * @description If true, then editor is invoked as soon as cell receives focus. Default false. + *
    _requires both the cellNav feature and the edit feature to be enabled_ + */ + // enableCellEditOnFocus can only be used if cellnav module is used + colDef.enableCellEditOnFocus = colDef.enableCellEditOnFocus === undefined ? gridOptions.enableCellEditOnFocus : colDef.enableCellEditOnFocus; + + + /** + * @ngdoc string + * @name editModelField + * @propertyOf ui.grid.edit.api:ColumnDef + * @description a bindable string value that is used when binding to edit controls instead of colDef.field + *
    example: You have a complex property on and object like state:{abbrev: 'MS',name: 'Mississippi'}. The + * grid should display state.name in the cell and sort/filter based on the state.name property but the editor + * requires the full state object. + *
    colDef.field = 'state.name' + *
    colDef.editModelField = 'state' + */ + // colDef.editModelField + + return $q.all(promises); + }, + + /** + * @ngdoc service + * @name isStartEditKey + * @methodOf ui.grid.edit.service:uiGridEditService + * @description Determines if a keypress should start editing. Decorate this service to override with your + * own key events. See service decorator in angular docs. + * @param {Event} evt keydown event + * @returns {boolean} true if an edit should start + */ + isStartEditKey: function (evt) { + return !(evt.metaKey || + evt.keyCode === uiGridConstants.keymap.ESC || + evt.keyCode === uiGridConstants.keymap.SHIFT || + evt.keyCode === uiGridConstants.keymap.CTRL || + evt.keyCode === uiGridConstants.keymap.ALT || + evt.keyCode === uiGridConstants.keymap.WIN || + evt.keyCode === uiGridConstants.keymap.CAPSLOCK || + + evt.keyCode === uiGridConstants.keymap.LEFT || + (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey) || + + evt.keyCode === uiGridConstants.keymap.RIGHT || + evt.keyCode === uiGridConstants.keymap.TAB || + + evt.keyCode === uiGridConstants.keymap.UP || + (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) || + + evt.keyCode === uiGridConstants.keymap.DOWN || + evt.keyCode === uiGridConstants.keymap.ENTER); + } + }; + + return service; + + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridEdit + * @element div + * @restrict A + * + * @description Adds editing features to the ui-grid directive. + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.edit']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name', enableCellEdit: true}, + {name: 'title', enableCellEdit: true} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridEdit', ['gridUtil', 'uiGridEditService', function (gridUtil, uiGridEditService) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridEditService.initializeGrid(uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridRenderContainer + * @element div + * @restrict A + * + * @description Adds keydown listeners to renderContainer element so we can capture when to begin edits + * + */ + module.directive('uiGridViewport', [ 'uiGridEditConstants', + function ( uiGridEditConstants) { + return { + replace: true, + priority: -99998, // run before cellNav + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: false, + compile: function () { + return { + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + + // Skip attaching if edit and cellNav is not enabled + if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = controllers[1].containerId; + // no need to process for other containers + if (containerId !== 'body') { + return; + } + + // refocus on the grid + $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () { + uiGridCtrl.focus(); + }); + $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () { + uiGridCtrl.focus(); + }); + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridCell + * @element div + * @restrict A + * + * @description Stacks on top of ui.grid.uiGridCell to provide in-line editing capabilities to the cell + * Editing Actions. + * + * Binds edit start events to the uiGridCell element. When the events fire, the gridCell element is appended + * with the columnDef.editableCellTemplate element ('cellEditor.html' by default). + * + * The editableCellTemplate should respond to uiGridEditConstants.events.BEGIN\_CELL\_EDIT angular event + * and do the initial steps needed to edit the cell (setfocus on input element, etc). + * + * When the editableCellTemplate recognizes that the editing is ended (blur event, Enter key, etc.) + * it should emit the uiGridEditConstants.events.END\_CELL\_EDIT event. + * + * If editableCellTemplate recognizes that the editing has been cancelled (esc key) + * it should emit the uiGridEditConstants.events.CANCEL\_CELL\_EDIT event. The original value + * will be set back on the model by the uiGridCell directive. + * + * Events that invoke editing: + * - dblclick + * - F2 keydown (when using cell selection) + * + * Events that end editing: + * - Dependent on the specific editableCellTemplate + * - Standards should be blur and enter keydown + * + * Events that cancel editing: + * - Dependent on the specific editableCellTemplate + * - Standards should be Esc keydown + * + * Grid Events that end editing: + * - uiGridConstants.events.GRID_SCROLL + * + */ + + /** + * @ngdoc object + * @name ui.grid.edit.api:GridRow + * + * @description GridRow options for edit feature, these are available to be + * set internally only, by other features + */ + + /** + * @ngdoc object + * @name enableCellEdit + * @propertyOf ui.grid.edit.api:GridRow + * @description enable editing on row, grouping for example might disable editing on group header rows + */ + + module.directive('uiGridCell', + ['$compile', '$injector', '$timeout', 'uiGridConstants', 'uiGridEditConstants', 'gridUtil', '$parse', 'uiGridEditService', '$rootScope', '$q', + function ($compile, $injector, $timeout, uiGridConstants, uiGridEditConstants, gridUtil, $parse, uiGridEditService, $rootScope, $q) { + var touchstartTimeout = 500; + if ($injector.has('uiGridCellNavService')) { + var uiGridCellNavService = $injector.get('uiGridCellNavService'); + } + + return { + priority: -100, // run after default uiGridCell directive + restrict: 'A', + scope: false, + require: '?^uiGrid', + link: function ($scope, $elm, $attrs, uiGridCtrl) { + var html, + origCellValue, + cellModel, + cancelTouchstartTimeout, + inEdit = false; + + var editCellScope; + + if (!$scope.col.colDef.enableCellEdit) { + return; + } + + var cellNavNavigateDereg = function() {}; + var viewPortKeyDownDereg = function() {}; + + + var setEditable = function() { + if ($scope.col.colDef.enableCellEdit && $scope.row.enableCellEdit !== false) { + if (!$scope.beginEditEventsWired) { // prevent multiple attachments + registerBeginEditEvents(); + } + } else { + if ($scope.beginEditEventsWired) { + cancelBeginEditEvents(); + } + } + }; + + setEditable(); + + var rowWatchDereg = $scope.$watch('row', function (n, o) { + if (n !== o) { + setEditable(); + } + }); + + + $scope.$on('$destroy', function destroyEvents() { + rowWatchDereg(); + // unbind all jquery events in order to avoid memory leaks + $elm.off(); + }); + + function registerBeginEditEvents() { + $elm.on('dblclick', beginEdit); + + // Add touchstart handling. If the users starts a touch and it doesn't end after X milliseconds, then start the edit + $elm.on('touchstart', touchStart); + + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { + + viewPortKeyDownDereg = uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) { + if (rowCol === null) { + return; + } + + if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) { + // important to do this before scrollToIfNecessary + beginEditKeyDown(evt); + } + }); + + cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol, evt) { + if ($scope.col.colDef.enableCellEditOnFocus) { + // Don't begin edit if the cell hasn't changed + if (newRowCol.row === $scope.row && newRowCol.col === $scope.col && + (evt === null || (evt && (evt.type === 'click' || evt.type === 'keydown')))) { + $timeout(function() { + beginEdit(evt); + }); + } + } + }); + } + + $scope.beginEditEventsWired = true; + } + + function touchStart(event) { + // jQuery masks events + if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { + event = event.originalEvent; + } + + // Bind touchend handler + $elm.on('touchend', touchEnd); + + // Start a timeout + cancelTouchstartTimeout = $timeout(function() { }, touchstartTimeout); + + // Timeout's done! Start the edit + cancelTouchstartTimeout.then(function () { + // Use setTimeout to start the edit because beginEdit expects to be outside of $digest + setTimeout(beginEdit, 0); + + // Undbind the touchend handler, we don't need it anymore + $elm.off('touchend', touchEnd); + }).catch(angular.noop); + } + + // Cancel any touchstart timeout + function touchEnd() { + $timeout.cancel(cancelTouchstartTimeout); + $elm.off('touchend', touchEnd); + } + + function cancelBeginEditEvents() { + $elm.off('dblclick', beginEdit); + $elm.off('keydown', beginEditKeyDown); + $elm.off('touchstart', touchStart); + cellNavNavigateDereg(); + viewPortKeyDownDereg(); + $scope.beginEditEventsWired = false; + } + + function beginEditKeyDown(evt) { + if (uiGridEditService.isStartEditKey(evt)) { + beginEdit(evt); + } + } + + function shouldEdit(col, row, triggerEvent) { + return !row.isSaving && + ( angular.isFunction(col.colDef.cellEditableCondition) ? + col.colDef.cellEditableCondition($scope, triggerEvent) : + col.colDef.cellEditableCondition ); + } + + + function beginEdit(triggerEvent) { + // we need to scroll the cell into focus before invoking the editor + $scope.grid.api.core.scrollToIfNecessary($scope.row, $scope.col) + .then(function () { + beginEditAfterScroll(triggerEvent); + }); + } + + /** + * @ngdoc property + * @name editDropdownOptionsArray + * @propertyOf ui.grid.edit.api:ColumnDef + * @description an array of values in the format + * [ {id: xxx, value: xxx} ], which is populated + * into the edit dropdown + * + */ + /** + * @ngdoc property + * @name editDropdownIdLabel + * @propertyOf ui.grid.edit.api:ColumnDef + * @description the label for the "id" field + * in the editDropdownOptionsArray. Defaults + * to 'id' + * @example + *
    +             *    $scope.gridOptions = {
    +             *      columnDefs: [
    +             *        {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
    +             *          editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
    +             *          editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
    +             *      ],
    +             *  
    + * + */ + /** + * @ngdoc property + * @name editDropdownRowEntityOptionsArrayPath + * @propertyOf ui.grid.edit.api:ColumnDef + * @description a path to a property on row.entity containing an + * array of values in the format + * [ {id: xxx, value: xxx} ], which will be used to populate + * the edit dropdown. This can be used when the dropdown values are dependent on + * the backing row entity. + * If this property is set then editDropdownOptionsArray will be ignored. + * @example + *
    +             *    $scope.gridOptions = {
    +             *      columnDefs: [
    +             *        {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
    +             *          editDropdownRowEntityOptionsArrayPath: 'foo.bars[0].baz',
    +             *          editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
    +             *      ],
    +             *  
    + * + */ + /** + * @ngdoc service + * @name editDropdownOptionsFunction + * @methodOf ui.grid.edit.api:ColumnDef + * @description a function returning an array of values in the format + * [ {id: xxx, value: xxx} ], which will be used to populate + * the edit dropdown. This can be used when the dropdown values are dependent on + * the backing row entity with some kind of algorithm. + * If this property is set then both editDropdownOptionsArray and + * editDropdownRowEntityOptionsArrayPath will be ignored. + * @param {object} rowEntity the options.data element that the returned array refers to + * @param {object} colDef the column that implements this dropdown + * @returns {object} an array of values in the format + * [ {id: xxx, value: xxx} ] used to populate the edit dropdown + * @example + *
    +             *    $scope.gridOptions = {
    +             *      columnDefs: [
    +             *        {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
    +             *          editDropdownOptionsFunction: function(rowEntity, colDef) {
    +             *            if (rowEntity.foo === 'bar') {
    +             *              return [{id: 'bar1', value: 'BAR 1'},
    +             *                      {id: 'bar2', value: 'BAR 2'},
    +             *                      {id: 'bar3', value: 'BAR 3'}];
    +             *            } else {
    +             *              return [{id: 'foo1', value: 'FOO 1'},
    +             *                      {id: 'foo2', value: 'FOO 2'}];
    +             *            }
    +             *          },
    +             *          editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
    +             *      ],
    +             *  
    + * + */ + /** + * @ngdoc property + * @name editDropdownValueLabel + * @propertyOf ui.grid.edit.api:ColumnDef + * @description the label for the "value" field + * in the editDropdownOptionsArray. Defaults + * to 'value' + * @example + *
    +             *    $scope.gridOptions = {
    +             *      columnDefs: [
    +             *        {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
    +             *          editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
    +             *          editDropdownIdLabel: 'code', editDropdownValueLabel: 'status' }
    +             *      ],
    +             *  
    + * + */ + /** + * @ngdoc property + * @name editDropdownFilter + * @propertyOf ui.grid.edit.api:ColumnDef + * @description A filter that you would like to apply to the values in the options list + * of the dropdown. For example if you were using angular-translate you might set this + * to `'translate'` + * @example + *
    +             *    $scope.gridOptions = {
    +             *      columnDefs: [
    +             *        {name: 'status', editableCellTemplate: 'ui-grid/dropdownEditor',
    +             *          editDropdownOptionsArray: [{code: 1, status: 'active'}, {code: 2, status: 'inactive'}],
    +             *          editDropdownIdLabel: 'code', editDropdownValueLabel: 'status', editDropdownFilter: 'translate' }
    +             *      ],
    +             *  
    + * + */ + function beginEditAfterScroll(triggerEvent) { + // If we are already editing, then just skip this so we don't try editing twice... + if (inEdit) { + return; + } + + if (!shouldEdit($scope.col, $scope.row, triggerEvent)) { + return; + } + + var modelField = $scope.row.getQualifiedColField($scope.col); + if ($scope.col.colDef.editModelField) { + modelField = gridUtil.preEval('row.entity.' + $scope.col.colDef.editModelField); + } + + cellModel = $parse(modelField); + + // get original value from the cell + origCellValue = cellModel($scope); + + html = $scope.col.editableCellTemplate; + html = html.replace(uiGridConstants.MODEL_COL_FIELD, modelField); + html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + var optionFilter = $scope.col.colDef.editDropdownFilter ? '|' + $scope.col.colDef.editDropdownFilter : ''; + html = html.replace(uiGridConstants.CUSTOM_FILTERS, optionFilter); + + var inputType = 'text'; + switch ($scope.col.colDef.type) { + case 'boolean': + inputType = 'checkbox'; + break; + case 'number': + inputType = 'number'; + break; + case 'date': + inputType = 'date'; + break; + } + html = html.replace('INPUT_TYPE', inputType); + + // In order to fill dropdown options we use: + // - A function/promise or + // - An array inside of row entity if no function exists or + // - A single array for the whole column if none of the previous exists. + var editDropdownOptionsFunction = $scope.col.colDef.editDropdownOptionsFunction; + if (editDropdownOptionsFunction) { + $q.when(editDropdownOptionsFunction($scope.row.entity, $scope.col.colDef)) + .then(function(result) { + $scope.editDropdownOptionsArray = result; + }); + } else { + var editDropdownRowEntityOptionsArrayPath = $scope.col.colDef.editDropdownRowEntityOptionsArrayPath; + if (editDropdownRowEntityOptionsArrayPath) { + $scope.editDropdownOptionsArray = resolveObjectFromPath($scope.row.entity, editDropdownRowEntityOptionsArrayPath); + } + else { + $scope.editDropdownOptionsArray = $scope.col.colDef.editDropdownOptionsArray; + } + } + $scope.editDropdownIdLabel = $scope.col.colDef.editDropdownIdLabel ? $scope.col.colDef.editDropdownIdLabel : 'id'; + $scope.editDropdownValueLabel = $scope.col.colDef.editDropdownValueLabel ? $scope.col.colDef.editDropdownValueLabel : 'value'; + + var createEditor = function() { + inEdit = true; + cancelBeginEditEvents(); + var cellElement = angular.element(html); + $elm.append(cellElement); + editCellScope = $scope.$new(); + $compile(cellElement)(editCellScope); + var gridCellContentsEl = angular.element($elm.children()[0]); + gridCellContentsEl.addClass('ui-grid-cell-contents-hidden'); + }; + if (!$rootScope.$$phase) { + $scope.$apply(createEditor); + } else { + createEditor(); + } + + // stop editing when grid is scrolled + var deregOnGridScroll = $scope.col.grid.api.core.on.scrollBegin($scope, function () { + if ($scope.grid.disableScrolling) { + return; + } + endEdit(); + $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue); + deregOnGridScroll(); + deregOnEndCellEdit(); + deregOnCancelCellEdit(); + }); + + // end editing + var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () { + endEdit(); + $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue); + deregOnEndCellEdit(); + deregOnGridScroll(); + deregOnCancelCellEdit(); + }); + + // cancel editing + var deregOnCancelCellEdit = $scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () { + cancelEdit(); + deregOnCancelCellEdit(); + deregOnGridScroll(); + deregOnEndCellEdit(); + }); + + $scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent); + $timeout(function () { + // execute in a timeout to give any complex editor templates a cycle to completely render + $scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent); + }); + } + + function endEdit() { + $scope.grid.disableScrolling = false; + if (!inEdit) { + return; + } + + // sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus + // back to grid here. The focus call needs to be before the $destroy and removal of the control, + // otherwise ng-model-options of UpdateOn: 'blur' will not work. + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { + uiGridCtrl.focus(); + } + + var gridCellContentsEl = angular.element($elm.children()[0]); + // remove edit element + editCellScope.$destroy(); + var children = $elm.children(); + for (var i = 1; i < children.length; i++) { + angular.element(children[i]).remove(); + } + gridCellContentsEl.removeClass('ui-grid-cell-contents-hidden'); + inEdit = false; + registerBeginEditEvents(); + $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.EDIT ); + } + + function cancelEdit() { + $scope.grid.disableScrolling = false; + if (!inEdit) { + return; + } + cellModel.assign($scope, origCellValue); + $scope.$apply(); + + $scope.grid.api.edit.raise.cancelCellEdit($scope.row.entity, $scope.col.colDef); + endEdit(); + } + + // resolves a string path against the given object + // shamelessly borrowed from + // http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key + function resolveObjectFromPath(object, path) { + path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties + path = path.replace(/^\./, ''); // strip a leading dot + var a = path.split('.'); + while (a.length) { + var n = a.shift(); + if (n in object) { + object = object[n]; + } else { + return; + } + } + return object; + } + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridEditor + * @element div + * @restrict A + * + * @description input editor directive for editable fields. + * Provides EndEdit and CancelEdit events + * + * Events that end editing: + * blur and enter keydown + * + * Events that cancel editing: + * - Esc keydown + * + */ + module.directive('uiGridEditor', + ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', 'uiGridEditService', + function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout, uiGridEditService) { + return { + scope: true, + require: ['?^uiGrid', '?^uiGridRenderContainer', 'ngModel'], + compile: function () { + return { + pre: function ($scope, $elm, $attrs) { + + }, + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl, renderContainerCtrl, ngModel; + if (controllers[0]) { uiGridCtrl = controllers[0]; } + if (controllers[1]) { renderContainerCtrl = controllers[1]; } + if (controllers[2]) { ngModel = controllers[2]; } + + // set focus at start of edit + $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { + // must be in a timeout since it requires a new digest cycle + $timeout(function () { + $elm[0].focus(); + // only select text if it is not being replaced below in the cellNav viewPortKeyPress + if ($elm[0].select && ($scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav))) { + $elm[0].select(); + } + else { + // some browsers (Chrome) stupidly, imo, support the w3 standard that number, email, ... + // fields should not allow setSelectionRange. We ignore the error for those browsers + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24796 + try { + $elm[0].setSelectionRange($elm[0].value.length, $elm[0].value.length); + } + catch (ex) { + // ignore + } + } + }); + + // set the keystroke that started the edit event + // we must do this because the BeginEdit is done in a different event loop than the intitial + // keydown event + // fire this event for the keypress that is received + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { + var viewPortKeyDownUnregister = uiGridCtrl.grid.api.cellNav.on.viewPortKeyPress($scope, function (evt, rowCol) { + if (uiGridEditService.isStartEditKey(evt)) { + var code = typeof evt.which === 'number' ? evt.which : evt.keyCode; + if (code > 0) { + ngModel.$setViewValue(String.fromCharCode(code), evt); + ngModel.$render(); + } + } + viewPortKeyDownUnregister(); + }); + } + + // macOS will blur the checkbox when clicked in Safari and Firefox, + // to get around this, we disable the blur handler on mousedown, + // and then focus the checkbox and re-enable the blur handler after $timeout + $elm.on('mousedown', function(evt) { + if ($elm[0].type === 'checkbox') { + $elm.off('blur', $scope.stopEdit); + $timeout(function() { + $elm[0].focus(); + $elm.on('blur', $scope.stopEdit); + }); + } + }); + + if ($elm[0]) { + $elm[0].focus(); + } + $elm.on('blur', $scope.stopEdit); + }); + + + $scope.deepEdit = false; + + $scope.stopEdit = function (evt) { + if ($scope.inputForm && !$scope.inputForm.$valid) { + evt.stopPropagation(); + $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT); + } + else { + $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT); + } + $scope.deepEdit = false; + }; + + + $elm.on('click', function (evt) { + if ($elm[0].type !== 'checkbox') { + $scope.deepEdit = true; + $scope.$applyAsync(function () { + $scope.grid.disableScrolling = true; + }); + } + }); + + $elm.on('keydown', function (evt) { + switch (evt.keyCode) { + case uiGridConstants.keymap.ESC: + evt.stopPropagation(); + $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT); + break; + } + + if ($scope.deepEdit && + (evt.keyCode === uiGridConstants.keymap.LEFT || + evt.keyCode === uiGridConstants.keymap.RIGHT || + evt.keyCode === uiGridConstants.keymap.UP || + evt.keyCode === uiGridConstants.keymap.DOWN)) { + evt.stopPropagation(); + } + // Pass the keydown event off to the cellNav service, if it exists + else if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { + evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId; + if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) { + $scope.stopEdit(evt); + } + } + else { + // handle enter and tab for editing not using cellNav + switch (evt.keyCode) { + case uiGridConstants.keymap.ENTER: // Enter (Leave Field) + case uiGridConstants.keymap.TAB: + evt.stopPropagation(); + evt.preventDefault(); + $scope.stopEdit(evt); + break; + } + } + + return true; + }); + + $scope.$on('$destroy', function unbindEvents() { + // unbind all jquery events in order to avoid memory leaks + $elm.off(); + }); + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:input + * @element input + * @restrict E + * + * @description directive to provide binding between input[date] value and ng-model for angular 1.2 + * It is similar to input[date] directive of angular 1.3 + * + * Supported date format for input is 'yyyy-MM-dd' + * The directive will set the $valid property of input element and the enclosing form to false if + * model is invalid date or value of input is entered wrong. + * + */ + module.directive('uiGridEditor', ['$filter', function ($filter) { + function parseDateString(dateString) { + if (typeof(dateString) === 'undefined' || dateString === '') { + return null; + } + var parts = dateString.split('-'); + if (parts.length !== 3) { + return null; + } + var year = parseInt(parts[0], 10); + var month = parseInt(parts[1], 10); + var day = parseInt(parts[2], 10); + + if (month < 1 || year < 1 || day < 1) { + return null; + } + return new Date(year, (month - 1), day); + } + return { + priority: -100, // run after default uiGridEditor directive + require: '?ngModel', + link: function (scope, element, attrs, ngModel) { + if (angular.version.minor === 2 && attrs.type && attrs.type === 'date' && ngModel) { + ngModel.$formatters.push(function (modelValue) { + ngModel.$setValidity(null,(!modelValue || !isNaN(modelValue.getTime()))); + return $filter('date')(modelValue, 'yyyy-MM-dd'); + }); + + ngModel.$parsers.push(function (viewValue) { + if (viewValue && viewValue.length > 0) { + var dateValue = parseDateString(viewValue); + ngModel.$setValidity(null, (dateValue && !isNaN(dateValue.getTime()))); + return dateValue; + } + else { + ngModel.$setValidity(null, true); + return null; + } + }); + } + } + }; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridEditDropdown + * @element div + * @restrict A + * + * @description dropdown editor for editable fields. + * Provides EndEdit and CancelEdit events + * + * Events that end editing: + * blur and enter keydown, and any left/right nav + * + * Events that cancel editing: + * - Esc keydown + * + */ + module.directive('uiGridEditDropdown', + ['uiGridConstants', 'uiGridEditConstants', '$timeout', + function (uiGridConstants, uiGridEditConstants, $timeout) { + return { + require: ['?^uiGrid', '?^uiGridRenderContainer'], + scope: true, + compile: function () { + return { + pre: function ($scope, $elm, $attrs) { + + }, + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var renderContainerCtrl = controllers[1]; + + // set focus at start of edit + $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { + $timeout(function() { + $elm[0].focus(); + }); + + $elm[0].style.width = ($elm[0].parentElement.offsetWidth - 1) + 'px'; + $elm.on('blur', function (evt) { + $scope.stopEdit(evt); + }); + }); + + + $scope.stopEdit = function (evt) { + // no need to validate a dropdown - invalid values shouldn't be + // available in the list + $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT); + }; + + $elm.on('keydown', function (evt) { + switch (evt.keyCode) { + case uiGridConstants.keymap.ESC: + evt.stopPropagation(); + $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT); + break; + } + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { + evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId; + if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) { + $scope.stopEdit(evt); + } + } + else { + // handle enter and tab for editing not using cellNav + switch (evt.keyCode) { + case uiGridConstants.keymap.ENTER: // Enter (Leave Field) + case uiGridConstants.keymap.TAB: + evt.stopPropagation(); + evt.preventDefault(); + $scope.stopEdit(evt); + break; + } + } + return true; + }); + + $scope.$on('$destroy', function unbindEvents() { + // unbind jquery events to prevent memory leaks + $elm.off(); + }); + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.edit.directive:uiGridEditFileChooser + * @element div + * @restrict A + * + * @description input editor directive for editable fields. + * Provides EndEdit and CancelEdit events + * + * Events that end editing: + * blur and enter keydown + * + * Events that cancel editing: + * - Esc keydown + * + */ + module.directive('uiGridEditFileChooser', + ['gridUtil', 'uiGridConstants', 'uiGridEditConstants', + function (gridUtil, uiGridConstants, uiGridEditConstants) { + return { + scope: true, + require: ['?^uiGrid', '?^uiGridRenderContainer'], + compile: function () { + return { + pre: function ($scope, $elm, $attrs) { + + }, + post: function ($scope, $elm) { + function handleFileSelect(event) { + var target = event.srcElement || event.target; + + if (target && target.files && target.files.length > 0) { + /** + * @ngdoc property + * @name editFileChooserCallback + * @propertyOf ui.grid.edit.api:ColumnDef + * @description A function that should be called when any files have been chosen + * by the user. You should use this to process the files appropriately for your + * application. + * + * It passes the gridCol, the gridRow (from which you can get gridRow.entity), + * and the files. The files are in the format as returned from the file chooser, + * an array of files, with each having useful information such as: + * - `files[0].lastModifiedDate` + * - `files[0].name` + * - `files[0].size` (appears to be in bytes) + * - `files[0].type` (MIME type by the looks) + * + * Typically you would do something with these files - most commonly you would + * use the filename or read the file itself in. The example function does both. + * + * @example + *
    +                     *  editFileChooserCallBack: function(gridRow, gridCol, files ) {
    +                     *    // ignore all but the first file, it can only choose one anyway
    +                     *    // set the filename into this column
    +                     *    gridRow.entity.filename = file[0].name;
    +                     *
    +                     *    // read the file and set it into a hidden column, which we may do stuff with later
    +                     *    var setFile = function(fileContent) {
    +                     *      gridRow.entity.file = fileContent.currentTarget.result;
    +                     *    };
    +                     *    var reader = new FileReader();
    +                     *    reader.onload = setFile;
    +                     *    reader.readAsText( files[0] );
    +                     *  }
    +                     *  
    + */ + if ( typeof($scope.col.colDef.editFileChooserCallback) === 'function' ) { + $scope.col.colDef.editFileChooserCallback($scope.row, $scope.col, target.files); + } else { + gridUtil.logError('You need to set colDef.editFileChooserCallback to use the file chooser'); + } + + target.form.reset(); + $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT); + } else { + $scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT); + } + $elm[0].removeEventListener('change', handleFileSelect, false); + } + + $elm[0].addEventListener('change', handleFileSelect, false); + + $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { + $elm[0].focus(); + $elm[0].select(); + + $elm.on('blur', function () { + $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT); + $elm.off(); + }); + }); + } + }; + } + }; + }]); +})(); + +angular.module('ui.grid.edit').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/cellEditor', + "
    " + ); + + + $templateCache.put('ui-grid/dropdownEditor', + "
    " + ); + + + $templateCache.put('ui-grid/fileChooserEditor', + "
    " + ); + +}]); diff --git a/src/ui-grid.edit.min.js b/src/ui-grid.edit.min.js new file mode 100644 index 0000000000..d79212a7c3 --- /dev/null +++ b/src/ui-grid.edit.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.edit",["ui.grid"]);e.constant("uiGridEditConstants",{EDITABLE_CELL_TEMPLATE:/EDITABLE_CELL_TEMPLATE/g,EDITABLE_CELL_DIRECTIVE:/editable_cell_directive/g,events:{BEGIN_CELL_EDIT:"uiGridEventBeginCellEdit",END_CELL_EDIT:"uiGridEventEndCellEdit",CANCEL_CELL_EDIT:"uiGridEventCancelCellEdit"}}),e.service("uiGridEditService",["$q","uiGridConstants","gridUtil",function(o,i,l){var t={initializeGrid:function(e){t.defaultGridOptions(e.options),e.registerColumnBuilder(t.editColumnBuilder),e.edit={};e.api.registerEventsFromObject({edit:{afterCellEdit:function(e,i,t,n){},beginCellEdit:function(e,i,t){},cancelCellEdit:function(e,i){}}})},defaultGridOptions:function(e){e.cellEditableCondition=void 0===e.cellEditableCondition||e.cellEditableCondition,e.enableCellEditOnFocus=void 0!==e.enableCellEditOnFocus&&e.enableCellEditOnFocus},editColumnBuilder:function(i,t,e){var n=[];return i.enableCellEdit=void 0===i.enableCellEdit?void 0===e.enableCellEdit?"object"!==i.type:e.enableCellEdit:i.enableCellEdit,i.cellEditableCondition=void 0===i.cellEditableCondition?e.cellEditableCondition:i.cellEditableCondition,i.enableCellEdit&&(i.editableCellTemplate=i.editableCellTemplate||e.editableCellTemplate||"ui-grid/cellEditor",n.push(l.getTemplate(i.editableCellTemplate).then(function(e){t.editableCellTemplate=e},function(e){throw new Error("Couldn't fetch/use colDef.editableCellTemplate '"+i.editableCellTemplate+"'")}))),i.enableCellEditOnFocus=void 0===i.enableCellEditOnFocus?e.enableCellEditOnFocus:i.enableCellEditOnFocus,o.all(n)},isStartEditKey:function(e){return!(e.metaKey||e.keyCode===i.keymap.ESC||e.keyCode===i.keymap.SHIFT||e.keyCode===i.keymap.CTRL||e.keyCode===i.keymap.ALT||e.keyCode===i.keymap.WIN||e.keyCode===i.keymap.CAPSLOCK||e.keyCode===i.keymap.LEFT||e.keyCode===i.keymap.TAB&&e.shiftKey||e.keyCode===i.keymap.RIGHT||e.keyCode===i.keymap.TAB||e.keyCode===i.keymap.UP||e.keyCode===i.keymap.ENTER&&e.shiftKey||e.keyCode===i.keymap.DOWN||e.keyCode===i.keymap.ENTER)}};return t}]),e.directive("uiGridEdit",["gridUtil","uiGridEditService",function(e,o){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,t,n){o.initializeGrid(n.grid)},post:function(e,i,t,n){}}}}}]),e.directive("uiGridViewport",["uiGridEditConstants",function(l){return{replace:!0,priority:-99998,require:["^uiGrid","^uiGridRenderContainer"],scope:!1,compile:function(){return{post:function(e,i,t,n){var o=n[0];o.grid.api.edit&&o.grid.api.cellNav&&("body"===n[1].containerId&&(e.$on(l.events.CANCEL_CELL_EDIT,function(){o.focus()}),e.$on(l.events.END_CELL_EDIT,function(){o.focus()})))}}}}}]),e.directive("uiGridCell",["$compile","$injector","$timeout","uiGridConstants","uiGridEditConstants","gridUtil","$parse","uiGridEditService","$rootScope","$q",function(b,e,h,T,k,w,_,f,I,G){if(e.has("uiGridCellNavService"))e.get("uiGridCellNavService");return{priority:-100,restrict:"A",scope:!1,require:"?^uiGrid",link:function(E,p,e,n){var C,v,g,i,y,m=!1;if(E.col.colDef.enableCellEdit){var t=function(){},o=function(){},l=function(){E.col.colDef.enableCellEdit&&!1!==E.row.enableCellEdit?E.beginEditEventsWired||d():E.beginEditEventsWired&&D()};l();var r=E.$watch("row",function(e,i){e!==i&&l()});E.$on("$destroy",function(){r(),p.off()})}function d(){p.on("dblclick",s),p.on("touchstart",c),n&&n.grid.api.cellNav&&(o=n.grid.api.cellNav.on.viewPortKeyDown(E,function(e,i){null!==i&&(i.row!==E.row||i.col!==E.col||E.col.colDef.enableCellEditOnFocus||u(e))}),t=n.grid.api.cellNav.on.navigate(E,function(e,i,t){E.col.colDef.enableCellEditOnFocus&&(e.row!==E.row||e.col!==E.col||null!==t&&(!t||"click"!==t.type&&"keydown"!==t.type)||h(function(){s(t)}))})),E.beginEditEventsWired=!0}function c(e){void 0!==e.originalEvent&&void 0!==e.originalEvent&&(e=e.originalEvent),p.on("touchend",a),(i=h(function(){},500)).then(function(){setTimeout(s,0),p.off("touchend",a)}).catch(angular.noop)}function a(){h.cancel(i),p.off("touchend",a)}function D(){p.off("dblclick",s),p.off("keydown",u),p.off("touchstart",c),t(),o(),E.beginEditEventsWired=!1}function u(e){f.isStartEditKey(e)&&s(e)}function s(e){E.grid.api.core.scrollToIfNecessary(E.row,E.col).then(function(){!function(e){if(m)return;if(i=E.col,t=E.row,n=e,t.isSaving||(angular.isFunction(i.colDef.cellEditableCondition)?!i.colDef.cellEditableCondition(E,n):!i.colDef.cellEditableCondition))return;var i,t,n;var o=E.row.getQualifiedColField(E.col);E.col.colDef.editModelField&&(o=w.preEval("row.entity."+E.col.colDef.editModelField));g=_(o),v=g(E),C=(C=(C=E.col.editableCellTemplate).replace(T.MODEL_COL_FIELD,o)).replace(T.COL_FIELD,"grid.getCellValue(row, col)");var l=E.col.colDef.editDropdownFilter?"|"+E.col.colDef.editDropdownFilter:"";C=C.replace(T.CUSTOM_FILTERS,l);var r="text";switch(E.col.colDef.type){case"boolean":r="checkbox";break;case"number":r="number";break;case"date":r="date"}C=C.replace("INPUT_TYPE",r);var d=E.col.colDef.editDropdownOptionsFunction;if(d)G.when(d(E.row.entity,E.col.colDef)).then(function(e){E.editDropdownOptionsArray=e});else{var c=E.col.colDef.editDropdownRowEntityOptionsArrayPath;E.editDropdownOptionsArray=c?function(e,i){var t=(i=(i=i.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");for(;t.length;){var n=t.shift();if(!(n in e))return;e=e[n]}return e}(E.row.entity,c):E.col.colDef.editDropdownOptionsArray}E.editDropdownIdLabel=E.col.colDef.editDropdownIdLabel?E.col.colDef.editDropdownIdLabel:"id",E.editDropdownValueLabel=E.col.colDef.editDropdownValueLabel?E.col.colDef.editDropdownValueLabel:"value";var a=function(){m=!0,D();var e=angular.element(C);p.append(e),y=E.$new(),b(e)(y);var i=angular.element(p.children()[0]);i.addClass("ui-grid-cell-contents-hidden")};I.$$phase?a():E.$apply(a);var u=E.col.grid.api.core.on.scrollBegin(E,function(){E.grid.disableScrolling||(L(),E.grid.api.edit.raise.afterCellEdit(E.row.entity,E.col.colDef,g(E),v),u(),s(),f())}),s=E.$on(k.events.END_CELL_EDIT,function(){L(),E.grid.api.edit.raise.afterCellEdit(E.row.entity,E.col.colDef,g(E),v),s(),u(),f()}),f=E.$on(k.events.CANCEL_CELL_EDIT,function(){!function(){if(E.grid.disableScrolling=!1,!m)return;g.assign(E,v),E.$apply(),E.grid.api.edit.raise.cancelCellEdit(E.row.entity,E.col.colDef),L()}(),f(),u(),s()});E.$broadcast(k.events.BEGIN_CELL_EDIT,e),h(function(){E.grid.api.edit.raise.beginCellEdit(E.row.entity,E.col.colDef,e)})}(e)})}function L(){if(E.grid.disableScrolling=!1,m){n&&n.grid.api.cellNav&&n.focus();var e=angular.element(p.children()[0]);y.$destroy();for(var i=p.children(),t=1;t
    '),e.put("ui-grid/dropdownEditor",'
    '),e.put("ui-grid/fileChooserEditor",'
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.empty-base-layer.js b/src/ui-grid.empty-base-layer.js new file mode 100644 index 0000000000..9497f359c0 --- /dev/null +++ b/src/ui-grid.empty-base-layer.js @@ -0,0 +1,177 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.emptyBaseLayer + * @description + * + * # ui.grid.emptyBaseLayer + * + * + * + * This module provides the ability to have the background of the ui-grid be empty rows, this would be displayed in the case were + * the grid height is greater then the amount of rows displayed. + * + *
    + */ + var module = angular.module('ui.grid.emptyBaseLayer', ['ui.grid']); + + + /** + * @ngdoc service + * @name ui.grid.emptyBaseLayer.service:uiGridBaseLayerService + * + * @description Services for the empty base layer grid + */ + module.service('uiGridBaseLayerService', ['gridUtil', '$compile', function (gridUtil, $compile) { + return { + initializeGrid: function (grid, disableEmptyBaseLayer) { + + /** + * @ngdoc object + * @name ui.grid.emptyBaseLayer.api:GridOptions + * + * @description GridOptions for emptyBaseLayer feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + grid.baseLayer = { + emptyRows: [] + }; + + /** + * @ngdoc object + * @name enableEmptyGridBaseLayer + * @propertyOf ui.grid.emptyBaseLayer.api:GridOptions + * @description Enable empty base layer, which shows empty rows as background on the entire grid + *
    Defaults to true, if the directive is used. + *
    Set to false either by setting this attribute or passing false to the directive. + */ + // default option to true unless it was explicitly set to false + if (grid.options.enableEmptyGridBaseLayer !== false) { + grid.options.enableEmptyGridBaseLayer = !disableEmptyBaseLayer; + } + }, + + setNumberOfEmptyRows: function(viewportHeight, grid) { + var rowHeight = grid.options.rowHeight, + rows = Math.ceil(viewportHeight / rowHeight); + + if (rows > 0) { + grid.baseLayer.emptyRows = []; + for (var i = 0; i < rows; i++) { + grid.baseLayer.emptyRows.push({}); + } + } + } + }; + }]); + + /** + * @ngdoc object + * @name ui.grid.emptyBaseLayer.directive:uiGridEmptyBaseLayer + * @description Shows empty rows in the background of the ui-grid, these span + * the full height of the ui-grid, so that there won't be blank space below the shown rows. + * @example + *
    +   *  
    + *
    + * Or you can enable/disable it dynamically by passing in true or false. It doesn't + * the value, so it would only be set on initial render. + *
    +   *  
    + *
    + */ + module.directive('uiGridEmptyBaseLayer', ['gridUtil', 'uiGridBaseLayerService', + '$parse', + function (gridUtil, uiGridBaseLayerService, $parse) { + return { + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + var disableEmptyBaseLayer = $parse($attrs.uiGridEmptyBaseLayer)($scope) === false; + + uiGridBaseLayerService.initializeGrid(uiGridCtrl.grid, disableEmptyBaseLayer); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + if (!uiGridCtrl.grid.options.enableEmptyGridBaseLayer) { + return; + } + + var renderBodyContainer = uiGridCtrl.grid.renderContainers.body, + viewportHeight = renderBodyContainer.getViewportHeight(); + + function heightHasChanged() { + var newViewPortHeight = renderBodyContainer.getViewportHeight(); + + if (newViewPortHeight !== viewportHeight) { + viewportHeight = newViewPortHeight; + return true; + } + return false; + } + + function getEmptyBaseLayerCss(viewportHeight) { + // Set ui-grid-empty-base-layer height + return '.grid' + uiGridCtrl.grid.id + + ' .ui-grid-render-container ' + + '.ui-grid-empty-base-layer-container.ui-grid-canvas ' + + '{ height: ' + viewportHeight + 'px; }'; + } + + uiGridCtrl.grid.registerStyleComputation({ + func: function() { + if (heightHasChanged()) { + uiGridBaseLayerService.setNumberOfEmptyRows(viewportHeight, uiGridCtrl.grid); + } + return getEmptyBaseLayerCss(viewportHeight); + } + }); + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.emptyBaseLayer.directive:uiGridViewport + * @description stacks on the uiGridViewport directive to append the empty grid base layer html elements to the + * default gridRow template + */ + module.directive('uiGridViewport', + ['$compile', 'gridUtil', '$templateCache', + function ($compile, gridUtil, $templateCache) { + return { + priority: -200, + scope: false, + compile: function ($elm) { + var emptyBaseLayerContainer = $templateCache.get('ui-grid/emptyBaseLayerContainer'); + $elm.prepend(emptyBaseLayerContainer); + return { + pre: function ($scope, $elm, $attrs, controllers) { + }, + post: function ($scope, $elm, $attrs, controllers) { + } + }; + } + }; + }]); + +})(); + +angular.module('ui.grid.emptyBaseLayer').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/emptyBaseLayerContainer', + "
    " + ); + +}]); diff --git a/src/ui-grid.empty-base-layer.min.js b/src/ui-grid.empty-base-layer.min.js new file mode 100644 index 0000000000..b121fb0bf0 --- /dev/null +++ b/src/ui-grid.empty-base-layer.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.emptyBaseLayer",["ui.grid"]);e.service("uiGridBaseLayerService",["gridUtil","$compile",function(e,i){return{initializeGrid:function(e,i){!(e.baseLayer={emptyRows:[]})!==e.options.enableEmptyGridBaseLayer&&(e.options.enableEmptyGridBaseLayer=!i)},setNumberOfEmptyRows:function(e,i){var r=i.options.rowHeight,t=Math.ceil(e/r);if(0
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.expandable.js b/src/ui-grid.expandable.js new file mode 100644 index 0000000000..a57ec20933 --- /dev/null +++ b/src/ui-grid.expandable.js @@ -0,0 +1,650 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.expandable + * @description + * + * # ui.grid.expandable + * + * + * + * This module provides the ability to create subgrids with the ability to expand a row + * to show the subgrid. + * + *
    + */ + var module = angular.module('ui.grid.expandable', ['ui.grid']); + + /** + * @ngdoc service + * @name ui.grid.expandable.service:uiGridExpandableService + * + * @description Services for the expandable grid + */ + module.service('uiGridExpandableService', ['gridUtil', function (gridUtil) { + var service = { + initializeGrid: function (grid) { + + grid.expandable = {}; + grid.expandable.expandedAll = false; + + /** + * @ngdoc boolean + * @name enableOnDblClickExpand + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Defaults to true. + * @example + *
    +         *    $scope.gridOptions = {
    +         *      onDblClickExpand: false
    +         *    }
    +         *  
    + */ + grid.options.enableOnDblClickExpand = grid.options.enableOnDblClickExpand !== false; + /** + * @ngdoc boolean + * @name enableExpandable + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Whether or not to use expandable feature, allows you to turn off expandable on specific grids + * within your application, or in specific modes on _this_ grid. Defaults to true. + * @example + *
    +         *    $scope.gridOptions = {
    +         *      enableExpandable: false
    +         *    }
    +         *  
    + */ + grid.options.enableExpandable = grid.options.enableExpandable !== false; + + /** + * @ngdoc object + * @name showExpandAllButton + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Whether or not to display the expand all button, allows you to hide expand all button on specific grids + * within your application, or in specific modes on _this_ grid. Defaults to true. + * @example + *
    +         *    $scope.gridOptions = {
    +         *      showExpandAllButton: false
    +         *    }
    +         *  
    + */ + grid.options.showExpandAllButton = grid.options.showExpandAllButton !== false; + + /** + * @ngdoc object + * @name expandableRowHeight + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Height in pixels of the expanded subgrid. Defaults to + * 150 + * @example + *
    +         *    $scope.gridOptions = {
    +         *      expandableRowHeight: 150
    +         *    }
    +         *  
    + */ + grid.options.expandableRowHeight = grid.options.expandableRowHeight || 150; + + /** + * @ngdoc object + * @name expandableRowHeaderWidth + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Width in pixels of the expandable column. Defaults to 40 + * @example + *
    +         *    $scope.gridOptions = {
    +         *      expandableRowHeaderWidth: 40
    +         *    }
    +         *  
    + */ + grid.options.expandableRowHeaderWidth = grid.options.expandableRowHeaderWidth || 40; + + /** + * @ngdoc object + * @name expandableRowTemplate + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Mandatory. The template for your expanded row + * @example + *
    +         *    $scope.gridOptions = {
    +         *      expandableRowTemplate: 'expandableRowTemplate.html'
    +         *    }
    +         *  
    + */ + if ( grid.options.enableExpandable && !grid.options.expandableRowTemplate ) { + gridUtil.logError( 'You have not set the expandableRowTemplate, disabling expandable module' ); + grid.options.enableExpandable = false; + } + + /** + * @ngdoc object + * @name ui.grid.expandable.api:PublicApi + * + * @description Public Api for expandable feature + */ + /** + * @ngdoc object + * @name ui.grid.expandable.api:GridRow + * + * @description Additional properties added to GridRow when using the expandable module + */ + /** + * @ngdoc object + * @name ui.grid.expandable.api:GridOptions + * + * @description Options for configuring the expandable feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + var publicApi = { + events: { + expandable: { + /** + * @ngdoc event + * @name rowExpandedBeforeStateChanged + * @eventOf ui.grid.expandable.api:PublicApi + * @description raised when row is expanding or collapsing + *
    +               *      gridApi.expandable.on.rowExpandedBeforeStateChanged(scope,function(row, event) {})
    +               * 
    + * @param {scope} scope the application scope + * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event + */ + rowExpandedBeforeStateChanged: function(scope, row, evt) {}, + + /** + * @ngdoc event + * @name rowExpandedStateChanged + * @eventOf ui.grid.expandable.api:PublicApi + * @description raised when row expanded or collapsed + *
    +               *      gridApi.expandable.on.rowExpandedStateChanged(scope,function(row, event) {})
    +               * 
    + * @param {scope} scope the application scope + * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event + */ + rowExpandedStateChanged: function (scope, row, evt) {}, + + /** + * @ngdoc event + * @name rowExpandedRendered + * @eventOf ui.grid.expandable.api:PublicApi + * @description raised when expanded row is rendered + *
    +               *      gridApi.expandable.on.rowExpandedRendered(scope,function(row, event) {})
    +               * 
    + * @param {scope} scope the application scope + * @param {GridRow} row the row that was expanded + * @param {Event} evt object if raised from an event + */ + rowExpandedRendered: function (scope, row, evt) {} + } + }, + + methods: { + expandable: { + /** + * @ngdoc method + * @name toggleRowExpansion + * @methodOf ui.grid.expandable.api:PublicApi + * @description Toggle a specific row + *
    +               *      gridApi.expandable.toggleRowExpansion(rowEntity, event);
    +               * 
    + * @param {object} rowEntity the data entity for the row you want to expand + * @param {Event} [e] event (if exist) + */ + toggleRowExpansion: function (rowEntity, e) { + var row = grid.getRow(rowEntity); + + if (row !== null) { + service.toggleRowExpansion(grid, row, e); + } + }, + + /** + * @ngdoc method + * @name expandAllRows + * @methodOf ui.grid.expandable.api:PublicApi + * @description Expand all subgrids. + *
    +               *      gridApi.expandable.expandAllRows();
    +               * 
    + */ + expandAllRows: function() { + service.expandAllRows(grid); + }, + + /** + * @ngdoc method + * @name collapseAllRows + * @methodOf ui.grid.expandable.api:PublicApi + * @description Collapse all subgrids. + *
    +               *      gridApi.expandable.collapseAllRows();
    +               * 
    + */ + collapseAllRows: function() { + service.collapseAllRows(grid); + }, + + /** + * @ngdoc method + * @name toggleAllRows + * @methodOf ui.grid.expandable.api:PublicApi + * @description Toggle all subgrids. + *
    +               *      gridApi.expandable.toggleAllRows();
    +               * 
    + */ + toggleAllRows: function() { + service.toggleAllRows(grid); + }, + /** + * @ngdoc function + * @name expandRow + * @methodOf ui.grid.expandable.api:PublicApi + * @description Expand the data row + * @param {object} rowEntity gridOptions.data[] array instance + */ + expandRow: function (rowEntity) { + var row = grid.getRow(rowEntity); + + if (row !== null && !row.isExpanded) { + service.toggleRowExpansion(grid, row); + } + }, + /** + * @ngdoc function + * @name collapseRow + * @methodOf ui.grid.expandable.api:PublicApi + * @description Collapse the data row + * @param {object} rowEntity gridOptions.data[] array instance + */ + collapseRow: function (rowEntity) { + var row = grid.getRow(rowEntity); + + if (row !== null && row.isExpanded) { + service.toggleRowExpansion(grid, row); + } + }, + /** + * @ngdoc function + * @name getExpandedRows + * @methodOf ui.grid.expandable.api:PublicApi + * @description returns all expandedRow's entity references + */ + getExpandedRows: function () { + return service.getExpandedRows(grid).map(function (gridRow) { + return gridRow.entity; + }); + } + } + } + }; + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + /** + * + * @param grid + * @param row + * @param {Event} [e] event (if exist) + */ + toggleRowExpansion: function (grid, row, e) { + // trigger the "before change" event. Can change row height dynamically this way. + grid.api.expandable.raise.rowExpandedBeforeStateChanged(row); + /** + * @ngdoc object + * @name isExpanded + * @propertyOf ui.grid.expandable.api:GridRow + * @description Whether or not the row is currently expanded. + * @example + *
    +         *    $scope.api.expandable.on.rowExpandedStateChanged($scope, function (row) {
    +         *      if (row.isExpanded) {
    +         *        //...
    +         *      }
    +         *    });
    +         *  
    + */ + row.isExpanded = !row.isExpanded; + if (angular.isUndefined(row.expandedRowHeight)) { + row.expandedRowHeight = grid.options.expandableRowHeight; + } + + if (row.isExpanded) { + row.height = row.grid.options.rowHeight + row.expandedRowHeight; + grid.expandable.expandedAll = service.getExpandedRows(grid).length === grid.rows.length; + } + else { + row.height = row.grid.options.rowHeight; + grid.expandable.expandedAll = false; + } + grid.api.expandable.raise.rowExpandedStateChanged(row, e); + + // fire event on render complete + function _tWatcher() { + if (row.expandedRendered) { + grid.api.expandable.raise.rowExpandedRendered(row, e); + } + else { + window.setTimeout(_tWatcher, 1e2); + } + } + _tWatcher(); + }, + + expandAllRows: function(grid) { + grid.renderContainers.body.visibleRowCache.forEach( function(row) { + if (!row.isExpanded && !(row.entity.subGridOptions && row.entity.subGridOptions.disableRowExpandable)) { + service.toggleRowExpansion(grid, row); + } + }); + grid.expandable.expandedAll = true; + grid.queueGridRefresh(); + }, + + collapseAllRows: function(grid) { + grid.renderContainers.body.visibleRowCache.forEach( function(row) { + if (row.isExpanded) { + service.toggleRowExpansion(grid, row); + } + }); + grid.expandable.expandedAll = false; + grid.queueGridRefresh(); + }, + + toggleAllRows: function(grid) { + if (grid.expandable.expandedAll) { + service.collapseAllRows(grid); + } + else { + service.expandAllRows(grid); + } + }, + + getExpandedRows: function (grid) { + return grid.rows.filter(function (row) { + return row.isExpanded; + }); + } + }; + return service; + }]); + + /** + * @ngdoc object + * @name enableExpandableRowHeader + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Show a rowHeader to provide the expandable buttons. If set to false then implies + * you're going to use a custom method for expanding and collapsing the subgrids. Defaults to true. + * @example + *
    +   *    $scope.gridOptions = {
    +   *      enableExpandableRowHeader: false
    +   *    }
    +   *  
    + */ + + module.directive('uiGridExpandable', ['uiGridExpandableService', '$templateCache', + function (uiGridExpandableService, $templateCache) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridExpandableService.initializeGrid(uiGridCtrl.grid); + + if (!uiGridCtrl.grid.options.enableExpandable) { + return; + } + + if (uiGridCtrl.grid.options.enableExpandableRowHeader !== false ) { + var expandableRowHeaderColDef = { + name: 'expandableButtons', + displayName: '', + exporterSuppressExport: true, + enableColumnResizing: false, + enableColumnMenu: false, + width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 30 + }; + + expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader'); + expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader'); + uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) {} + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.expandable.directive:uiGrid + * @description stacks on the uiGrid directive to register child grid with parent row when child is created + */ + module.directive('uiGrid', + function () { + return { + replace: true, + priority: 599, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + + uiGridCtrl.grid.api.core.on.renderingComplete($scope, function() { + // if a parent grid row is on the scope, then add the parentRow property to this childGrid + if ($scope.row && $scope.row.grid && $scope.row.grid.options + && $scope.row.grid.options.enableExpandable) { + + /** + * @ngdoc directive + * @name ui.grid.expandable.class:Grid + * @description Additional Grid properties added by expandable module + */ + + /** + * @ngdoc object + * @name parentRow + * @propertyOf ui.grid.expandable.class:Grid + * @description reference to the expanded parent row that owns this grid + */ + uiGridCtrl.grid.parentRow = $scope.row; + + // todo: adjust height on parent row when child grid height changes. we need some sort of gridHeightChanged event + // uiGridCtrl.grid.core.on.canvasHeightChanged($scope, function(oldHeight, newHeight) { + // uiGridCtrl.grid.parentRow = newHeight; + // }); + } + }); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) {} + }; + } + }; + }); + + /** + * @ngdoc directive + * @name ui.grid.expandable.directive:uiGridExpandableRow + * @description directive to render the Row template on Expand + */ + module.directive('uiGridExpandableRow', + ['uiGridExpandableService', '$compile', 'uiGridConstants','gridUtil', + function (uiGridExpandableService, $compile, uiGridConstants, gridUtil) { + + return { + replace: false, + priority: 0, + scope: false, + compile: function () { + return { + pre: function ($scope, $elm) { + gridUtil.getTemplate($scope.grid.options.expandableRowTemplate).then( + function (template) { + if ($scope.grid.options.expandableRowScope) { + /** + * @ngdoc object + * @name expandableRowScope + * @propertyOf ui.grid.expandable.api:GridOptions + * @description Variables of object expandableScope will be available in the scope of the expanded subgrid + * @example + *
    +                     *    $scope.gridOptions = {
    +                     *      expandableRowScope: expandableScope
    +                     *    }
    +                     *  
    + */ + var expandableRowScope = $scope.grid.options.expandableRowScope; + + for (var property in expandableRowScope) { + if (expandableRowScope.hasOwnProperty(property)) { + $scope[property] = expandableRowScope[property]; + } + } + } + var expandedRowElement = angular.element(template); + + expandedRowElement = $compile(expandedRowElement)($scope); + $elm.append(expandedRowElement); + $scope.row.element = $elm; + $scope.row.expandedRendered = true; + }); + }, + + post: function ($scope, $elm) { + $scope.row.element = $elm; + $scope.$on('$destroy', function() { + $scope.row.expandedRendered = false; + }); + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.expandable.directive:uiGridRow + * @description stacks on the uiGridRow directive to add support for expandable rows + */ + module.directive('uiGridRow', + function () { + return { + priority: -200, + scope: false, + compile: function () { + return { + pre: function ($scope, $elm) { + if (!$scope.grid.options.enableExpandable) { + return; + } + + $scope.expandableRow = {}; + + $scope.expandableRow.shouldRenderExpand = function () { + return $scope.colContainer.name === 'body' + && $scope.grid.options.enableExpandable !== false + && $scope.row.isExpanded + && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered); + }; + + $scope.expandableRow.shouldRenderFiller = function () { + return $scope.row.isExpanded + && ( + $scope.colContainer.name !== 'body' + || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered)); + }; + + if ($scope.grid.options.enableOnDblClickExpand) { + $elm.on('dblclick', function (event) { + // if necessary, it is possible for everyone to stop the processing of a single click OR + // Inside the Config in the output agent to enter a line: + // event.stopPropagation() + $scope.grid.api.expandable.toggleRowExpansion($scope.row.entity, event); + }); + } + }, + post: function ($scope, $elm, $attrs, controllers) {} + }; + } + }; + }); + + /** + * @ngdoc directive + * @name ui.grid.expandable.directive:uiGridViewport + * @description stacks on the uiGridViewport directive to append the expandable row html elements to the + * default gridRow template + */ + module.directive('uiGridViewport', + ['$compile', 'gridUtil', '$templateCache', + function ($compile, gridUtil, $templateCache) { + return { + priority: -200, + scope: false, + compile: function ($elm) { + + // todo: this adds ng-if watchers to each row even if the grid is not using expandable directive + // or options.enableExpandable == false + // The alternative is to compile the template and append to each row in a uiGridRow directive + + var rowRepeatDiv = angular.element($elm.children().children()[0]), + expandedRowFillerElement = $templateCache.get('ui-grid/expandableScrollFiller'), + expandedRowElement = $templateCache.get('ui-grid/expandableRow'); + + rowRepeatDiv.append(expandedRowElement); + rowRepeatDiv.append(expandedRowFillerElement); + return { + pre: function ($scope, $elm, $attrs, controllers) { + }, + post: function ($scope, $elm, $attrs, controllers) { + } + }; + } + }; + }]); + +})(); + +angular.module('ui.grid.expandable').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/expandableRow', + "
    " + ); + + + $templateCache.put('ui-grid/expandableRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/expandableScrollFiller', + "
     
    " + ); + + + $templateCache.put('ui-grid/expandableTopRowHeader', + "
    " + ); + +}]); diff --git a/src/ui-grid.expandable.min.js b/src/ui-grid.expandable.min.js new file mode 100644 index 0000000000..29545ddc02 --- /dev/null +++ b/src/ui-grid.expandable.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.expandable",["ui.grid"]);e.service("uiGridExpandableService",["gridUtil",function(n){var a={initializeGrid:function(o){o.expandable={},o.expandable.expandedAll=!1,o.options.enableOnDblClickExpand=!1!==o.options.enableOnDblClickExpand,o.options.enableExpandable=!1!==o.options.enableExpandable,o.options.showExpandAllButton=!1!==o.options.showExpandAllButton,o.options.expandableRowHeight=o.options.expandableRowHeight||150,o.options.expandableRowHeaderWidth=o.options.expandableRowHeaderWidth||40,o.options.enableExpandable&&!o.options.expandableRowTemplate&&(n.logError("You have not set the expandableRowTemplate, disabling expandable module"),o.options.enableExpandable=!1);var e={events:{expandable:{rowExpandedBeforeStateChanged:function(e,n,i){},rowExpandedStateChanged:function(e,n,i){},rowExpandedRendered:function(e,n,i){}}},methods:{expandable:{toggleRowExpansion:function(e,n){var i=o.getRow(e);null!==i&&a.toggleRowExpansion(o,i,n)},expandAllRows:function(){a.expandAllRows(o)},collapseAllRows:function(){a.collapseAllRows(o)},toggleAllRows:function(){a.toggleAllRows(o)},expandRow:function(e){var n=o.getRow(e);null===n||n.isExpanded||a.toggleRowExpansion(o,n)},collapseRow:function(e){var n=o.getRow(e);null!==n&&n.isExpanded&&a.toggleRowExpansion(o,n)},getExpandedRows:function(){return a.getExpandedRows(o).map(function(e){return e.entity})}}}};o.api.registerEventsFromObject(e.events),o.api.registerMethodsFromObject(e.methods)},toggleRowExpansion:function(n,i,o){n.api.expandable.raise.rowExpandedBeforeStateChanged(i),i.isExpanded=!i.isExpanded,angular.isUndefined(i.expandedRowHeight)&&(i.expandedRowHeight=n.options.expandableRowHeight),i.isExpanded?(i.height=i.grid.options.rowHeight+i.expandedRowHeight,n.expandable.expandedAll=a.getExpandedRows(n).length===n.rows.length):(i.height=i.grid.options.rowHeight,n.expandable.expandedAll=!1),n.api.expandable.raise.rowExpandedStateChanged(i,o),function e(){i.expandedRendered?n.api.expandable.raise.rowExpandedRendered(i,o):window.setTimeout(e,100)}()},expandAllRows:function(n){n.renderContainers.body.visibleRowCache.forEach(function(e){e.isExpanded||e.entity.subGridOptions&&e.entity.subGridOptions.disableRowExpandable||a.toggleRowExpansion(n,e)}),n.expandable.expandedAll=!0,n.queueGridRefresh()},collapseAllRows:function(n){n.renderContainers.body.visibleRowCache.forEach(function(e){e.isExpanded&&a.toggleRowExpansion(n,e)}),n.expandable.expandedAll=!1,n.queueGridRefresh()},toggleAllRows:function(e){e.expandable.expandedAll?a.collapseAllRows(e):a.expandAllRows(e)},getExpandedRows:function(e){return e.rows.filter(function(e){return e.isExpanded})}};return a}]),e.directive("uiGridExpandable",["uiGridExpandableService","$templateCache",function(d,l){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,n,i,o){if(d.initializeGrid(o.grid),o.grid.options.enableExpandable&&!1!==o.grid.options.enableExpandableRowHeader){var a={name:"expandableButtons",displayName:"",exporterSuppressExport:!0,enableColumnResizing:!1,enableColumnMenu:!1,width:o.grid.options.expandableRowHeaderWidth||30};a.cellTemplate=l.get("ui-grid/expandableRowHeader"),a.headerCellTemplate=l.get("ui-grid/expandableTopRowHeader"),o.grid.addRowHeaderColumn(a,-90)}},post:function(e,n,i,o){}}}}}]),e.directive("uiGrid",function(){return{replace:!0,priority:599,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,n,i,o){o.grid.api.core.on.renderingComplete(e,function(){e.row&&e.row.grid&&e.row.grid.options&&e.row.grid.options.enableExpandable&&(o.grid.parentRow=e.row)})},post:function(e,n,i,o){}}}}}),e.directive("uiGridExpandableRow",["uiGridExpandableService","$compile","uiGridConstants","gridUtil",function(e,l,n,i){return{replace:!1,priority:0,scope:!1,compile:function(){return{pre:function(a,d){i.getTemplate(a.grid.options.expandableRowTemplate).then(function(e){if(a.grid.options.expandableRowScope){var n=a.grid.options.expandableRowScope;for(var i in n)n.hasOwnProperty(i)&&(a[i]=n[i])}var o=angular.element(e);o=l(o)(a),d.append(o),a.row.element=d,a.row.expandedRendered=!0})},post:function(e,n){e.row.element=n,e.$on("$destroy",function(){e.row.expandedRendered=!1})}}}}}]),e.directive("uiGridRow",function(){return{priority:-200,scope:!1,compile:function(){return{pre:function(n,e){n.grid.options.enableExpandable&&(n.expandableRow={},n.expandableRow.shouldRenderExpand=function(){return"body"===n.colContainer.name&&!1!==n.grid.options.enableExpandable&&n.row.isExpanded&&(!n.grid.isScrollingVertically||n.row.expandedRendered)},n.expandableRow.shouldRenderFiller=function(){return n.row.isExpanded&&("body"!==n.colContainer.name||n.grid.isScrollingVertically&&!n.row.expandedRendered)},n.grid.options.enableOnDblClickExpand&&e.on("dblclick",function(e){n.grid.api.expandable.toggleRowExpansion(n.row.entity,e)}))},post:function(e,n,i,o){}}}}}),e.directive("uiGridViewport",["$compile","gridUtil","$templateCache",function(e,n,a){return{priority:-200,scope:!1,compile:function(e){var n=angular.element(e.children().children()[0]),i=a.get("ui-grid/expandableScrollFiller"),o=a.get("ui-grid/expandableRow");return n.append(o),n.append(i),{pre:function(e,n,i,o){},post:function(e,n,i,o){}}}}}])}(),angular.module("ui.grid.expandable").run(["$templateCache",function(e){"use strict";e.put("ui-grid/expandableRow",'
    '),e.put("ui-grid/expandableRowHeader",'
    '),e.put("ui-grid/expandableScrollFiller","
     
    "),e.put("ui-grid/expandableTopRowHeader",'
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.exporter.js b/src/ui-grid.exporter.js new file mode 100644 index 0000000000..070ca7b693 --- /dev/null +++ b/src/ui-grid.exporter.js @@ -0,0 +1,1739 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +/* global ExcelBuilder */ +/* global console */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.exporter + * @description + * + * # ui.grid.exporter + * + * + * + * This module provides the ability to export data from the grid. + * + * Data can be exported in a range of formats, and all data, visible + * data, or selected rows can be exported, with all columns or visible + * columns. + * + * No UI is provided, the caller should provide their own UI/buttons + * as appropriate, or enable the gridMenu + * + *
    + *
    + * + *
    + */ + + var module = angular.module('ui.grid.exporter', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.exporter.constant:uiGridExporterConstants + * + * @description constants available in exporter module + */ + /** + * @ngdoc property + * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants + * @name ALL + * @description export all data, including data not visible. Can + * be set for either rowTypes or colTypes + */ + /** + * @ngdoc property + * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants + * @name VISIBLE + * @description export only visible data, including data not visible. Can + * be set for either rowTypes or colTypes + */ + /** + * @ngdoc property + * @propertyOf ui.grid.exporter.constant:uiGridExporterConstants + * @name SELECTED + * @description export all data, including data not visible. Can + * be set only for rowTypes, selection of only some columns is + * not supported + */ + module.constant('uiGridExporterConstants', { + featureName: 'exporter', + rowHeaderColName: 'treeBaseRowHeaderCol', + selectionRowHeaderColName: 'selectionRowHeaderCol', + ALL: 'all', + VISIBLE: 'visible', + SELECTED: 'selected', + CSV_CONTENT: 'CSV_CONTENT', + BUTTON_LABEL: 'BUTTON_LABEL', + FILE_NAME: 'FILE_NAME' + }); + + /** + * @ngdoc service + * @name ui.grid.exporter.service:uiGridExporterService + * + * @description Services for exporter feature + */ + module.service('uiGridExporterService', ['$filter', '$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', + function ($filter, $q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) { + var service = { + + delay: 100, + + initializeGrid: function (grid) { + + // add feature namespace and any properties to grid for needed state + grid.exporter = {}; + this.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.exporter.api:PublicApi + * + * @description Public Api for exporter feature + */ + var publicApi = { + events: { + exporter: { + } + }, + methods: { + exporter: { + /** + * @ngdoc function + * @name csvExport + * @methodOf ui.grid.exporter.api:PublicApi + * @description Exports rows from the grid in csv format, + * the data exported is selected based on the provided options + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE + */ + csvExport: function (rowTypes, colTypes) { + service.csvExport(grid, rowTypes, colTypes); + }, + /** + * @ngdoc function + * @name pdfExport + * @methodOf ui.grid.exporter.api:PublicApi + * @description Exports rows from the grid in pdf format, + * the data exported is selected based on the provided options + * Note that this function has a dependency on pdfMake, all + * going well this has been installed for you. + * The resulting pdf opens in a new browser window. + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE + */ + pdfExport: function (rowTypes, colTypes) { + service.pdfExport(grid, rowTypes, colTypes); + }, + /** + * @ngdoc function + * @name excelExport + * @methodOf ui.grid.exporter.api:PublicApi + * @description Exports rows from the grid in excel format, + * the data exported is selected based on the provided options + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE + */ + excelExport: function (rowTypes, colTypes) { + service.excelExport(grid, rowTypes, colTypes); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + + if (grid.api.core.addToGridMenu) { + service.addToMenu( grid ); + } else { + // order of registration is not guaranteed, register in a little while + $interval( function() { + if (grid.api.core.addToGridMenu) { + service.addToMenu( grid ); + } + }, this.delay, 1); + } + + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.exporter.api:GridOptions + * + * @description GridOptions for exporter feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + /** + * @ngdoc object + * @name ui.grid.exporter.api:ColumnDef + * @description ColumnDef settings for exporter + */ + /** + * @ngdoc object + * @name exporterSuppressMenu + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Don't show the export menu button, implying the user + * will roll their own UI for calling the exporter + *
    Defaults to false + */ + gridOptions.exporterSuppressMenu = gridOptions.exporterSuppressMenu === true; + /** + * @ngdoc object + * @name exporterMenuLabel + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The text to show on the exporter menu button + * link + *
    Defaults to 'Export' + */ + gridOptions.exporterMenuLabel = gridOptions.exporterMenuLabel ? gridOptions.exporterMenuLabel : 'Export'; + /** + * @ngdoc object + * @name exporterSuppressColumns + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Columns that should not be exported. The selectionRowHeader is already automatically + * suppressed, but if you had a button column or some other "system" column that shouldn't be shown in the + * output then add it in this list. You should provide an array of column names. + *
    Defaults to: [] + *
    +           *   gridOptions.exporterSuppressColumns = [ 'buttons' ];
    +           * 
    + */ + gridOptions.exporterSuppressColumns = gridOptions.exporterSuppressColumns ? gridOptions.exporterSuppressColumns : []; + /** + * @ngdoc object + * @name exporterCsvColumnSeparator + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The character to use as column separator + * link + *
    Defaults to ',' + */ + gridOptions.exporterCsvColumnSeparator = gridOptions.exporterCsvColumnSeparator ? gridOptions.exporterCsvColumnSeparator : ','; + /** + * @ngdoc object + * @name exporterCsvFilename + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default filename to use when saving the downloaded csv. + * This will only work in some browsers. + *
    Defaults to 'download.csv' + */ + gridOptions.exporterCsvFilename = gridOptions.exporterCsvFilename ? gridOptions.exporterCsvFilename : 'download.csv'; + /** + * @ngdoc object + * @name exporterPdfFilename + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default filename to use when saving the downloaded pdf, only used in IE (other browsers open pdfs in a new window) + *
    Defaults to 'download.pdf' + */ + gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf'; + /** + * @ngdoc object + * @name exporterExcelFilename + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window) + *
    Defaults to 'download.xlsx' + */ + gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx'; + + /** + * @ngdoc object + * @name exporterExcelSheetName + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default sheetname to use when saving the downloaded to excel + *
    Defaults to 'Sheet1' + */ + gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1'; + + /** + * @ngdoc object + * @name exporterOlderExcelCompatibility + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Some versions of excel don't like the utf-16 BOM on the front, and it comes + * through as  in the first column header. Setting this option to false will suppress this, at the + * expense of proper utf-16 handling in applications that do recognise the BOM + *
    Defaults to false + */ + gridOptions.exporterOlderExcelCompatibility = gridOptions.exporterOlderExcelCompatibility === true; + /** + * @ngdoc object + * @name exporterIsExcelCompatible + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Separator header, used to set a custom column separator in a csv file, only works on MS Excel. + * Used it on other programs will make csv content display unproperly. Setting this option to false won't add this header. + *
    Defaults to false + */ + gridOptions.exporterIsExcelCompatible = gridOptions.exporterIsExcelCompatible === true; + /** + * @ngdoc object + * @name exporterMenuItemOrder + * @propertyOf ui.grid.exporter.api:GridOptions + * @description An option to determine the starting point for the menu items created by the exporter + *
    Defaults to 200 + */ + gridOptions.exporterMenuItemOrder = gridOptions.exporterMenuItemOrder ? gridOptions.exporterMenuItemOrder : 200; + /** + * @ngdoc object + * @name exporterPdfDefaultStyle + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The default style in pdfMake format + *
    Defaults to: + *
    +           *   {
    +           *     fontSize: 11
    +           *   }
    +           * 
    + */ + gridOptions.exporterPdfDefaultStyle = gridOptions.exporterPdfDefaultStyle ? gridOptions.exporterPdfDefaultStyle : { fontSize: 11 }; + /** + * @ngdoc object + * @name exporterPdfTableStyle + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The table style in pdfMake format + *
    Defaults to: + *
    +           *   {
    +           *     margin: [0, 5, 0, 15]
    +           *   }
    +           * 
    + */ + gridOptions.exporterPdfTableStyle = gridOptions.exporterPdfTableStyle ? gridOptions.exporterPdfTableStyle : { margin: [0, 5, 0, 15] }; + /** + * @ngdoc object + * @name exporterPdfTableHeaderStyle + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The tableHeader style in pdfMake format + *
    Defaults to: + *
    +           *   {
    +           *     bold: true,
    +           *     fontSize: 12,
    +           *     color: 'black'
    +           *   }
    +           * 
    + */ + gridOptions.exporterPdfTableHeaderStyle = gridOptions.exporterPdfTableHeaderStyle ? gridOptions.exporterPdfTableHeaderStyle : { bold: true, fontSize: 12, color: 'black' }; + /** + * @ngdoc object + * @name exporterPdfHeader + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The header section for pdf exports. Can be + * simple text: + *
    +           *   gridOptions.exporterPdfHeader = 'My Header';
    +           * 
    + * Can be a more complex object in pdfMake format: + *
    +           *   gridOptions.exporterPdfHeader = {
    +           *     columns: [
    +           *       'Left part',
    +           *       { text: 'Right part', alignment: 'right' }
    +           *     ]
    +           *   };
    +           * 
    + * Or can be a function, allowing page numbers and the like + *
    +           *   gridOptions.exporterPdfHeader: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
    +           * 
    + */ + gridOptions.exporterPdfHeader = gridOptions.exporterPdfHeader ? gridOptions.exporterPdfHeader : null; + /** + * @ngdoc object + * @name exporterPdfFooter + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The header section for pdf exports. Can be + * simple text: + *
    +           *   gridOptions.exporterPdfFooter = 'My Footer';
    +           * 
    + * Can be a more complex object in pdfMake format: + *
    +           *   gridOptions.exporterPdfFooter = {
    +           *     columns: [
    +           *       'Left part',
    +           *       { text: 'Right part', alignment: 'right' }
    +           *     ]
    +           *   };
    +           * 
    + * Or can be a function, allowing page numbers and the like + *
    +           *   gridOptions.exporterPdfFooter: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
    +           * 
    + */ + gridOptions.exporterPdfFooter = gridOptions.exporterPdfFooter ? gridOptions.exporterPdfFooter : null; + /** + * @ngdoc object + * @name exporterPdfOrientation + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The orientation, should be a valid pdfMake value, + * 'landscape' or 'portrait' + *
    Defaults to landscape + */ + gridOptions.exporterPdfOrientation = gridOptions.exporterPdfOrientation ? gridOptions.exporterPdfOrientation : 'landscape'; + /** + * @ngdoc object + * @name exporterPdfPageSize + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The orientation, should be a valid pdfMake + * paper size, usually 'A4' or 'LETTER' + * {@link https://github.com/bpampuch/pdfmake/blob/master/src/standardPageSizes.js pdfMake page sizes} + *
    Defaults to A4 + */ + gridOptions.exporterPdfPageSize = gridOptions.exporterPdfPageSize ? gridOptions.exporterPdfPageSize : 'A4'; + /** + * @ngdoc object + * @name exporterPdfMaxGridWidth + * @propertyOf ui.grid.exporter.api:GridOptions + * @description The maxium grid width - the current grid width + * will be scaled to match this, with any fixed width columns + * being adjusted accordingly. + *
    Defaults to 720 (for A4 landscape), use 670 for LETTER + */ + gridOptions.exporterPdfMaxGridWidth = gridOptions.exporterPdfMaxGridWidth ? gridOptions.exporterPdfMaxGridWidth : 720; + /** + * @ngdoc object + * @name exporterPdfTableLayout + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A tableLayout in pdfMake format, + * controls gridlines and the like. We use the default + * layout usually. + *
    Defaults to null, which means no layout + */ + + /** + * @ngdoc object + * @name exporterMenuAllData + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add export all data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuAllData = gridOptions.exporterMenuAllData !== undefined ? gridOptions.exporterMenuAllData : true; + + /** + * @ngdoc object + * @name exporterMenuVisibleData + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add export visible data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuVisibleData = gridOptions.exporterMenuVisibleData !== undefined ? gridOptions.exporterMenuVisibleData : true; + + /** + * @ngdoc object + * @name exporterMenuSelectedData + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add export selected data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuSelectedData = gridOptions.exporterMenuSelectedData !== undefined ? gridOptions.exporterMenuSelectedData : true; + + /** + * @ngdoc object + * @name exporterMenuCsv + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add csv export menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuCsv = gridOptions.exporterMenuCsv !== undefined ? gridOptions.exporterMenuCsv : true; + + /** + * @ngdoc object + * @name exporterMenuPdf + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add pdf export menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuPdf = gridOptions.exporterMenuPdf !== undefined ? gridOptions.exporterMenuPdf : true; + + /** + * @ngdoc object + * @name exporterMenuExcel + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Add excel export menu items to the ui-grid grid menu, if it's present. Defaults to true. + */ + gridOptions.exporterMenuExcel = gridOptions.exporterMenuExcel !== undefined ? gridOptions.exporterMenuExcel : true; + + /** + * @ngdoc object + * @name exporterPdfCustomFormatter + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A custom callback routine that changes the pdf document, adding any + * custom styling or content that is supported by pdfMake. Takes in the complete docDefinition, and + * must return an updated docDefinition ready for pdfMake. + * @example + * In this example we add a style to the style array, so that we can use it in our + * footer definition. + *
    +           *   gridOptions.exporterPdfCustomFormatter = function ( docDefinition ) {
    +           *     docDefinition.styles.footerStyle = { bold: true, fontSize: 10 };
    +           *     return docDefinition;
    +           *   }
    +           *
    +           *   gridOptions.exporterPdfFooter = { text: 'My footer', style: 'footerStyle' }
    +           * 
    + */ + gridOptions.exporterPdfCustomFormatter = ( gridOptions.exporterPdfCustomFormatter && typeof( gridOptions.exporterPdfCustomFormatter ) === 'function' ) ? gridOptions.exporterPdfCustomFormatter : function ( docDef ) { return docDef; }; + + /** + * @ngdoc object + * @name exporterHeaderFilterUseName + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Defaults to false, which leads to `displayName` being passed into the headerFilter. + * If set to true, then will pass `name` instead. + * + * + * @example + *
    +           *   gridOptions.exporterHeaderFilterUseName = true;
    +           * 
    + */ + gridOptions.exporterHeaderFilterUseName = gridOptions.exporterHeaderFilterUseName === true; + + /** + * @ngdoc object + * @name exporterHeaderFilter + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to apply to the header displayNames before exporting. Useful for internationalisation, + * for example if you were using angular-translate you'd set this to `$translate.instant`. Note that this + * call must be synchronous, it cannot be a call that returns a promise. + * + * Behaviour can be changed to pass in `name` instead of `displayName` through use of `exporterHeaderFilterUseName: true`. + * + * @example + *
    +           *   gridOptions.exporterHeaderFilter = function( displayName ) { return 'col: ' + name; };
    +           * 
    + * OR + *
    +           *   gridOptions.exporterHeaderFilter = $translate.instant;
    +           * 
    + */ + + /** + * @ngdoc function + * @name exporterFieldCallback + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to call for each field before exporting it. Allows + * massaging of raw data into a display format, for example if you have applied + * filters to convert codes into decodes, or you require + * a specific date format in the exported content. + * + * The method is called once for each field exported, and provides the grid, the + * gridCol and the GridRow for you to use as context in massaging the data. + * + * @param {Grid} grid provides the grid in case you have need of it + * @param {GridRow} row the row from which the data comes + * @param {GridColumn} col the column from which the data comes + * @param {object} value the value for your massaging + * @returns {object} you must return the massaged value ready for exporting + * + * @example + *
    +           *   gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
    +           *     if ( col.name === 'status' ) {
    +           *       value = decodeStatus( value );
    +           *     }
    +           *     return value;
    +           *   }
    +           * 
    + */ + gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : defaultExporterFieldCallback; + + /** + * @ngdoc function + * @name exporterFieldFormatCallback + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to call for each field before exporting it. Allows + * general object to be return to modify the format of a cell in the case of + * excel exports + * + * The method is called once for each field exported, and provides the grid, the + * gridCol and the GridRow for you to use as context in massaging the data. + * + * @param {Grid} grid provides the grid in case you have need of it + * @param {GridRow} row the row from which the data comes + * @param {GridColumn} col the column from which the data comes + * @param {object} value the value for your massaging + * @returns {object} you must return the massaged value ready for exporting + * + * @example + *
    +           *   gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
    +           *     if ( col.name === 'status' ) {
    +           *       value = decodeStatus( value );
    +           *     }
    +           *     return value;
    +           *   }
    +           * 
    + */ + gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; }; + + /** + * @ngdoc function + * @name exporterExcelCustomFormatters + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to call to setup formatters and store on docDefinition. + * + * The method is called at the start and can setup all the formatters to export to excel + * + * @param {Grid} grid provides the grid in case you have need of it + * @param {Workbook} row the row from which the data comes + * @param {docDefinition} The docDefinition that will have styles as a object to store formatters + * @returns {docDefinition} Updated docDefinition with formatter styles + * + * @example + *
    +           *   gridOptions.exporterExcelCustomFormatters = function(grid, workbook, docDefinition) {
    +           *     const formatters = {};
    +           *     const stylesheet = workbook.getStyleSheet();
    +           *     const headerFormatDefn = {
    +           *       'font': { 'size': 11, 'fontName': 'Calibri', 'bold': true },
    +           *       'alignment': { 'wrapText': false }
    +           *     };
    +           *
    +           *     formatters['header'] = headerFormatter;
    +           *     Object.assign(docDefinition.styles , formatters);
    +           *     grid.docDefinition = docDefinition;
    +           *     return docDefinition;
    +           *   }
    +           * 
    + */ + gridOptions.exporterExcelCustomFormatters = gridOptions.exporterExcelCustomFormatters ? gridOptions.exporterExcelCustomFormatters : function( grid, workbook, docDefinition ) { return docDefinition; }; + + /** + * @ngdoc function + * @name exporterExcelHeader + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A function to write formatted header data to sheet. + * + * The method is called to provide custom header building for Excel. This data comes before the grid header + * + * @param {grid} grid provides the grid in case you have need of it + * @param {Workbook} row the row from which the data comes + * @param {Sheet} the sheet to insert data + * @param {docDefinition} The docDefinition that will have styles as a object to store formatters + * @returns {docDefinition} Updated docDefinition with formatter styles + * + * @example + *
    +           *   gridOptions.exporterExcelCustomFormatters = function (grid, workbook, sheet, docDefinition) {
    +           *      const headerFormatter = docDefinition.styles['header'];
    +           *      let cols = [];
    +           *      // push data in A1 cell with metadata formatter
    +           *      cols.push({ value: 'Summary Report', metadata: {style: headerFormatter.id} });
    +           *      sheet.data.push(cols);
    +           *   }
    +           * 
    + */ + gridOptions.exporterExcelHeader = gridOptions.exporterExcelHeader ? gridOptions.exporterExcelHeader : function( grid, workbook, sheet, docDefinition ) { return null; }; + + + /** + * @ngdoc object + * @name exporterColumnScaleFactor + * @propertyOf ui.grid.exporter.api:GridOptions + * @description A scaling factor to divide the drawnwidth of a column to convert to target excel column + * format size + * @example + * In this example we add a number to divide the drawnwidth of a column to get the excel width. + *
    Defaults to 3.5 + */ + gridOptions.exporterColumnScaleFactor = gridOptions.exporterColumnScaleFactor ? gridOptions.exporterColumnScaleFactor : 3.5; + + /** + * @ngdoc object + * @name exporterFieldApplyFilters + * @propertyOf ui.grid.exporter.api:GridOptions + * @description Defaults to false, which leads to filters being evaluated on export * + * + * @example + *
    +           *   gridOptions.exporterFieldApplyFilters = true;
    +           * 
    + */ + gridOptions.exporterFieldApplyFilters = gridOptions.exporterFieldApplyFilters === true; + + /** + * @ngdoc function + * @name exporterAllDataFn + * @propertyOf ui.grid.exporter.api:GridOptions + * @description This promise is needed when exporting all rows, + * and the data need to be provided by server side. Default is null. + * @returns {Promise} a promise to load all data from server + * + * @example + *
    +           *   gridOptions.exporterAllDataFn = function () {
    +           *     return $http.get('/data/100.json')
    +           *   }
    +           * 
    + */ + gridOptions.exporterAllDataFn = gridOptions.exporterAllDataFn ? gridOptions.exporterAllDataFn : null; + + /** + * @ngdoc function + * @name exporterAllDataPromise + * @propertyOf ui.grid.exporter.api:GridOptions + * @description DEPRECATED - exporterAllDataFn used to be + * called this, but it wasn't a promise, it was a function that returned + * a promise. Deprecated, but supported for backward compatibility, use + * exporterAllDataFn instead. + * @returns {Promise} a promise to load all data from server + * + * @example + *
    +           *   gridOptions.exporterAllDataFn = function () {
    +           *     return $http.get('/data/100.json')
    +           *   }
    +           * 
    + */ + if ( gridOptions.exporterAllDataFn === null && gridOptions.exporterAllDataPromise ) { + gridOptions.exporterAllDataFn = gridOptions.exporterAllDataPromise; + } + }, + + + /** + * @ngdoc function + * @name addToMenu + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Adds export items to the grid menu, + * allowing the user to select export options + * @param {Grid} grid the grid from which data should be exported + */ + addToMenu: function ( grid ) { + grid.api.core.addToGridMenu( grid, [ + { + title: i18nService.getSafeText('gridMenu.exporterAllAsCsv'), + action: function () { + grid.api.exporter.csvExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); + }, + shown: function() { + return grid.options.exporterMenuCsv && grid.options.exporterMenuAllData; + }, + order: grid.options.exporterMenuItemOrder + }, + { + title: i18nService.getSafeText('gridMenu.exporterVisibleAsCsv'), + action: function () { + grid.api.exporter.csvExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuCsv && grid.options.exporterMenuVisibleData; + }, + order: grid.options.exporterMenuItemOrder + 1 + }, + { + title: i18nService.getSafeText('gridMenu.exporterSelectedAsCsv'), + action: function () { + grid.api.exporter.csvExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuCsv && grid.options.exporterMenuSelectedData && + ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 ); + }, + order: grid.options.exporterMenuItemOrder + 2 + }, + { + title: i18nService.getSafeText('gridMenu.exporterAllAsPdf'), + action: function () { + grid.api.exporter.pdfExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); + }, + shown: function() { + return grid.options.exporterMenuPdf && grid.options.exporterMenuAllData; + }, + order: grid.options.exporterMenuItemOrder + 3 + }, + { + title: i18nService.getSafeText('gridMenu.exporterVisibleAsPdf'), + action: function () { + grid.api.exporter.pdfExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuPdf && grid.options.exporterMenuVisibleData; + }, + order: grid.options.exporterMenuItemOrder + 4 + }, + { + title: i18nService.getSafeText('gridMenu.exporterSelectedAsPdf'), + action: function () { + grid.api.exporter.pdfExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuPdf && grid.options.exporterMenuSelectedData && + ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 ); + }, + order: grid.options.exporterMenuItemOrder + 5 + }, + { + title: i18nService.getSafeText('gridMenu.exporterAllAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuAllData; + }, + order: grid.options.exporterMenuItemOrder + 6 + }, + { + title: i18nService.getSafeText('gridMenu.exporterVisibleAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuVisibleData; + }, + order: grid.options.exporterMenuItemOrder + 7 + }, + { + title: i18nService.getSafeText('gridMenu.exporterSelectedAsExcel'), + action: function () { + grid.api.exporter.excelExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE ); + }, + shown: function() { + return grid.options.exporterMenuExcel && grid.options.exporterMenuSelectedData && + ( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 ); + }, + order: grid.options.exporterMenuItemOrder + 8 + } + ]); + }, + + + /** + * @ngdoc function + * @name csvExport + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Exports rows from the grid in csv format, + * the data exported is selected based on the provided options + * @param {Grid} grid the grid from which data should be exported + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + */ + csvExport: function (grid, rowTypes, colTypes) { + var self = this; + this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() { + var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : []; + var exportData = self.getData(grid, rowTypes, colTypes); + var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator); + + self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility, grid.options.exporterIsExcelCompatible); + }); + }, + + /** + * @ngdoc function + * @name loadAllDataIfNeeded + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description When using server side pagination, use exporterAllDataFn to + * load all data before continuing processing. + * When using client side pagination, return a resolved promise so processing + * continues immediately + * @param {Grid} grid the grid from which data should be exported + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + */ + loadAllDataIfNeeded: function (grid, rowTypes, colTypes) { + if ( rowTypes === uiGridExporterConstants.ALL && grid.rows.length !== grid.options.totalItems && grid.options.exporterAllDataFn) { + return grid.options.exporterAllDataFn() + .then(function(allData) { + grid.modifyRows(allData); + }); + } else { + var deferred = $q.defer(); + deferred.resolve(); + return deferred.promise; + } + }, + + /** + * @ngdoc property + * @propertyOf ui.grid.exporter.api:ColumnDef + * @name exporterSuppressExport + * @description Suppresses export for this column. Used by selection and expandable. + */ + + /** + * @ngdoc function + * @name getColumnHeaders + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Gets the column headers from the grid to use + * as a title row for the exported file, all headers have + * headerCellFilters applied as appropriate. + * + * Column headers are an array of objects, each object has + * name, displayName, width and align attributes. Only name is + * used for csv, all attributes are used for pdf. + * + * @param {Grid} grid the grid from which data should be exported + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + */ + getColumnHeaders: function (grid, colTypes) { + var headers = [], + columns; + + if ( colTypes === uiGridExporterConstants.ALL ) { + columns = grid.columns; + } else { + var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [], + bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [], + rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ) { return column.visible; } ) : []; + + columns = leftColumns.concat(bodyColumns, rightColumns); + } + + columns.forEach( function( gridCol ) { + // $$hashKey check since when grouping and sorting pragmatically this ends up in export. Filtering it out + if ( gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' && + grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ) { + var headerEntry = { + name: gridCol.field, + displayName: getDisplayName(grid, gridCol), + width: gridCol.drawnWidth ? gridCol.drawnWidth : gridCol.width, + align: gridCol.colDef.align ? gridCol.colDef.align : (gridCol.colDef.type === 'number' ? 'right' : 'left') + }; + + headers.push(headerEntry); + } + }); + + return headers; + }, + + /** + * @ngdoc property + * @propertyOf ui.grid.exporter.api:ColumnDef + * @name exporterPdfAlign + * @description the alignment you'd like for this specific column when + * exported into a pdf. Can be 'left', 'right', 'center' or any other + * valid pdfMake alignment option. + */ + + /** + * @ngdoc object + * @name ui.grid.exporter.api:GridRow + * @description GridRow settings for exporter + */ + + /** + * @ngdoc object + * @name exporterEnableExporting + * @propertyOf ui.grid.exporter.api:GridRow + * @description If set to false, then don't export this row, notwithstanding visible or + * other settings + *
    Defaults to true + */ + + /** + * @ngdoc function + * @name getRowsFromNode + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Gets rows from a node. If the node is grouped it will + * recurse down into the children to get to the raw data element + * which is a row without children (a leaf). + * @param {Node} aNode the tree node on the grid + * @returns {Array} an array with all child nodes from aNode + */ + getRowsFromNode: function(aNode) { + var rows = []; + + // Push parent node if it is not undefined and has values other than 'children' + var nodeKeys = aNode ? Object.keys(aNode) : ['children']; + if (nodeKeys.length > 1 || nodeKeys[0] != 'children') { + rows.push(aNode); + } + + if (aNode && aNode.children && aNode.children.length > 0) { + for (var i = 0; i < aNode.children.length; i++) { + rows = rows.concat(this.getRowsFromNode(aNode.children[i])); + } + } + return rows; + }, + /** + * @ngdoc function + * @name getDataSorted + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Gets rows from a node. If the node is grouped it will + * recurse down into the children to get to the raw data element + * which is a row without children (a leaf). If the grid is not + * grouped this will return just the raw rows + * @param {Grid} grid the grid from which data should be exported + * @returns {Array} an array of leaf nodes + */ + getDataSorted: function (grid) { + if (!grid.treeBase || grid.treeBase.numberLevels === 0) { + return grid.rows; + } + var rows = []; + + for (var i = 0; i< grid.treeBase.tree.length; i++) { + var nodeRows = this.getRowsFromNode(grid.treeBase.tree[i]); + + for (var j = 0; j 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : ''; + + csv += exportData.map(this.formatRowAsCsv(this, separator)).join('\n'); + + return csv; + }, + + /** + * @ngdoc function + * @name formatRowAsCsv + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Renders a single field as a csv field, including + * quotes around the value + * @param {exporterService} exporter pass in exporter + * @param {string} separator the string to be used to join the row data + * @returns {function} A function that returns a csv-ified version of the row + */ + formatRowAsCsv: function (exporter, separator) { + return function (row) { + return row.map(exporter.formatFieldAsCsv).join(separator); + }; + }, + + /** + * @ngdoc function + * @name formatFieldAsCsv + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Renders a single field as a csv field, including + * quotes around the value + * @param {field} field the field to be turned into a csv string, + * may be of any type + * @returns {string} a csv-ified version of the field + */ + formatFieldAsCsv: function (field) { + if (field.value == null) { // we want to catch anything null-ish, hence just == not === + return ''; + } + if (typeof(field.value) === 'number') { + return field.value; + } + if (typeof(field.value) === 'boolean') { + return (field.value ? 'TRUE' : 'FALSE') ; + } + if (typeof(field.value) === 'string') { + return '"' + field.value.replace(/"/g,'""') + '"'; + } + if (typeof(field.value) === 'object' && !(field.value instanceof Date)) { + return '"' + JSON.stringify(field.value).replace(/"/g,'""') + '"'; + } + // if field type is date, numberStr + return JSON.stringify(field.value); + }, + + /** + * @ngdoc function + * @name isIE + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Checks whether current browser is IE and returns it's version if it is + */ + isIE: function () { + var match = navigator.userAgent.search(/(?:Edge|MSIE|Trident\/.*; rv:)/); + var isIE = false; + + if (match !== -1) { + isIE = true; + } + + return isIE; + }, + + + /** + * @ngdoc function + * @name downloadFile + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Triggers download of a csv file. Logic provided + * by @cssensei (from his colleagues at https://github.com/ifeelgoods) in issue #2391 + * @param {string} fileName the filename we'd like our file to be + * given + * @param {string} csvContent the csv content that we'd like to + * download as a file + * @param {string} columnSeparator The separator to be used by the columns + * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF) + * @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X') + */ + downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) { + var D = document, + a = D.createElement('a'), + strMimeType = 'application/octet-stream;charset=utf-8', + rawFile, + ieVersion = this.isIE(); + + if (exporterIsExcelCompatible) { + csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent; + } + + // IE10+ + if (navigator.msSaveBlob) { + return navigator.msSaveOrOpenBlob( + new Blob( + [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent], + { type: strMimeType } ), + fileName + ); + } + + if (ieVersion) { + var frame = D.createElement('iframe'); + + document.body.appendChild(frame); + + frame.contentWindow.document.open('text/html', 'replace'); + frame.contentWindow.document.write(csvContent); + frame.contentWindow.document.close(); + frame.contentWindow.focus(); + frame.contentWindow.document.execCommand('SaveAs', true, fileName); + + document.body.removeChild(frame); + return true; + } + + // html5 A[download] + if ('download' in a) { + var blob = new Blob( + [exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent], + { type: strMimeType } + ); + rawFile = URL.createObjectURL(blob); + a.setAttribute('download', fileName); + } else { + rawFile = 'data: ' + strMimeType + ',' + encodeURIComponent(csvContent); + a.setAttribute('target', '_blank'); + } + + a.href = rawFile; + a.setAttribute('style', 'display:none;'); + D.body.appendChild(a); + setTimeout(function() { + if (a.click) { + a.click(); + // Workaround for Safari 5 + } else if (document.createEvent) { + var eventObj = document.createEvent('MouseEvents'); + eventObj.initEvent('click', true, true); + a.dispatchEvent(eventObj); + } + D.body.removeChild(a); + + }, this.delay); + }, + + /** + * @ngdoc function + * @name pdfExport + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Exports rows from the grid in pdf format, + * the data exported is selected based on the provided options. + * Note that this function has a dependency on pdfMake, which must + * be installed. The resulting pdf opens in a new + * browser window. + * @param {Grid} grid the grid from which data should be exported + * @param {string} rowTypes which rows to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + * @param {string} colTypes which columns to export, valid values are + * uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE, + * uiGridExporterConstants.SELECTED + */ + pdfExport: function (grid, rowTypes, colTypes) { + var self = this; + + this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function () { + var exportColumnHeaders = self.getColumnHeaders(grid, colTypes), + exportData = self.getData(grid, rowTypes, colTypes), + docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData); + + if (self.isIE() || navigator.appVersion.indexOf('Edge') !== -1) { + self.downloadPDF(grid.options.exporterPdfFilename, docDefinition); + } else { + pdfMake.createPdf(docDefinition).open(); + } + }); + }, + + + /** + * @ngdoc function + * @name downloadPdf + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Generates and retrieves the pdf as a blob, then downloads + * it as a file. Only used in IE, in all other browsers we use the native + * pdfMake.open function to just open the PDF + * @param {string} fileName the filename to give to the pdf, can be set + * through exporterPdfFilename + * @param {object} docDefinition a pdf docDefinition that we can generate + * and get a blob from + */ + downloadPDF: function (fileName, docDefinition) { + var D = document, + a = D.createElement('a'), + ieVersion; + + ieVersion = this.isIE(); // This is now a boolean value + var doc = pdfMake.createPdf(docDefinition); + var blob; + + doc.getBuffer( function (buffer) { + blob = new Blob([buffer]); + + // IE10+ + if (navigator.msSaveBlob) { + return navigator.msSaveBlob( + blob, fileName + ); + } + + // Previously: && ieVersion < 10 + // ieVersion now returns a boolean for the + // sake of sanity. We just check `msSaveBlob` first. + if (ieVersion) { + var frame = D.createElement('iframe'); + document.body.appendChild(frame); + + frame.contentWindow.document.open('text/html', 'replace'); + frame.contentWindow.document.write(blob); + frame.contentWindow.document.close(); + frame.contentWindow.focus(); + frame.contentWindow.document.execCommand('SaveAs', true, fileName); + + document.body.removeChild(frame); + return true; + } + }); + }, + + + /** + * @ngdoc function + * @name renderAsPdf + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Renders the data into a pdf, and opens that pdf. + * + * @param {Grid} grid the grid from which data should be exported + * @param {array} exportColumnHeaders an array of column headers, + * where each header is an object with name, width and maybe alignment + * @param {array} exportData an array of rows, where each row is + * an array of column data + * @returns {object} a pdfMake format document definition, ready + * for generation + */ + prepareAsPdf: function(grid, exportColumnHeaders, exportData) { + var headerWidths = this.calculatePdfHeaderWidths( grid, exportColumnHeaders ); + + var headerColumns = exportColumnHeaders.map( function( header ) { + return { text: header.displayName, style: 'tableHeader' }; + }); + + var stringData = exportData.map(this.formatRowAsPdf(this)); + + var allData = [headerColumns].concat(stringData); + + var docDefinition = { + pageOrientation: grid.options.exporterPdfOrientation, + pageSize: grid.options.exporterPdfPageSize, + content: [{ + style: 'tableStyle', + table: { + headerRows: 1, + widths: headerWidths, + body: allData + } + }], + styles: { + tableStyle: grid.options.exporterPdfTableStyle, + tableHeader: grid.options.exporterPdfTableHeaderStyle + }, + defaultStyle: grid.options.exporterPdfDefaultStyle + }; + + if ( grid.options.exporterPdfLayout ) { + docDefinition.layout = grid.options.exporterPdfLayout; + } + + if ( grid.options.exporterPdfHeader ) { + docDefinition.header = grid.options.exporterPdfHeader; + } + + if ( grid.options.exporterPdfFooter ) { + docDefinition.footer = grid.options.exporterPdfFooter; + } + + if ( grid.options.exporterPdfCustomFormatter ) { + docDefinition = grid.options.exporterPdfCustomFormatter( docDefinition ); + } + return docDefinition; + + }, + + + /** + * @ngdoc function + * @name calculatePdfHeaderWidths + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Determines the column widths base on the + * widths we got from the grid. If the column is drawn + * then we have a drawnWidth. If the column is not visible + * then we have '*', 'x%' or a width. When columns are + * not visible they don't contribute to the overall gridWidth, + * so we need to adjust to allow for extra columns + * + * Our basic heuristic is to take the current gridWidth, plus + * numeric columns and call this the base gridwidth. + * + * To that we add 100 for any '*' column, and x% of the base gridWidth + * for any column that is a % + * + * @param {Grid} grid the grid from which data should be exported + * @param {array} exportHeaders array of header information + * @returns {object} an array of header widths + */ + calculatePdfHeaderWidths: function ( grid, exportHeaders ) { + var baseGridWidth = 0; + + exportHeaders.forEach(function(value) { + if (typeof(value.width) === 'number') { + baseGridWidth += value.width; + } + }); + + var extraColumns = 0; + + exportHeaders.forEach(function(value) { + if (value.width === '*') { + extraColumns += 100; + } + if (typeof(value.width) === 'string' && value.width.match(/(\d)*%/)) { + var percent = parseInt(value.width.match(/(\d)*%/)[0]); + + value.width = baseGridWidth * percent / 100; + extraColumns += value.width; + } + }); + + var gridWidth = baseGridWidth + extraColumns; + + return exportHeaders.map(function( header ) { + return header.width === '*' ? header.width : header.width * grid.options.exporterPdfMaxGridWidth / gridWidth; + }); + }, + + /** + * @ngdoc function + * @name formatRowAsPdf + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Renders a row in a format consumable by PDF, + * mainly meaning casting everything to a string + * @param {exporterService} exporter pass in exporter + * @param {array} row the row to be turned into a csv string + * @returns {string} a csv-ified version of the row + */ + formatRowAsPdf: function ( exporter ) { + return function( row ) { + return row.map(exporter.formatFieldAsPdfString); + }; + }, + + + /** + * @ngdoc function + * @name formatFieldAsCsv + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Renders a single field as a pdf-able field, which + * is different from a csv field only in that strings don't have quotes + * around them + * @param {field} field the field to be turned into a pdf string, + * may be of any type + * @returns {string} a string-ified version of the field + */ + formatFieldAsPdfString: function (field) { + var returnVal; + + if (field.value == null) { // we want to catch anything null-ish, hence just == not === + returnVal = ''; + } else if (typeof(field.value) === 'number') { + returnVal = field.value.toString(); + } else if (typeof(field.value) === 'boolean') { + returnVal = (field.value ? 'TRUE' : 'FALSE') ; + } else if (typeof(field.value) === 'string') { + returnVal = field.value.replace(/"/g,'""'); + } else if (field.value instanceof Date) { + returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,''); + } else if (typeof(field.value) === 'object') { + returnVal = field.value; + } else { + returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,''); + } + + if (field.alignment && typeof(field.alignment) === 'string' ) { + returnVal = { text: returnVal, alignment: field.alignment }; + } + + return returnVal; + }, + + /** + * @ngdoc function + * @name formatAsExcel + * @methodOf ui.grid.exporter.service:uiGridExporterService + * @description Formats the column headers and data as a excel, + * and sends that data to the user + * @param {array} exportColumnHeaders an array of column headers, + * where each header is an object with name, width and maybe alignment + * @param {array} exportData an array of rows, where each row is + * an array of column data + * @param {string} separator a string that represents the separator to be used in the csv file + * @returns {string} csv the formatted excel as a string + */ + formatAsExcel: function (exportColumnHeaders, exportData, workbook, sheet, docDefinition) { + var bareHeaders = exportColumnHeaders.map(function(header) {return { value: header.displayName };}); + + var sheetData = []; + var headerData = []; + for (var i = 0; i < bareHeaders.length; i++) { + // TODO - probably need callback to determine header value and header styling + var exportStyle = 'header'; + switch (exportColumnHeaders[i].align) { + case 'center': + exportStyle = 'headerCenter'; + break; + case 'right': + exportStyle = 'headerRight'; + break; + } + var metadata = (docDefinition.styles && docDefinition.styles[exportStyle]) ? {style: docDefinition.styles[exportStyle].id} : null; + headerData.push({value: bareHeaders[i].value, metadata: metadata}); + } + sheetData.push(headerData); + + var result = exportData.map(this.formatRowAsExcel(this, workbook, sheet)); + for (var j = 0; j + + var app = angular.module('app', ['ui.grid', 'ui.grid.exporter']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.gridOptions = { + enableGridMenu: true, + exporterMenuCsv: false, + columnDefs: [ + {name: 'name', enableCellEdit: true}, + {name: 'title', enableCellEdit: true} + ], + data: $scope.data + }; + }]); + + +
    +
    +
    +
    + + */ + module.directive('uiGridExporter', ['uiGridExporterConstants', 'uiGridExporterService', 'gridUtil', '$compile', + function (uiGridExporterConstants, uiGridExporterService, gridUtil, $compile) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridExporterService.initializeGrid(uiGridCtrl.grid); + uiGridCtrl.grid.exporter.$scope = $scope; + } + }; + } + ]); +})(); + +angular.module('ui.grid.exporter').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/csvLink', + "LINK_LABEL" + ); + +}]); diff --git a/src/ui-grid.exporter.min.js b/src/ui-grid.exporter.min.js new file mode 100644 index 0000000000..4561d7fe7c --- /dev/null +++ b/src/ui-grid.exporter.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.exporter",["ui.grid"]);e.constant("uiGridExporterConstants",{featureName:"exporter",rowHeaderColName:"treeBaseRowHeaderCol",selectionRowHeaderColName:"selectionRowHeaderCol",ALL:"all",VISIBLE:"visible",SELECTED:"selected",CSV_CONTENT:"CSV_CONTENT",BUTTON_LABEL:"BUTTON_LABEL",FILE_NAME:"FILE_NAME"}),e.service("uiGridExporterService",["$filter","$q","uiGridExporterConstants","gridUtil","$compile","$interval","i18nService",function(p,n,x,d,e,t,r){var o={delay:100,initializeGrid:function(r){r.exporter={},this.defaultGridOptions(r.options);var e={events:{exporter:{}},methods:{exporter:{csvExport:function(e,t){o.csvExport(r,e,t)},pdfExport:function(e,t){o.pdfExport(r,e,t)},excelExport:function(e,t){o.excelExport(r,e,t)}}}};r.api.registerEventsFromObject(e.events),r.api.registerMethodsFromObject(e.methods),r.api.core.addToGridMenu?o.addToMenu(r):t(function(){r.api.core.addToGridMenu&&o.addToMenu(r)},this.delay,1)},defaultGridOptions:function(e){e.exporterSuppressMenu=!0===e.exporterSuppressMenu,e.exporterMenuLabel=e.exporterMenuLabel?e.exporterMenuLabel:"Export",e.exporterSuppressColumns=e.exporterSuppressColumns?e.exporterSuppressColumns:[],e.exporterCsvColumnSeparator=e.exporterCsvColumnSeparator?e.exporterCsvColumnSeparator:",",e.exporterCsvFilename=e.exporterCsvFilename?e.exporterCsvFilename:"download.csv",e.exporterPdfFilename=e.exporterPdfFilename?e.exporterPdfFilename:"download.pdf",e.exporterExcelFilename=e.exporterExcelFilename?e.exporterExcelFilename:"download.xlsx",e.exporterExcelSheetName=e.exporterExcelSheetName?e.exporterExcelSheetName:"Sheet1",e.exporterOlderExcelCompatibility=!0===e.exporterOlderExcelCompatibility,e.exporterIsExcelCompatible=!0===e.exporterIsExcelCompatible,e.exporterMenuItemOrder=e.exporterMenuItemOrder?e.exporterMenuItemOrder:200,e.exporterPdfDefaultStyle=e.exporterPdfDefaultStyle?e.exporterPdfDefaultStyle:{fontSize:11},e.exporterPdfTableStyle=e.exporterPdfTableStyle?e.exporterPdfTableStyle:{margin:[0,5,0,15]},e.exporterPdfTableHeaderStyle=e.exporterPdfTableHeaderStyle?e.exporterPdfTableHeaderStyle:{bold:!0,fontSize:12,color:"black"},e.exporterPdfHeader=e.exporterPdfHeader?e.exporterPdfHeader:null,e.exporterPdfFooter=e.exporterPdfFooter?e.exporterPdfFooter:null,e.exporterPdfOrientation=e.exporterPdfOrientation?e.exporterPdfOrientation:"landscape",e.exporterPdfPageSize=e.exporterPdfPageSize?e.exporterPdfPageSize:"A4",e.exporterPdfMaxGridWidth=e.exporterPdfMaxGridWidth?e.exporterPdfMaxGridWidth:720,e.exporterMenuAllData=void 0===e.exporterMenuAllData||e.exporterMenuAllData,e.exporterMenuVisibleData=void 0===e.exporterMenuVisibleData||e.exporterMenuVisibleData,e.exporterMenuSelectedData=void 0===e.exporterMenuSelectedData||e.exporterMenuSelectedData,e.exporterMenuCsv=void 0===e.exporterMenuCsv||e.exporterMenuCsv,e.exporterMenuPdf=void 0===e.exporterMenuPdf||e.exporterMenuPdf,e.exporterMenuExcel=void 0===e.exporterMenuExcel||e.exporterMenuExcel,e.exporterPdfCustomFormatter=e.exporterPdfCustomFormatter&&"function"==typeof e.exporterPdfCustomFormatter?e.exporterPdfCustomFormatter:function(e){return e},e.exporterHeaderFilterUseName=!0===e.exporterHeaderFilterUseName,e.exporterFieldCallback=e.exporterFieldCallback?e.exporterFieldCallback:i,e.exporterFieldFormatCallback=e.exporterFieldFormatCallback?e.exporterFieldFormatCallback:function(e,t,r,o){return null},e.exporterExcelCustomFormatters=e.exporterExcelCustomFormatters?e.exporterExcelCustomFormatters:function(e,t,r){return r},e.exporterExcelHeader=e.exporterExcelHeader?e.exporterExcelHeader:function(e,t,r,o){return null},e.exporterColumnScaleFactor=e.exporterColumnScaleFactor?e.exporterColumnScaleFactor:3.5,e.exporterFieldApplyFilters=!0===e.exporterFieldApplyFilters,e.exporterAllDataFn=e.exporterAllDataFn?e.exporterAllDataFn:null,null===e.exporterAllDataFn&&e.exporterAllDataPromise&&(e.exporterAllDataFn=e.exporterAllDataPromise)},addToMenu:function(e){e.api.core.addToGridMenu(e,[{title:r.getSafeText("gridMenu.exporterAllAsCsv"),action:function(){e.api.exporter.csvExport(x.ALL,x.ALL)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuAllData},order:e.options.exporterMenuItemOrder},{title:r.getSafeText("gridMenu.exporterVisibleAsCsv"),action:function(){e.api.exporter.csvExport(x.VISIBLE,x.VISIBLE)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuVisibleData},order:e.options.exporterMenuItemOrder+1},{title:r.getSafeText("gridMenu.exporterSelectedAsCsv"),action:function(){e.api.exporter.csvExport(x.SELECTED,x.VISIBLE)},shown:function(){return e.options.exporterMenuCsv&&e.options.exporterMenuSelectedData&&e.api.selection&&0LINK_LABEL')}]); \ No newline at end of file diff --git a/src/ui-grid.grouping.js b/src/ui-grid.grouping.js new file mode 100644 index 0000000000..cddd600d6b --- /dev/null +++ b/src/ui-grid.grouping.js @@ -0,0 +1,1290 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.grouping + * @description + * + * # ui.grid.grouping + * + * + * + * This module provides grouping of rows based on the data in them, similar + * in concept to excel grouping. You can group multiple columns, resulting in + * nested grouping. + * + * In concept this feature is similar to sorting + grid footer/aggregation, it + * sorts the data based on the grouped columns, then creates group rows that + * reflect a break in the data. Each of those group rows can have aggregations for + * the data within that group. + * + * This feature leverages treeBase to provide the tree functionality itself, + * the key thing this feature does therefore is to set treeLevels on the rows + * and insert the group headers. + * + * Design information: + * ------------------- + * + * Each column will get new menu items - group by, and aggregate by. Group by + * will cause this column to be sorted (if not already), and will move this column + * to the front of the sorted columns (i.e. grouped columns take precedence over + * sorted columns). It will respect the sort order already set if there is one, + * and it will allow the sorting logic to change that sort order, it just forces + * the column to the front of the sorting. You can group by multiple columns, the + * logic will add this column to the sorting after any already grouped columns. + * + * Once a grouping is defined, grouping logic is added to the rowsProcessors. This + * will process the rows, identifying a break in the data value, and inserting a grouping row. + * Grouping rows have specific attributes on them: + * + * - internalRow = true: tells us that this isn't a real row, so we can ignore it + * from any processing that it looking at core data rows. This is used by the core + * logic (or will be one day), as it's not grouping specific + * - groupHeader = true: tells us this is a groupHeader. This is used by the grouping logic + * to know if this is a groupHeader row or not + * + * Since the logic is baked into the rowsProcessors, it should get triggered whenever + * row order or filtering or anything like that is changed. In order to avoid the row instantiation + * time, and to preserve state across invocations, we hold a cache of the rows that we created + * last time, and we use them again this time if we can. + * + * By default rows are collapsed, which means all data rows have their visible property + * set to false, and only level 0 group rows are set to visible. + * + *
    + *
    + * + *
    + */ + + var module = angular.module('ui.grid.grouping', ['ui.grid', 'ui.grid.treeBase']); + + /** + * @ngdoc object + * @name ui.grid.grouping.constant:uiGridGroupingConstants + * + * @description constants available in grouping module, this includes + * all the constants declared in the treeBase module (these are manually copied + * as there isn't an easy way to include constants in another constants file, and + * we don't want to make users include treeBase) + * + */ + module.constant('uiGridGroupingConstants', { + featureName: "grouping", + rowHeaderColName: 'treeBaseRowHeaderCol', + EXPANDED: 'expanded', + COLLAPSED: 'collapsed', + aggregation: { + COUNT: 'count', + SUM: 'sum', + MAX: 'max', + MIN: 'min', + AVG: 'avg' + } + }); + + /** + * @ngdoc service + * @name ui.grid.grouping.service:uiGridGroupingService + * + * @description Services for grouping features + */ + module.service('uiGridGroupingService', ['$q', 'uiGridGroupingConstants', 'gridUtil', 'rowSorter', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'uiGridTreeBaseService', + function ($q, uiGridGroupingConstants, gridUtil, rowSorter, GridRow, gridClassFactory, i18nService, uiGridConstants, uiGridTreeBaseService) { + var service = { + initializeGrid: function (grid, $scope) { + uiGridTreeBaseService.initializeGrid( grid, $scope ); + + // add feature namespace and any properties to grid for needed + /** + * @ngdoc object + * @name ui.grid.grouping.grid:grouping + * + * @description Grid properties and functions added for grouping + */ + grid.grouping = {}; + + /** + * @ngdoc property + * @propertyOf ui.grid.grouping.grid:grouping + * @name groupHeaderCache + * + * @description Cache that holds the group header rows we created last time, we'll + * reuse these next time, not least because they hold our expanded states. + * + * We need to take care with these that they don't become a memory leak, we + * create a new cache each time using the values from the old cache. This works + * so long as we're creating group rows for invisible rows as well. + * + * The cache is a nested hash, indexed on the value we grouped by. So if we + * grouped by gender then age, we'd maybe have something like: + * ``` + * { + * male: { + * row: , + * children: { + * 22: { row: }, + * 31: { row: } + * }, + * female: { + * row: , + * children: { + * 28: { row: }, + * 55: { row: } + * } + * } + * ``` + * + * We create new rows for any missing rows, this means that they come in as collapsed. + * + */ + grid.grouping.groupHeaderCache = {}; + + service.defaultGridOptions(grid.options); + + grid.registerRowsProcessor(service.groupRows, 400); + + grid.registerColumnBuilder( service.groupingColumnBuilder); + + grid.registerColumnsProcessor(service.groupingColumnProcessor, 400); + + /** + * @ngdoc object + * @name ui.grid.grouping.api:PublicApi + * + * @description Public Api for grouping feature + */ + var publicApi = { + events: { + grouping: { + /** + * @ngdoc event + * @eventOf ui.grid.grouping.api:PublicApi + * @name aggregationChanged + * @description raised whenever aggregation is changed, added or removed from a column + * + *
    +               *      gridApi.grouping.on.aggregationChanged(scope,function(col) {})
    +               * 
    + * @param {GridColumn} col the column on which aggregation changed. The aggregation + * type is available as `col.treeAggregation.type` + */ + aggregationChanged: {}, + /** + * @ngdoc event + * @eventOf ui.grid.grouping.api:PublicApi + * @name groupingChanged + * @description raised whenever the grouped columns changes + * + *
    +               *      gridApi.grouping.on.groupingChanged(scope,function(col) {})
    +               * 
    + * @param {GridColumn} col the column on which grouping changed. The new grouping is + * available as `col.grouping` + */ + groupingChanged: {} + } + }, + methods: { + grouping: { + /** + * @ngdoc function + * @name getGrouping + * @methodOf ui.grid.grouping.api:PublicApi + * @description Get the grouping configuration for this grid, + * used by the saveState feature. Adds expandedState to the information + * provided by the internal getGrouping, and removes any aggregations that have a source + * of grouping (i.e. will be automatically reapplied when we regroup the column) + * Returned grouping is an object + * `{ grouping: groupArray, treeAggregations: aggregateArray, expandedState: hash }` + * where grouping contains an array of objects: + * `{ field: column.field, colName: column.name, groupPriority: column.grouping.groupPriority }` + * and aggregations contains an array of objects: + * `{ field: column.field, colName: column.name, aggregation: column.grouping.aggregation }` + * and expandedState is a hash of the currently expanded nodes + * + * The groupArray will be sorted by groupPriority. + * + * @param {boolean} getExpanded whether or not to return the expanded state + * @returns {object} grouping configuration + */ + getGrouping: function ( getExpanded ) { + var grouping = service.getGrouping(grid); + + grouping.grouping.forEach( function( group ) { + group.colName = group.col.name; + delete group.col; + }); + + grouping.aggregations.forEach( function( aggregation ) { + aggregation.colName = aggregation.col.name; + delete aggregation.col; + }); + + grouping.aggregations = grouping.aggregations.filter( function( aggregation ) { + return !aggregation.aggregation.source || aggregation.aggregation.source !== 'grouping'; + }); + + if ( getExpanded ) { + grouping.rowExpandedStates = service.getRowExpandedStates( grid.grouping.groupingHeaderCache ); + } + + return grouping; + }, + + /** + * @ngdoc function + * @name setGrouping + * @methodOf ui.grid.grouping.api:PublicApi + * @description Set the grouping configuration for this grid, + * used by the saveState feature, but can also be used by any + * user to specify a combined grouping and aggregation configuration + * @param {object} config the config you want to apply, in the format + * provided out by getGrouping + */ + setGrouping: function ( config ) { + service.setGrouping(grid, config); + }, + + /** + * @ngdoc function + * @name groupColumn + * @methodOf ui.grid.grouping.api:PublicApi + * @description Adds this column to the existing grouping, at the end of the priority order. + * If the column doesn't have a sort, adds one, by default ASC + * + * This column will move to the left of any non-group columns, the + * move is handled in a columnProcessor, so gets called as part of refresh + * + * @param {string} columnName the name of the column we want to group + */ + groupColumn: function(columnName) { + var column = grid.getColumn(columnName); + + service.groupColumn(grid, column); + }, + + /** + * @ngdoc function + * @name ungroupColumn + * @methodOf ui.grid.grouping.api:PublicApi + * @description Removes the groupPriority from this column. If the + * column was previously aggregated the aggregation will come back. + * The sort will remain. + * + * This column will move to the right of any other group columns, the + * move is handled in a columnProcessor, so gets called as part of refresh + * + * @param {string} columnName the name of the column we want to ungroup + */ + ungroupColumn: function(columnName) { + var column = grid.getColumn(columnName); + + service.ungroupColumn(grid, column); + }, + + /** + * @ngdoc function + * @name clearGrouping + * @methodOf ui.grid.grouping.api:PublicApi + * @description Clear any grouped columns and any aggregations. Doesn't remove sorting, + * as we don't know whether that sorting was added by grouping or was there beforehand + * + */ + clearGrouping: function() { + service.clearGrouping(grid); + }, + + /** + * @ngdoc function + * @name aggregateColumn + * @methodOf ui.grid.grouping.api:PublicApi + * @description Sets the aggregation type on a column, if the + * column is currently grouped then it removes the grouping first. + * If the aggregationDef is null then will result in the aggregation + * being removed + * + * @param {string} columnName the column we want to aggregate + * @param {string|function} aggregationDef one of the recognised types + * from uiGridGroupingConstants or a custom aggregation function. + * @param {string} aggregationLabel (optional) The label to use for this aggregation. + */ + aggregateColumn: function(columnName, aggregationDef, aggregationLabel) { + var column = grid.getColumn(columnName); + + service.aggregateColumn(grid, column, aggregationDef, aggregationLabel); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + + grid.api.core.on.sortChanged($scope, service.tidyPriorities); + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.grouping.api:GridOptions + * + * @description GridOptions for grouping feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enableGrouping + * @propertyOf ui.grid.grouping.api:GridOptions + * @description Enable row grouping for entire grid. + *
    Defaults to true + */ + gridOptions.enableGrouping = gridOptions.enableGrouping !== false; + + /** + * @ngdoc object + * @name groupingShowCounts + * @propertyOf ui.grid.grouping.api:GridOptions + * @description shows counts on the groupHeader rows. Not that if you are using a cellFilter or a + * sortingAlgorithm which relies on a specific format or data type, showing counts may cause that + * to break, since the group header rows will always be a string with groupingShowCounts enabled. + *
    Defaults to true except on columns of types 'date' and 'object' + */ + gridOptions.groupingShowCounts = gridOptions.groupingShowCounts !== false; + + /** + * @ngdoc object + * @name groupingNullLabel + * @propertyOf ui.grid.grouping.api:GridOptions + * @description The string to use for the grouping header row label on rows which contain a null or undefined value in the grouped column. + *
    Defaults to "Null" + */ + gridOptions.groupingNullLabel = typeof(gridOptions.groupingNullLabel) === 'undefined' ? 'Null' : gridOptions.groupingNullLabel; + + /** + * @ngdoc object + * @name enableGroupHeaderSelection + * @propertyOf ui.grid.grouping.api:GridOptions + * @description Allows group header rows to be selected. + *
    Defaults to false + */ + gridOptions.enableGroupHeaderSelection = gridOptions.enableGroupHeaderSelection === true; + }, + + + /** + * @ngdoc function + * @name groupingColumnBuilder + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Sets the grouping defaults based on the columnDefs + * + * @param {object} colDef columnDef we're basing on + * @param {GridColumn} col the column we're to update + * @param {object} gridOptions the options we should use + * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved + */ + groupingColumnBuilder: function (colDef, col, gridOptions) { + /** + * @ngdoc object + * @name ui.grid.grouping.api:ColumnDef + * + * @description ColumnDef for grouping feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name enableGrouping + * @propertyOf ui.grid.grouping.api:ColumnDef + * @description Enable grouping on this column + *
    Defaults to true. + */ + if (colDef.enableGrouping === false) { + return; + } + + /** + * @ngdoc object + * @name grouping + * @propertyOf ui.grid.grouping.api:ColumnDef + * @description Set the grouping for a column. Format is: + * ``` + * { + * groupPriority: + * } + * ``` + * + * **Note that aggregation used to be included in grouping, but is now separately set on the column via treeAggregation + * setting in treeBase** + * + * We group in the priority order given, this will also put these columns to the high order of the sort irrespective + * of the sort priority given them. If there is no sort defined then we sort ascending, if there is a sort defined then + * we use that sort. + * + * If the groupPriority is undefined or less than 0, then we expect to be aggregating, and we look at the + * aggregation types to determine what sort of aggregation we can do. Values are in the constants file, but + * include SUM, COUNT, MAX, MIN + * + * groupPriorities should generally be sequential, if they're not then the next time getGrouping is called + * we'll renumber them to be sequential. + *
    Defaults to undefined. + */ + + if ( typeof(col.grouping) === 'undefined' && typeof(colDef.grouping) !== 'undefined') { + col.grouping = angular.copy(colDef.grouping); + if ( typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority > -1 ) { + col.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn; + col.treeAggregationFinalizerFn = service.groupedFinalizerFn; + } + } else if (typeof(col.grouping) === 'undefined') { + col.grouping = {}; + } + + if (typeof(col.grouping) !== 'undefined' && typeof(col.grouping.groupPriority) !== 'undefined' && col.grouping.groupPriority >= 0) { + col.suppressRemoveSort = true; + } + + var groupColumn = { + name: 'ui.grid.grouping.group', + title: i18nService.get().grouping.group, + icon: 'ui-grid-icon-indent-right', + shown: function () { + return typeof(this.context.col.grouping) === 'undefined' || + typeof(this.context.col.grouping.groupPriority) === 'undefined' || + this.context.col.grouping.groupPriority < 0; + }, + action: function () { + service.groupColumn( this.context.col.grid, this.context.col ); + } + }; + + var ungroupColumn = { + name: 'ui.grid.grouping.ungroup', + title: i18nService.get().grouping.ungroup, + icon: 'ui-grid-icon-indent-left', + shown: function () { + return typeof(this.context.col.grouping) !== 'undefined' && + typeof(this.context.col.grouping.groupPriority) !== 'undefined' && + this.context.col.grouping.groupPriority >= 0; + }, + action: function () { + service.ungroupColumn( this.context.col.grid, this.context.col ); + } + }; + + var aggregateRemove = { + name: 'ui.grid.grouping.aggregateRemove', + title: i18nService.get().grouping.aggregate_remove, + shown: function () { + return typeof(this.context.col.treeAggregationFn) !== 'undefined'; + }, + action: function () { + service.aggregateColumn( this.context.col.grid, this.context.col, null); + } + }; + + // generic adder for the aggregation menus, which follow a pattern + var addAggregationMenu = function(type, title) { + title = title || i18nService.get().grouping['aggregate_' + type] || type; + var menuItem = { + name: 'ui.grid.grouping.aggregate' + type, + title: title, + shown: function () { + return typeof(this.context.col.treeAggregation) === 'undefined' || + typeof(this.context.col.treeAggregation.type) === 'undefined' || + this.context.col.treeAggregation.type !== type; + }, + action: function () { + service.aggregateColumn( this.context.col.grid, this.context.col, type); + } + }; + + if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregate' + type)) { + col.menuItems.push(menuItem); + } + }; + + /** + * @ngdoc object + * @name groupingShowGroupingMenu + * @propertyOf ui.grid.grouping.api:ColumnDef + * @description Show the grouping (group and ungroup items) menu on this column + *
    Defaults to true. + */ + if ( col.colDef.groupingShowGroupingMenu !== false ) { + if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.group')) { + col.menuItems.push(groupColumn); + } + + if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.ungroup')) { + col.menuItems.push(ungroupColumn); + } + } + + + /** + * @ngdoc object + * @name groupingShowAggregationMenu + * @propertyOf ui.grid.grouping.api:ColumnDef + * @description Show the aggregation menu on this column + *
    Defaults to true. + */ + if ( col.colDef.groupingShowAggregationMenu !== false ) { + angular.forEach(uiGridTreeBaseService.nativeAggregations(), function(aggregationDef, name) { + addAggregationMenu(name); + }); + angular.forEach(gridOptions.treeCustomAggregations, function(aggregationDef, name) { + addAggregationMenu(name, aggregationDef.menuTitle); + }); + + if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.grouping.aggregateRemove')) { + col.menuItems.push(aggregateRemove); + } + } + }, + + + + + /** + * @ngdoc function + * @name groupingColumnProcessor + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Moves the columns around based on which are grouped + * + * @param {array} columns the columns to consider rendering + * @param {array} rows the grid rows, which we don't use but are passed to us + * @returns {array} updated columns array + */ + groupingColumnProcessor: function( columns, rows ) { + columns = service.moveGroupColumns(this, columns, rows); + return columns; + }, + + /** + * @ngdoc function + * @name groupedFinalizerFn + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Used on group columns to display the rendered value and optionally + * display the count of rows. + * + * @param {aggregation} aggregation The aggregation entity for a grouped column + */ + groupedFinalizerFn: function( aggregation ) { + var col = this; + + if ( typeof(aggregation.groupVal) !== 'undefined') { + aggregation.rendered = aggregation.groupVal; + if ( col.grid.options.groupingShowCounts && col.colDef.type !== 'date' && col.colDef.type !== 'object' ) { + aggregation.rendered += (' (' + aggregation.value + ')'); + } + } else { + aggregation.rendered = null; + } + }, + + /** + * @ngdoc function + * @name moveGroupColumns + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Moves the column order so that the grouped columns are lined up + * to the left (well, unless you're RTL, then it's the right). By doing this in + * the columnsProcessor, we make it transient - when the column is ungrouped it'll + * go back to where it was. + * + * Does nothing if the option `moveGroupColumns` is set to false. + * + * @param {Grid} grid grid object + * @param {array} columns the columns that we should process/move + * @returns {array} updated columns + */ + moveGroupColumns: function( grid, columns ) { + if ( grid.options.moveGroupColumns === false) { + return columns; + } + + columns.forEach(function(column, index) { + // position used to make stable sort in moveGroupColumns + column.groupingPosition = index; + }); + + columns.sort(function(a, b) { + var a_group, b_group; + + if (a.isRowHeader) { + a_group = a.headerPriority; + } + else if ( typeof(a.grouping) === 'undefined' || typeof(a.grouping.groupPriority) === 'undefined' || a.grouping.groupPriority < 0) { + a_group = null; + } + else { + a_group = a.grouping.groupPriority; + } + + if (b.isRowHeader) { + b_group = b.headerPriority; + } + else if ( typeof(b.grouping) === 'undefined' || typeof(b.grouping.groupPriority) === 'undefined' || b.grouping.groupPriority < 0) { + b_group = null; + } + else { + b_group = b.grouping.groupPriority; + } + + // groups get sorted to the top + if ( a_group !== null && b_group === null) { return -1; } + if ( b_group !== null && a_group === null) { return 1; } + if ( a_group !== null && b_group !== null) {return a_group - b_group; } + + return a.groupingPosition - b.groupingPosition; + }); + + columns.forEach( function(column) { + delete column.groupingPosition; + }); + + return columns; + }, + + + /** + * @ngdoc function + * @name groupColumn + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Adds this column to the existing grouping, at the end of the priority order. + * If the column doesn't have a sort, adds one, by default ASC + * + * This column will move to the left of any non-group columns, the + * move is handled in a columnProcessor, so gets called as part of refresh + * + * @param {Grid} grid grid object + * @param {GridColumn} column the column we want to group + */ + groupColumn: function( grid, column) { + if ( typeof(column.grouping) === 'undefined' ) { + column.grouping = {}; + } + + // set the group priority to the next number in the hierarchy + var existingGrouping = service.getGrouping( grid ); + column.grouping.groupPriority = existingGrouping.grouping.length; + + // save sort in order to restore it when column is ungrouped + column.previousSort = angular.copy(column.sort); + + // add sort if not present + if ( !column.sort ) { + column.sort = { direction: uiGridConstants.ASC }; + } else if ( typeof(column.sort.direction) === 'undefined' || column.sort.direction === null ) { + column.sort.direction = uiGridConstants.ASC; + } + + column.treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT, source: 'grouping' }; + + if ( column.colDef && angular.isFunction(column.colDef.customTreeAggregationFn) ) { + column.treeAggregationFn = column.colDef.customTreeAggregationFn; + } else { + column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn; + } + + column.treeAggregationFinalizerFn = service.groupedFinalizerFn; + + grid.api.grouping.raise.groupingChanged(column); + // This indirectly calls service.tidyPriorities( grid ); + grid.api.core.raise.sortChanged(grid, grid.getColumnSorting()); + + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name ungroupColumn + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Removes the groupPriority from this column. If the + * column was previously aggregated the aggregation will come back. + * The sort will remain. + * + * This column will move to the right of any other group columns, the + * move is handled in a columnProcessor, so gets called as part of refresh + * + * @param {Grid} grid grid object + * @param {GridColumn} column the column we want to ungroup + */ + ungroupColumn: function( grid, column) { + if ( typeof(column.grouping) === 'undefined' ) { + return; + } + + delete column.grouping.groupPriority; + delete column.treeAggregation; + delete column.customTreeAggregationFinalizer; + + if (column.previousSort) { + column.sort = column.previousSort; + delete column.previousSort; + } + + service.tidyPriorities( grid ); + + grid.api.grouping.raise.groupingChanged(column); + grid.api.core.raise.sortChanged(grid, grid.getColumnSorting()); + + grid.queueGridRefresh(); + }, + + /** + * @ngdoc function + * @name aggregateColumn + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Sets the aggregation type on a column, if the + * column is currently grouped then it removes the grouping first. + * + * @param {Grid} grid grid object + * @param {GridColumn} column the column we want to aggregate + * @param {string} aggregationType of the recognised types from uiGridGroupingConstants or one of the custom aggregations from gridOptions + * @param {string} aggregationLabel to be used instead of the default label. If empty string is passed, label is omitted + */ + aggregateColumn: function( grid, column, aggregationType, aggregationLabel ) { + if (typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { + service.ungroupColumn( grid, column ); + } + + var aggregationDef = {}; + + if ( typeof(grid.options.treeCustomAggregations[aggregationType]) !== 'undefined' ) { + aggregationDef = grid.options.treeCustomAggregations[aggregationType]; + } else if ( typeof(uiGridTreeBaseService.nativeAggregations()[aggregationType]) !== 'undefined' ) { + aggregationDef = uiGridTreeBaseService.nativeAggregations()[aggregationType]; + } + + column.treeAggregation = { + type: aggregationType, + label: ( typeof aggregationLabel === 'string') ? + aggregationLabel : + i18nService.get().aggregation[aggregationDef.label] || aggregationDef.label + }; + column.treeAggregationFn = aggregationDef.aggregationFn; + column.treeAggregationFinalizerFn = aggregationDef.finalizerFn; + + grid.api.grouping.raise.aggregationChanged(column); + + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name setGrouping + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Set the grouping based on a config object, used by the save state feature + * (more specifically, by the restore function in that feature ) + * + * @param {Grid} grid grid object + * @param {object} config the config we want to set, same format as that returned by getGrouping + */ + setGrouping: function ( grid, config ) { + if ( typeof(config) === 'undefined' ) { + return; + } + + // first remove any existing grouping + service.clearGrouping(grid); + + if ( config.grouping && config.grouping.length && config.grouping.length > 0 ) { + config.grouping.forEach( function( group ) { + var col = grid.getColumn(group.colName); + + if ( col ) { + service.groupColumn( grid, col ); + } + }); + } + + if ( config.aggregations && config.aggregations.length ) { + config.aggregations.forEach( function( aggregation ) { + var col = grid.getColumn(aggregation.colName); + + if ( col ) { + service.aggregateColumn( grid, col, aggregation.aggregation.type ); + } + }); + } + + if ( config.rowExpandedStates ) { + service.applyRowExpandedStates( grid.grouping.groupingHeaderCache, config.rowExpandedStates ); + } + }, + + + /** + * @ngdoc function + * @name clearGrouping + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Clear any grouped columns and any aggregations. Doesn't remove sorting, + * as we don't know whether that sorting was added by grouping or was there beforehand + * + * @param {Grid} grid grid object + */ + clearGrouping: function( grid ) { + var currentGrouping = service.getGrouping(grid); + + if ( currentGrouping.grouping.length > 0 ) { + currentGrouping.grouping.forEach( function( group ) { + if (!group.col) { + // should have a group.colName if there's no col + group.col = grid.getColumn(group.colName); + } + service.ungroupColumn(grid, group.col); + }); + } + + if ( currentGrouping.aggregations.length > 0 ) { + currentGrouping.aggregations.forEach( function( aggregation ) { + if (!aggregation.col) { + // should have a group.colName if there's no col + aggregation.col = grid.getColumn(aggregation.colName); + } + service.aggregateColumn(grid, aggregation.col, null); + }); + } + }, + + + /** + * @ngdoc function + * @name tidyPriorities + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Renumbers groupPriority and sortPriority such that + * groupPriority is contiguous, and sortPriority either matches + * groupPriority (for group columns), and otherwise is contiguous and + * higher than groupPriority. + * + * @param {Grid} grid grid object + */ + tidyPriorities: function( grid ) { + // if we're called from sortChanged, grid is in this, not passed as param, the param can be a column or undefined + if ( ( typeof(grid) === 'undefined' || typeof(grid.grid) !== 'undefined' ) && typeof(this.grid) !== 'undefined' ) { + grid = this.grid; + } + + var groupArray = [], + sortArray = []; + + grid.columns.forEach( function(column, index) { + if ( typeof(column.grouping) !== 'undefined' && typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { + groupArray.push(column); + } + else if ( typeof(column.sort) !== 'undefined' && typeof(column.sort.priority) !== 'undefined' && column.sort.priority >= 0) { + sortArray.push(column); + } + }); + + groupArray.sort(function(a, b) { return a.grouping.groupPriority - b.grouping.groupPriority; }); + groupArray.forEach( function(column, index) { + column.grouping.groupPriority = index; + column.suppressRemoveSort = true; + if ( typeof(column.sort) === 'undefined') { + column.sort = {}; + } + column.sort.priority = index; + }); + + var i = groupArray.length; + + sortArray.sort(function(a, b) { return a.sort.priority - b.sort.priority; }); + sortArray.forEach(function(column) { + column.sort.priority = i; + column.suppressRemoveSort = column.colDef.suppressRemoveSort; + i++; + }); + }, + + /** + * @ngdoc function + * @name groupRows + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description The rowProcessor that creates the groupHeaders (i.e. does + * the actual grouping). + * + * Assumes it is always called after the sorting processor, guaranteed by the priority setting + * + * Processes all the rows in order, inserting a groupHeader row whenever there is a change + * in value of a grouped row, based on the sortAlgorithm used for the column. The group header row + * is looked up in the groupHeaderCache, and used from there if there is one. The entity is reset + * to {} if one is found. + * + * As it processes it maintains a `processingState` array. This records, for each level of grouping we're + * working with, the following information: + * ``` + * { + * fieldName: name, + * col: col, + * initialised: boolean, + * currentValue: value, + * currentRow: gridRow, + * } + * ``` + * We look for changes in the currentValue at any of the levels. Where we find a change we: + * + * - create a new groupHeader row in the array + * + * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor + * @returns {array} the updated rows, including our new group rows + */ + groupRows: function( renderableRows ) { + if (renderableRows.length === 0) { + return renderableRows; + } + + var grid = this; + grid.grouping.oldGroupingHeaderCache = grid.grouping.groupingHeaderCache || {}; + grid.grouping.groupingHeaderCache = {}; + + var processingState = service.initialiseProcessingState( grid ); + + // processes each of the fields we are grouping by, checks if the value has changed and inserts a groupHeader + // Broken out as shouldn't create functions in a loop. + var updateProcessingState = function( groupFieldState, stateIndex ) { + var fieldValue = grid.getCellValue(row, groupFieldState.col); + + // look for change of value - and insert a header + if ( !groupFieldState.initialised || rowSorter.getSortFn(grid, groupFieldState.col, renderableRows)(fieldValue, groupFieldState.currentValue) !== 0 ) { + service.insertGroupHeader( grid, renderableRows, i, processingState, stateIndex ); + i++; + } + }; + + // use a for loop because it's tolerant of the array length changing whilst we go - we can + // manipulate the iterator when we insert groupHeader rows + for (var i = 0; i < renderableRows.length; i++ ) { + var row = renderableRows[i]; + + if ( row.visible ) { + processingState.forEach( updateProcessingState ); + } + } + + delete grid.grouping.oldGroupingHeaderCache; + return renderableRows; + }, + + + /** + * @ngdoc function + * @name initialiseProcessingState + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Creates the processing state array that is used + * for groupRows. + * + * @param {Grid} grid grid object + * @returns {array} an array in the format described in the groupRows method, + * initialised with blank values + */ + initialiseProcessingState: function( grid ) { + var processingState = []; + var columnSettings = service.getGrouping( grid ); + + columnSettings.grouping.forEach( function( groupItem, index) { + processingState.push({ + fieldName: groupItem.field, + col: groupItem.col, + initialised: false, + currentValue: null, + currentRow: null + }); + }); + + return processingState; + }, + + + /** + * @ngdoc function + * @name getGrouping + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Get the grouping settings from the columns. As a side effect + * this always renumbers the grouping starting at 0 + * @param {Grid} grid grid object + * @returns {array} an array of the group fields, in order of priority + */ + getGrouping: function( grid ) { + var groupArray = [], + aggregateArray = []; + + // get all the grouping + grid.columns.forEach(function(column) { + if ( column.grouping ) { + if ( typeof(column.grouping.groupPriority) !== 'undefined' && column.grouping.groupPriority >= 0) { + groupArray.push({ field: column.field, col: column, groupPriority: column.grouping.groupPriority, grouping: column.grouping }); + } + } + if ( column.treeAggregation && column.treeAggregation.type ) { + aggregateArray.push({ field: column.field, col: column, aggregation: column.treeAggregation }); + } + }); + + // sort grouping into priority order + groupArray.sort( function(a, b) { + return a.groupPriority - b.groupPriority; + }); + + // renumber the priority in case it was somewhat messed up, then remove the grouping reference + groupArray.forEach( function( group, index) { + group.grouping.groupPriority = index; + group.groupPriority = index; + delete group.grouping; + }); + + return { grouping: groupArray, aggregations: aggregateArray }; + }, + + + /** + * @ngdoc function + * @name insertGroupHeader + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Create a group header row, and link it to the various configuration + * items that we use. + * + * Look for the row in the oldGroupingHeaderCache, write the row into the new groupingHeaderCache. + * + * @param {Grid} grid grid object + * @param {array} renderableRows the rows that we are processing + * @param {number} rowIndex the row we were up to processing + * @param {array} processingState the current processing state + * @param {number} stateIndex the processing state item that we were on when we triggered a new group header - + * i.e. the column that we want to create a header for + */ + insertGroupHeader: function( grid, renderableRows, rowIndex, processingState, stateIndex ) { + // set the value that caused the end of a group into the header row and the processing state + var col = processingState[stateIndex].col, + newValue = grid.getCellValue(renderableRows[rowIndex], col), + newDisplayValue = newValue; + + if ( typeof(newValue) === 'undefined' || newValue === null ) { + newDisplayValue = grid.options.groupingNullLabel; + } + + function getKeyAsValueForCacheMap(key) { + return angular.isObject(key) ? JSON.stringify(key) : key; + } + + var cacheItem = grid.grouping.oldGroupingHeaderCache; + + for ( var i = 0; i < stateIndex; i++ ) { + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ) { + cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; + } + } + + var headerRow; + + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]) { + headerRow = cacheItem[getKeyAsValueForCacheMap(newValue)].row; + headerRow.entity = {}; + } else { + headerRow = new GridRow( {}, null, grid ); + gridClassFactory.rowTemplateAssigner.call(grid, headerRow); + } + + headerRow.entity['$$' + processingState[stateIndex].col.uid] = { groupVal: newDisplayValue }; + headerRow.treeLevel = stateIndex; + headerRow.groupHeader = true; + headerRow.internalRow = true; + headerRow.enableCellEdit = false; + headerRow.enableSelection = grid.options.enableGroupHeaderSelection; + processingState[stateIndex].initialised = true; + processingState[stateIndex].currentValue = newValue; + processingState[stateIndex].currentRow = headerRow; + + // set all processing states below this one to not be initialised - change of this state + // means all those need to start again + service.finaliseProcessingState( processingState, stateIndex + 1); + + // insert our new header row + renderableRows.splice(rowIndex, 0, headerRow); + + // add our new header row to the cache + cacheItem = grid.grouping.groupingHeaderCache; + for ( i = 0; i < stateIndex; i++ ) { + cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; + } + cacheItem[getKeyAsValueForCacheMap(newValue)] = { row: headerRow, children: {} }; + }, + + + /** + * @ngdoc function + * @name finaliseProcessingState + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Set all processing states lower than the one that had a break in value to + * no longer be initialised. Render the counts into the entity ready for display. + * + * @param {array} processingState the current processing state + * @param {number} stateIndex the processing state item that we were on when we triggered a new group header, all + * processing states after this need to be finalised + */ + finaliseProcessingState: function( processingState, stateIndex ) { + for ( var i = stateIndex; i < processingState.length; i++) { + processingState[i].initialised = false; + processingState[i].currentRow = null; + processingState[i].currentValue = null; + } + }, + + + /** + * @ngdoc function + * @name getRowExpandedStates + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Extract the groupHeaderCache hash, pulling out only the states. + * + * The example below shows a grid that is grouped by gender then age + * + *
    +       *   {
    +       *     male: {
    +       *       state: 'expanded',
    +       *       children: {
    +       *         22: { state: 'expanded' },
    +       *         30: { state: 'collapsed' }
    +       *       }
    +       *     },
    +       *     female: {
    +       *       state: 'expanded',
    +       *       children: {
    +       *         28: { state: 'expanded' },
    +       *         55: { state: 'collapsed' }
    +       *       }
    +       *     }
    +       *   }
    +       * 
    + * + * @param {object} treeChildren The tree children elements object + * @returns {object} the expanded states as an object + */ + getRowExpandedStates: function(treeChildren) { + if ( typeof(treeChildren) === 'undefined' ) { + return {}; + } + + var newChildren = {}; + + angular.forEach( treeChildren, function( value, key ) { + newChildren[key] = { state: value.row.treeNode.state }; + if ( value.children ) { + newChildren[key].children = service.getRowExpandedStates( value.children ); + } else { + newChildren[key].children = {}; + } + }); + + return newChildren; + }, + + + /** + * @ngdoc function + * @name applyRowExpandedStates + * @methodOf ui.grid.grouping.service:uiGridGroupingService + * @description Take a hash in the format as created by getRowExpandedStates, + * and apply it to the grid.grouping.groupHeaderCache. + * + * Takes a treeSubset, and applies to a treeSubset - so can be called + * recursively. + * + * @param {object} currentNode can be grid.grouping.groupHeaderCache, or any of + * the children of that hash + * @param {object} expandedStates can be the full expanded states, or children + * of that expanded states (which hopefully matches the subset of the groupHeaderCache) + */ + applyRowExpandedStates: function( currentNode, expandedStates ) { + if ( typeof(expandedStates) === 'undefined' ) { + return; + } + + angular.forEach(expandedStates, function( value, key ) { + if ( currentNode[key] ) { + currentNode[key].row.treeNode.state = value.state; + + if (value.children && currentNode[key].children) { + service.applyRowExpandedStates( currentNode[key].children, value.children ); + } + } + }); + } + + + }; + + return service; + + }]); + + + /** + * @ngdoc directive + * @name ui.grid.grouping.directive:uiGridGrouping + * @element div + * @restrict A + * + * @description Adds grouping features to grid + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.grouping']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name', enableCellEdit: true}, + {name: 'title', enableCellEdit: true} + ]; + + $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data }; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridGrouping', ['uiGridGroupingConstants', 'uiGridGroupingService', + function (uiGridGroupingConstants, uiGridGroupingService) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + if (uiGridCtrl.grid.options.enableGrouping !== false) { + uiGridGroupingService.initializeGrid(uiGridCtrl.grid, $scope); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + +})(); diff --git a/src/ui-grid.grouping.min.js b/src/ui-grid.grouping.min.js new file mode 100644 index 0000000000..9f4c30aecd --- /dev/null +++ b/src/ui-grid.grouping.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var r=angular.module("ui.grid.grouping",["ui.grid","ui.grid.treeBase"]);r.constant("uiGridGroupingConstants",{featureName:"grouping",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),r.service("uiGridGroupingService",["$q","uiGridGroupingConstants","gridUtil","rowSorter","GridRow","gridClassFactory","i18nService","uiGridConstants","uiGridTreeBaseService",function(r,u,a,p,s,d,l,e,c){var f={initializeGrid:function(n,r){c.initializeGrid(n,r),n.grouping={},n.grouping.groupHeaderCache={},f.defaultGridOptions(n.options),n.registerRowsProcessor(f.groupRows,400),n.registerColumnBuilder(f.groupingColumnBuilder),n.registerColumnsProcessor(f.groupingColumnProcessor,400);var o={events:{grouping:{aggregationChanged:{},groupingChanged:{}}},methods:{grouping:{getGrouping:function(r){var o=f.getGrouping(n);return o.grouping.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations=o.aggregations.filter(function(r){return!r.aggregation.source||"grouping"!==r.aggregation.source}),r&&(o.rowExpandedStates=f.getRowExpandedStates(n.grouping.groupingHeaderCache)),o},setGrouping:function(r){f.setGrouping(n,r)},groupColumn:function(r){var o=n.getColumn(r);f.groupColumn(n,o)},ungroupColumn:function(r){var o=n.getColumn(r);f.ungroupColumn(n,o)},clearGrouping:function(){f.clearGrouping(n)},aggregateColumn:function(r,o,i){var e=n.getColumn(r);f.aggregateColumn(n,e,o,i)}}}};n.api.registerEventsFromObject(o.events),n.api.registerMethodsFromObject(o.methods),n.api.core.on.sortChanged(r,f.tidyPriorities)},defaultGridOptions:function(r){r.enableGrouping=!1!==r.enableGrouping,r.groupingShowCounts=!1!==r.groupingShowCounts,r.groupingNullLabel=void 0===r.groupingNullLabel?"Null":r.groupingNullLabel,r.enableGroupHeaderSelection=!0===r.enableGroupHeaderSelection},groupingColumnBuilder:function(r,e,o){if(!1!==r.enableGrouping){void 0===e.grouping&&void 0!==r.grouping?(e.grouping=angular.copy(r.grouping),void 0!==e.grouping.groupPriority&&-1Stable This feature is stable. There should no longer be breaking api changes without a deprecation warning. + * + * This module provides the ability to import data into the grid. It + * uses the column defs to work out which data belongs in which column, + * and creates entities from a configured class (typically a $resource). + * + * If the rowEdit feature is enabled, it also calls save on those newly + * created objects, and then displays any errors in the imported data. + * + * Currently the importer imports only CSV and json files, although provision has been + * made to process other file formats, and these can be added over time. + * + * For json files, the properties within each object in the json must match the column names + * (to put it another way, the importer doesn't process the json, it just copies the objects + * within the json into a new instance of the specified object type) + * + * For CSV import, the default column identification relies on each column in the + * header row matching a column.name or column.displayName. Optionally, a column identification + * callback can be used. This allows matching using other attributes, which is particularly + * useful if your application has internationalised column headings (i.e. the headings that + * the user sees don't match the column names). + * + * The importer makes use of the grid menu as the UI for requesting an + * import. + * + *
    + */ + + var module = angular.module('ui.grid.importer', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.importer.constant:uiGridImporterConstants + * + * @description constants available in importer module + */ + + module.constant('uiGridImporterConstants', { + featureName: 'importer' + }); + + /** + * @ngdoc service + * @name ui.grid.importer.service:uiGridImporterService + * + * @description Services for importer feature + */ + module.service('uiGridImporterService', ['$q', 'uiGridConstants', 'uiGridImporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', '$window', + function ($q, uiGridConstants, uiGridImporterConstants, gridUtil, $compile, $interval, i18nService, $window) { + + var service = { + + initializeGrid: function ($scope, grid) { + + // add feature namespace and any properties to grid for needed state + grid.importer = { + $scope: $scope + }; + + this.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.importer.api:PublicApi + * + * @description Public Api for importer feature + */ + var publicApi = { + events: { + importer: { + } + }, + methods: { + importer: { + /** + * @ngdoc function + * @name importFile + * @methodOf ui.grid.importer.api:PublicApi + * @description Imports a file into the grid using the file object + * provided. Bypasses the grid menu + * @param {File} fileObject the file we want to import, as a javascript + * File object + */ + importFile: function ( fileObject ) { + service.importThisFile( grid, fileObject ); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + + if ( grid.options.enableImporter && grid.options.importerShowMenu ) { + if ( grid.api.core.addToGridMenu ) { + service.addToMenu( grid ); + } else { + // order of registration is not guaranteed, register in a little while + $interval( function() { + if (grid.api.core.addToGridMenu) { + service.addToMenu( grid ); + } + }, 100, 1); + } + } + }, + + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.importer.api:GridOptions + * + * @description GridOptions for importer feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc property + * @propertyOf ui.grid.importer.api:GridOptions + * @name enableImporter + * @description Whether or not importer is enabled. Automatically set + * to false if the user's browser does not support the required fileApi. + * Otherwise defaults to true. + * + */ + if (gridOptions.enableImporter || gridOptions.enableImporter === undefined) { + if ( !($window.hasOwnProperty('File') && $window.hasOwnProperty('FileReader') && $window.hasOwnProperty('FileList') && $window.hasOwnProperty('Blob')) ) { + gridUtil.logError('The File APIs are not fully supported in this browser, grid importer cannot be used.'); + gridOptions.enableImporter = false; + } else { + gridOptions.enableImporter = true; + } + } else { + gridOptions.enableImporter = false; + } + + /** + * @ngdoc method + * @name importerProcessHeaders + * @methodOf ui.grid.importer.api:GridOptions + * @description A callback function that will process headers using custom + * logic. Set this callback function if the headers that your user will provide in their + * import file don't necessarily match the grid header or field names. This might commonly + * occur where your application is internationalised, and therefore the field names + * that the user recognises are in a different language than the field names that + * ui-grid knows about. + * + * Defaults to the internal `processHeaders` method, which seeks to match using both + * displayName and column.name. Any non-matching columns are discarded. + * + * Your callback routine should respond by processing the header array, and returning an array + * of matching column names. A null value in any given position means "don't import this column" + * + *
    +           *      gridOptions.importerProcessHeaders: function( grid, headerArray ) {
    +           *        var myHeaderColumns = [];
    +           *        var thisCol;
    +           *        headerArray.forEach( function( value, index ) {
    +           *          thisCol = mySpecialLookupFunction( value );
    +           *          myHeaderColumns.push( thisCol.name );
    +           *        });
    +           *
    +           *        return myHeaderCols;
    +           *      })
    +           * 
    + * @param {Grid} grid the grid we're importing into + * @param {array} headerArray an array of the text from the first row of the csv file, + * which you need to match to column.names + * @returns {array} array of matching column names, in the same order as the headerArray + * + */ + gridOptions.importerProcessHeaders = gridOptions.importerProcessHeaders || service.processHeaders; + + /** + * @ngdoc method + * @name importerHeaderFilter + * @methodOf ui.grid.importer.api:GridOptions + * @description A callback function that will filter (usually translate) a single + * header. Used when you want to match the passed in column names to the column + * displayName after the header filter. + * + * Your callback routine needs to return the filtered header value. + *
    +           *      gridOptions.importerHeaderFilter: function( displayName ) {
    +           *        return $translate.instant( displayName );
    +           *      })
    +           * 
    + * + * or: + *
    +           *      gridOptions.importerHeaderFilter: $translate.instant
    +           * 
    + * @param {string} displayName the displayName that we'd like to translate + * @returns {string} the translated name + * + */ + gridOptions.importerHeaderFilter = gridOptions.importerHeaderFilter || function( displayName ) { return displayName; }; + + /** + * @ngdoc method + * @name importerErrorCallback + * @methodOf ui.grid.importer.api:GridOptions + * @description A callback function that provides custom error handling, rather + * than the standard grid behaviour of an alert box and a console message. You + * might use this to internationalise the console log messages, or to write to a + * custom logging routine that returned errors to the server. + * + *
    +           *      gridOptions.importerErrorCallback: function( grid, errorKey, consoleMessage, context ) {
    +           *        myUserDisplayRoutine( errorKey );
    +           *        myLoggingRoutine( consoleMessage, context );
    +           *      })
    +           * 
    + * @param {Grid} grid the grid we're importing into, may be useful if you're positioning messages + * in some way + * @param {string} errorKey one of the i18n keys the importer can return - importer.noHeaders, + * importer.noObjects, importer.invalidCsv, importer.invalidJson, importer.jsonNotArray + * @param {string} consoleMessage the English console message that importer would have written + * @param {object} context the context data that importer would have appended to that console message, + * often the file content itself or the element that is in error + * + */ + if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ) { + delete gridOptions.importerErrorCallback; + } + + /** + * @ngdoc method + * @name importerDataAddCallback + * @methodOf ui.grid.importer.api:GridOptions + * @description A mandatory callback function that adds data to the source data array. The grid + * generally doesn't add rows to the source data array, it is tidier to handle this through a user + * callback. + * + *
    +           *      gridOptions.importerDataAddCallback: function( grid, newObjects ) {
    +           *        $scope.myData = $scope.myData.concat( newObjects );
    +           *      })
    +           * 
    + * @param {Grid} grid the grid we're importing into, may be useful in some way + * @param {array} newObjects an array of new objects that you should add to your data + * + */ + if ( gridOptions.enableImporter === true && !gridOptions.importerDataAddCallback ) { + gridUtil.logError("You have not set an importerDataAddCallback, importer is disabled"); + gridOptions.enableImporter = false; + } + + /** + * @ngdoc object + * @name importerNewObject + * @propertyOf ui.grid.importer.api:GridOptions + * @description An object on which we call `new` to create each new row before inserting it into + * the data array. Typically this would be a $resource entity, which means that if you're using + * the rowEdit feature, you can directly call save on this entity when the save event is triggered. + * + * Defaults to a vanilla javascript object + * + * @example + *
    +           *   gridOptions.importerNewObject = MyRes;
    +           * 
    + * + */ + + /** + * @ngdoc property + * @propertyOf ui.grid.importer.api:GridOptions + * @name importerShowMenu + * @description Whether or not to show an item in the grid menu. Defaults to true. + * + */ + gridOptions.importerShowMenu = gridOptions.importerShowMenu !== false; + + /** + * @ngdoc method + * @methodOf ui.grid.importer.api:GridOptions + * @name importerObjectCallback + * @description A callback that massages the data for each object. For example, + * you might have data stored as a code value, but display the decode. This callback + * can be used to change the decoded value back into a code. Defaults to doing nothing. + * @param {Grid} grid in case you need it + * @param {object} newObject the new object as importer has created it, modify it + * then return the modified version + * @returns {object} the modified object + * @example + *
    +           *   gridOptions.importerObjectCallback = function ( grid, newObject ) {
    +           *     switch newObject.status {
    +           *       case 'Active':
    +           *         newObject.status = 1;
    +           *         break;
    +           *       case 'Inactive':
    +           *         newObject.status = 2;
    +           *         break;
    +           *     }
    +           *     return newObject;
    +           *   };
    +           * 
    + */ + gridOptions.importerObjectCallback = gridOptions.importerObjectCallback || function( grid, newObject ) { return newObject; }; + }, + + + /** + * @ngdoc function + * @name addToMenu + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Adds import menu item to the grid menu, + * allowing the user to request import of a file + * @param {Grid} grid the grid into which data should be imported + */ + addToMenu: function ( grid ) { + grid.api.core.addToGridMenu( grid, [ + { + title: i18nService.getSafeText('gridMenu.importerTitle'), + order: 150 + }, + { + templateUrl: 'ui-grid/importerMenuItemContainer', + action: function () { + this.grid.api.importer.importAFile( grid ); + }, + order: 151 + } + ]); + }, + + + /** + * @ngdoc function + * @name importThisFile + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Imports the provided file into the grid using the file object + * provided. Bypasses the grid menu + * @param {Grid} grid the grid we're importing into + * @param {File} fileObject the file we want to import, as returned from the File + * javascript object + */ + importThisFile: function ( grid, fileObject ) { + if (!fileObject) { + gridUtil.logError( 'No file object provided to importThisFile, should be impossible, aborting'); + return; + } + + var reader = new FileReader(); + + switch ( fileObject.type ) { + case 'application/json': + reader.onload = service.importJsonClosure( grid ); + break; + default: + reader.onload = service.importCsvClosure( grid ); + break; + } + + reader.readAsText( fileObject ); + }, + + + /** + * @ngdoc function + * @name importJson + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Creates a function that imports a json file into the grid. + * The json data is imported into new objects of type `gridOptions.importerNewObject`, + * and if the rowEdit feature is enabled the rows are marked as dirty + * @param {Grid} grid the grid we want to import into + * @return {function} Function that receives the file that we want to import, as + * a FileObject as an argument + */ + importJsonClosure: function( grid ) { + return function( importFile ) { + var newObjects = [], + newObject, + importArray = service.parseJson( grid, importFile ); + + if (importArray === null) { + return; + } + importArray.forEach( function( value ) { + newObject = service.newObject( grid ); + angular.extend( newObject, value ); + newObject = grid.options.importerObjectCallback( grid, newObject ); + newObjects.push( newObject ); + }); + + service.addObjects( grid, newObjects ); + }; + }, + + + /** + * @ngdoc function + * @name parseJson + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Parses a json file, returns the parsed data. + * Displays an error if file doesn't parse + * @param {Grid} grid the grid that we want to import into + * @param {FileObject} importFile the file that we want to import, as + * a FileObject + * @returns {array} array of objects from the imported json + */ + parseJson: function( grid, importFile ) { + var loadedObjects; + + try { + loadedObjects = JSON.parse( importFile.target.result ); + } catch (e) { + service.alertError( grid, 'importer.invalidJson', 'File could not be processed, is it valid json? Content was: ', importFile.target.result ); + return; + } + + if ( !Array.isArray( loadedObjects ) ) { + service.alertError( grid, 'importer.jsonNotarray', 'Import failed, file is not an array, file was: ', importFile.target.result ); + return []; + } else { + return loadedObjects; + } + }, + + + + /** + * @ngdoc function + * @name importCsvClosure + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Creates a function that imports a csv file into the grid + * (allowing it to be used in the reader.onload event) + * @param {Grid} grid the grid that we want to import into + * @return {function} Function that receives the file that we want to import, as + * a file object + */ + importCsvClosure: function( grid ) { + return function( importFile ) { + var importArray = service.parseCsv( importFile ); + + if ( !importArray || importArray.length < 1 ) { + service.alertError( grid, 'importer.invalidCsv', 'File could not be processed, is it valid csv? Content was: ', importFile.target.result ); + return; + } + + var newObjects = service.createCsvObjects( grid, importArray ); + + if ( !newObjects || newObjects.length === 0 ) { + service.alertError( grid, 'importer.noObjects', 'Objects were not able to be derived, content was: ', importFile.target.result ); + return; + } + + service.addObjects( grid, newObjects ); + }; + }, + + + /** + * @ngdoc function + * @name parseCsv + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Parses a csv file into an array of arrays, with the first + * array being the headers, and the remaining arrays being the data. + * The logic for this comes from https://github.com/thetalecrafter/excel.js/blob/master/src/csv.js, + * which is noted as being under the MIT license. The code is modified to pass the jscs yoda condition + * checker + * @param {FileObject} importFile the file that we want to import, as a + * file object + */ + parseCsv: function( importFile ) { + var csv = importFile.target.result; + + // use the CSV-JS library to parse + return CSV.parse(csv); + }, + + + /** + * @ngdoc function + * @name createCsvObjects + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Converts an array of arrays (representing the csv file) + * into a set of objects. Uses the provided `gridOptions.importerNewObject` + * to create the objects, and maps the header row into the individual columns + * using either `gridOptions.importerProcessHeaders`, or by using a native method + * of matching to either the displayName, column name or column field of + * the columns in the column defs. The resulting objects will have attributes + * that are named based on the column.field or column.name, in that order. + * @param {Grid} grid the grid that we want to import into + * @param {Array} importArray the data that we want to import, as an array + */ + createCsvObjects: function( grid, importArray ) { + // pull off header row and turn into headers + var headerMapping = grid.options.importerProcessHeaders( grid, importArray.shift() ); + + if ( !headerMapping || headerMapping.length === 0 ) { + service.alertError( grid, 'importer.noHeaders', 'Column names could not be derived, content was: ', importArray ); + return []; + } + + var newObjects = [], + newObject; + + importArray.forEach( function( row ) { + newObject = service.newObject( grid ); + if ( row !== null ) { + row.forEach( function( field, index ) { + if ( headerMapping[index] !== null ) { + newObject[ headerMapping[index] ] = field; + } + }); + } + newObject = grid.options.importerObjectCallback( grid, newObject ); + newObjects.push( newObject ); + }); + + return newObjects; + }, + + + /** + * @ngdoc function + * @name processHeaders + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Determines the columns that the header row from + * a csv (or other) file represents. + * @param {Grid} grid the grid we're importing into + * @param {array} headerRow the header row that we wish to match against + * the column definitions + * @returns {array} an array of the attribute names that should be used + * for that column, based on matching the headers or creating the headers + * + */ + processHeaders: function( grid, headerRow ) { + var headers = []; + + if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ) { + // we are going to create new columnDefs for all these columns, so just remove + // spaces from the names to create fields + headerRow.forEach( function( value ) { + headers.push( value.replace( /[^0-9a-zA-Z\-_]/g, '_' ) ); + }); + return headers; + } + else { + var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs ); + headerRow.forEach( function( value ) { + if ( lookupHash[value] ) { + headers.push( lookupHash[value] ); + } + else if ( lookupHash[ value.toLowerCase() ] ) { + headers.push( lookupHash[ value.toLowerCase() ] ); + } + else { + headers.push( null ); + } + }); + return headers; + } + }, + + + /** + * @name flattenColumnDefs + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Runs through the column defs and creates a hash of + * the displayName, name and field, and of each of those values forced to lower case, + * with each pointing to the field or name + * (whichever is present). Used to lookup column headers and decide what + * attribute name to give to the resulting field. + * @param {Grid} grid the grid we're importing into + * @param {array} columnDefs the columnDefs that we should flatten + * @returns {hash} the flattened version of the column def information, allowing + * us to look up a value by `flattenedHash[ headerValue ]` + */ + flattenColumnDefs: function( grid, columnDefs ) { + var flattenedHash = {}; + + columnDefs.forEach( function( columnDef) { + if ( columnDef.name ) { + flattenedHash[ columnDef.name ] = columnDef.field || columnDef.name; + flattenedHash[ columnDef.name.toLowerCase() ] = columnDef.field || columnDef.name; + } + + if ( columnDef.field ) { + flattenedHash[ columnDef.field ] = columnDef.field || columnDef.name; + flattenedHash[ columnDef.field.toLowerCase() ] = columnDef.field || columnDef.name; + } + + if ( columnDef.displayName ) { + flattenedHash[ columnDef.displayName ] = columnDef.field || columnDef.name; + flattenedHash[ columnDef.displayName.toLowerCase() ] = columnDef.field || columnDef.name; + } + + if ( columnDef.displayName && grid.options.importerHeaderFilter ) { + flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName) ] = columnDef.field || columnDef.name; + flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName).toLowerCase() ] = columnDef.field || columnDef.name; + } + }); + + return flattenedHash; + }, + + + /** + * @ngdoc function + * @name addObjects + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Inserts our new objects into the grid data, and + * sets the rows to dirty if the rowEdit feature is being used + * + * Does this by registering a watch on dataChanges, which essentially + * is waiting on the result of the grid data watch, and downstream processing. + * + * When the callback is called, it deregisters itself - we don't want to run + * again next time data is added. + * + * If we never get called, we deregister on destroy. + * + * @param {Grid} grid the grid we're importing into + * @param {array} newObjects the objects we want to insert into the grid data + * @returns {object} the new object + */ + addObjects: function( grid, newObjects ) { + if ( grid.api.rowEdit ) { + var dataChangeDereg = grid.registerDataChangeCallback( function() { + grid.api.rowEdit.setRowsDirty( newObjects ); + dataChangeDereg(); + }, [uiGridConstants.dataChange.ROW] ); + + grid.importer.$scope.$on( '$destroy', dataChangeDereg ); + } + + grid.importer.$scope.$apply( grid.options.importerDataAddCallback( grid, newObjects ) ); + + }, + + + /** + * @ngdoc function + * @name newObject + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Makes a new object based on `gridOptions.importerNewObject`, + * or based on an empty object if not present + * @param {Grid} grid the grid we're importing into + * @returns {object} the new object + */ + newObject: function( grid ) { + if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ) { + return new grid.options.importerNewObject(); + } + else { + return {}; + } + }, + + + /** + * @ngdoc function + * @name alertError + * @methodOf ui.grid.importer.service:uiGridImporterService + * @description Provides an internationalised user alert for the failure, + * and logs a console message including diagnostic content. + * Optionally, if the the `gridOptions.importerErrorCallback` routine + * is defined, then calls that instead, allowing user specified error routines + * @param {Grid} grid the grid we're importing into + * @param {array} headerRow the header row that we wish to match against + * the column definitions + */ + alertError: function( grid, alertI18nToken, consoleMessage, context ) { + if ( grid.options.importerErrorCallback ) { + grid.options.importerErrorCallback( grid, alertI18nToken, consoleMessage, context ); + } + else { + $window.alert(i18nService.getSafeText( alertI18nToken )); + gridUtil.logError(consoleMessage + context ); + } + } + }; + + return service; + + } + ]); + + /** + * @ngdoc directive + * @name ui.grid.importer.directive:uiGridImporter + * @element div + * @restrict A + * + * @description Adds importer features to grid + * + */ + module.directive('uiGridImporter', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile', + function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridImporterService.initializeGrid($scope, uiGridCtrl.grid); + } + }; + } + ]); + + /** + * @ngdoc directive + * @name ui.grid.importer.directive:uiGridImporterMenuItem + * @element div + * @restrict A + * + * @description Handles the processing from the importer menu item - once a file is + * selected + * + */ + module.directive('uiGridImporterMenuItem', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile', + function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) { + return { + replace: true, + priority: 0, + require: '?^uiGrid', + scope: false, + templateUrl: 'ui-grid/importerMenuItem', + link: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid; + + function handleFileSelect(event) { + var target = event.srcElement || event.target; + + if (target && target.files && target.files.length === 1) { + var fileObject = target.files[0]; + + // Define grid if the uiGrid controller is present + if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) { + grid = uiGridCtrl.grid; + + uiGridImporterService.importThisFile( grid, fileObject ); + target.form.reset(); + } + else { + gridUtil.logError('Could not import file because UI Grid was not found.'); + } + } + } + + var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser'); + + if ( fileChooser.length !== 1 ) { + gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue'); + } + else { + fileChooser[0].addEventListener('change', handleFileSelect, false); + } + } + }; + } + ]); +})(); + +angular.module('ui.grid.importer').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/importerMenuItem', + "
  • " + ); + + + $templateCache.put('ui-grid/importerMenuItemContainer', + "
    " + ); + +}]); diff --git a/src/ui-grid.importer.min.js b/src/ui-grid.importer.min.js new file mode 100644 index 0000000000..c21292dac5 --- /dev/null +++ b/src/ui-grid.importer.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.importer",["ui.grid"]);e.constant("uiGridImporterConstants",{featureName:"importer"}),e.service("uiGridImporterService",["$q","uiGridConstants","uiGridImporterConstants","gridUtil","$compile","$interval","i18nService","$window",function(e,i,r,o,t,n,a,s){var l={initializeGrid:function(e,r){r.importer={$scope:e},this.defaultGridOptions(r.options);var t={events:{importer:{}},methods:{importer:{importFile:function(e){l.importThisFile(r,e)}}}};r.api.registerEventsFromObject(t.events),r.api.registerMethodsFromObject(t.methods),r.options.enableImporter&&r.options.importerShowMenu&&(r.api.core.addToGridMenu?l.addToMenu(r):n(function(){r.api.core.addToGridMenu&&l.addToMenu(r)},100,1))},defaultGridOptions:function(e){e.enableImporter||void 0===e.enableImporter?s.hasOwnProperty("File")&&s.hasOwnProperty("FileReader")&&s.hasOwnProperty("FileList")&&s.hasOwnProperty("Blob")?e.enableImporter=!0:(o.logError("The File APIs are not fully supported in this browser, grid importer cannot be used."),e.enableImporter=!1):e.enableImporter=!1,e.importerProcessHeaders=e.importerProcessHeaders||l.processHeaders,e.importerHeaderFilter=e.importerHeaderFilter||function(e){return e},e.importerErrorCallback&&"function"==typeof e.importerErrorCallback||delete e.importerErrorCallback,!0!==e.enableImporter||e.importerDataAddCallback||(o.logError("You have not set an importerDataAddCallback, importer is disabled"),e.enableImporter=!1),e.importerShowMenu=!1!==e.importerShowMenu,e.importerObjectCallback=e.importerObjectCallback||function(e,r){return r}},addToMenu:function(e){e.api.core.addToGridMenu(e,[{title:a.getSafeText("gridMenu.importerTitle"),order:150},{templateUrl:"ui-grid/importerMenuItemContainer",action:function(){this.grid.api.importer.importAFile(e)},order:151}])},importThisFile:function(e,r){if(r){var t=new FileReader;switch(r.type){case"application/json":t.onload=l.importJsonClosure(e);break;default:t.onload=l.importCsvClosure(e)}t.readAsText(r)}else o.logError("No file object provided to importThisFile, should be impossible, aborting")},importJsonClosure:function(o){return function(e){var r,t=[],i=l.parseJson(o,e);null!==i&&(i.forEach(function(e){r=l.newObject(o),angular.extend(r,e),r=o.options.importerObjectCallback(o,r),t.push(r)}),l.addObjects(o,t))}},parseJson:function(r,t){var e;try{e=JSON.parse(t.target.result)}catch(e){return void l.alertError(r,"importer.invalidJson","File could not be processed, is it valid json? Content was: ",t.target.result)}return Array.isArray(e)?e:(l.alertError(r,"importer.jsonNotarray","Import failed, file is not an array, file was: ",t.target.result),[])},importCsvClosure:function(i){return function(e){var r=l.parseCsv(e);if(!r||r.length<1)l.alertError(i,"importer.invalidCsv","File could not be processed, is it valid csv? Content was: ",e.target.result);else{var t=l.createCsvObjects(i,r);t&&0!==t.length?l.addObjects(i,t):l.alertError(i,"importer.noObjects","Objects were not able to be derived, content was: ",e.target.result)}}},parseCsv:function(e){var r=e.target.result;return CSV.parse(r)},createCsvObjects:function(r,e){var t=r.options.importerProcessHeaders(r,e.shift());if(!t||0===t.length)return l.alertError(r,"importer.noHeaders","Column names could not be derived, content was: ",e),[];var i,o=[];return e.forEach(function(e){i=l.newObject(r),null!==e&&e.forEach(function(e,r){null!==t[r]&&(i[t[r]]=e)}),i=r.options.importerObjectCallback(r,i),o.push(i)}),o},processHeaders:function(e,r){var t=[];if(e.options.columnDefs&&0!==e.options.columnDefs.length){var i=l.flattenColumnDefs(e,e.options.columnDefs);return r.forEach(function(e){i[e]?t.push(i[e]):i[e.toLowerCase()]?t.push(i[e.toLowerCase()]):t.push(null)}),t}return r.forEach(function(e){t.push(e.replace(/[^0-9a-zA-Z\-_]/g,"_"))}),t},flattenColumnDefs:function(r,e){var t={};return e.forEach(function(e){e.name&&(t[e.name]=e.field||e.name,t[e.name.toLowerCase()]=e.field||e.name),e.field&&(t[e.field]=e.field||e.name,t[e.field.toLowerCase()]=e.field||e.name),e.displayName&&(t[e.displayName]=e.field||e.name,t[e.displayName.toLowerCase()]=e.field||e.name),e.displayName&&r.options.importerHeaderFilter&&(t[r.options.importerHeaderFilter(e.displayName)]=e.field||e.name,t[r.options.importerHeaderFilter(e.displayName).toLowerCase()]=e.field||e.name)}),t},addObjects:function(e,r){if(e.api.rowEdit){var t=e.registerDataChangeCallback(function(){e.api.rowEdit.setRowsDirty(r),t()},[i.dataChange.ROW]);e.importer.$scope.$on("$destroy",t)}e.importer.$scope.$apply(e.options.importerDataAddCallback(e,r))},newObject:function(e){return void 0!==e.options&&void 0!==e.options.importerNewObject?new e.options.importerNewObject:{}},alertError:function(e,r,t,i){e.options.importerErrorCallback?e.options.importerErrorCallback(e,r,t,i):(s.alert(a.getSafeText(r)),o.logError(t+i))}};return l}]),e.directive("uiGridImporter",["uiGridImporterConstants","uiGridImporterService","gridUtil","$compile",function(e,o,r,t){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,link:function(e,r,t,i){o.initializeGrid(e,i.grid)}}}]),e.directive("uiGridImporterMenuItem",["uiGridImporterConstants","uiGridImporterService","gridUtil","$compile",function(e,a,s,r){return{replace:!0,priority:0,require:"?^uiGrid",scope:!1,templateUrl:"ui-grid/importerMenuItem",link:function(e,r,t,i){var o;var n=r[0].querySelectorAll(".ui-grid-importer-file-chooser");1!==n.length?s.logError("Found > 1 or < 1 file choosers within the menu item, error, cannot continue"):n[0].addEventListener("change",function(e){var r=e.srcElement||e.target;if(r&&r.files&&1===r.files.length){var t=r.files[0];void 0!==i&&i?(o=i.grid,a.importThisFile(o,t),r.form.reset()):s.logError("Could not import file because UI Grid was not found.")}},!1)}}}])}(),angular.module("ui.grid.importer").run(["$templateCache",function(e){"use strict";e.put("ui-grid/importerMenuItem",'
  • '),e.put("ui-grid/importerMenuItemContainer","
    ")}]); \ No newline at end of file diff --git a/src/ui-grid.infinite-scroll.js b/src/ui-grid.infinite-scroll.js new file mode 100644 index 0000000000..3a83bdca82 --- /dev/null +++ b/src/ui-grid.infinite-scroll.js @@ -0,0 +1,548 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + /** + * @ngdoc overview + * @name ui.grid.infiniteScroll + * + * @description + * + * #ui.grid.infiniteScroll + * + * + * + * This module provides infinite scroll functionality to ui-grid + * + */ + var module = angular.module('ui.grid.infiniteScroll', ['ui.grid']); + /** + * @ngdoc service + * @name ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * + * @description Service for infinite scroll features + */ + module.service('uiGridInfiniteScrollService', ['gridUtil', '$compile', '$rootScope', 'uiGridConstants', 'ScrollEvent', '$q', function (gridUtil, $compile, $rootScope, uiGridConstants, ScrollEvent, $q) { + var service = { + + /** + * @ngdoc function + * @name initializeGrid + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description This method register events and methods into grid public API + */ + + initializeGrid: function(grid, $scope) { + service.defaultGridOptions(grid.options); + + if (!grid.options.enableInfiniteScroll) { + return; + } + + grid.infiniteScroll = { dataLoading: false }; + service.setScrollDirections( grid, grid.options.infiniteScrollUp, grid.options.infiniteScrollDown ); + grid.api.core.on.scrollEnd($scope, service.handleScroll); + + /** + * @ngdoc object + * @name ui.grid.infiniteScroll.api:PublicAPI + * + * @description Public API for infinite scroll feature + */ + var publicApi = { + events: { + infiniteScroll: { + + /** + * @ngdoc event + * @name needLoadMoreData + * @eventOf ui.grid.infiniteScroll.api:PublicAPI + * @description This event fires when scroll reaches bottom percentage of grid + * and needs to load data + */ + + needLoadMoreData: function ($scope, fn) { + }, + + /** + * @ngdoc event + * @name needLoadMoreDataTop + * @eventOf ui.grid.infiniteScroll.api:PublicAPI + * @description This event fires when scroll reaches top percentage of grid + * and needs to load data + */ + + needLoadMoreDataTop: function ($scope, fn) { + } + } + }, + methods: { + infiniteScroll: { + + /** + * @ngdoc function + * @name dataLoaded + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Call this function when you have loaded the additional data + * requested. You should set scrollUp and scrollDown to indicate + * whether there are still more pages in each direction. + * + * If you call dataLoaded without first calling `saveScrollPercentage` then we will + * scroll the user to the start of the newly loaded data, which usually gives a smooth scroll + * experience, but can give a jumpy experience with large `infiniteScrollRowsFromEnd` values, and + * on variable speed internet connections. Using `saveScrollPercentage` as demonstrated in the tutorial + * should give a smoother scrolling experience for users. + * + * See infinite_scroll tutorial for example of usage + * @param {boolean} scrollUp if set to false flags that there are no more pages upwards, so don't fire + * any more infinite scroll events upward + * @param {boolean} scrollDown if set to false flags that there are no more pages downwards, so don't + * fire any more infinite scroll events downward + * @returns {promise} a promise that is resolved when the grid scrolling is fully adjusted. If you're + * planning to remove pages, you should wait on this promise first, or you'll break the scroll positioning + */ + dataLoaded: function( scrollUp, scrollDown ) { + service.setScrollDirections(grid, scrollUp, scrollDown); + + return service.adjustScroll(grid).then(function() { + grid.infiniteScroll.dataLoading = false; + }); + }, + + /** + * @ngdoc function + * @name resetScroll + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Call this function when you have taken some action that makes the current + * scroll position invalid. For example, if you're using external sorting and you've resorted + * then you might reset the scroll, or if you've otherwise substantially changed the data, perhaps + * you've reused an existing grid for a new data set + * + * You must tell us whether there is data upwards or downwards after the reset + * + * @param {boolean} scrollUp flag that there are pages upwards, fire + * infinite scroll events upward + * @param {boolean} scrollDown flag that there are pages downwards, so + * fire infinite scroll events downward + */ + resetScroll: function( scrollUp, scrollDown ) { + service.setScrollDirections( grid, scrollUp, scrollDown); + + service.adjustInfiniteScrollPosition(grid, 0); + }, + + + /** + * @ngdoc function + * @name saveScrollPercentage + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Saves the scroll percentage and number of visible rows before you adjust the data, + * used if you're subsequently going to call `dataRemovedTop` or `dataRemovedBottom` + */ + saveScrollPercentage: function() { + grid.infiniteScroll.prevScrollTop = grid.renderContainers.body.prevScrollTop; + grid.infiniteScroll.previousVisibleRows = grid.getVisibleRowCount(); + }, + + + /** + * @ngdoc function + * @name dataRemovedTop + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Adjusts the scroll position after you've removed data at the top + * @param {boolean} scrollUp flag that there are pages upwards, fire + * infinite scroll events upward + * @param {boolean} scrollDown flag that there are pages downwards, so + * fire infinite scroll events downward + */ + dataRemovedTop: function( scrollUp, scrollDown ) { + service.dataRemovedTop( grid, scrollUp, scrollDown ); + }, + + /** + * @ngdoc function + * @name dataRemovedBottom + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Adjusts the scroll position after you've removed data at the bottom + * @param {boolean} scrollUp flag that there are pages upwards, fire + * infinite scroll events upward + * @param {boolean} scrollDown flag that there are pages downwards, so + * fire infinite scroll events downward + */ + dataRemovedBottom: function( scrollUp, scrollDown ) { + service.dataRemovedBottom( grid, scrollUp, scrollDown ); + }, + + /** + * @ngdoc function + * @name setScrollDirections + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined, + * and also sets the grid.suppressParentScroll + * @param {boolean} scrollUp whether there are pages available up - defaults to false + * @param {boolean} scrollDown whether there are pages available down - defaults to true + */ + setScrollDirections: function ( scrollUp, scrollDown ) { + service.setScrollDirections( grid, scrollUp, scrollDown ); + } + + } + } + }; + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.infiniteScroll.api:GridOptions + * + * @description GridOptions for infinite scroll feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enableInfiniteScroll + * @propertyOf ui.grid.infiniteScroll.api:GridOptions + * @description Enable infinite scrolling for this grid + *
    Defaults to true + */ + gridOptions.enableInfiniteScroll = gridOptions.enableInfiniteScroll !== false; + + /** + * @ngdoc property + * @name infiniteScrollRowsFromEnd + * @propertyOf ui.grid.class:GridOptions + * @description This setting controls how close to the end of the dataset a user gets before + * more data is requested by the infinite scroll, whether scrolling up or down. This allows you to + * 'prefetch' rows before the user actually runs out of scrolling. + * + * Note that if you set this value too high it may give jumpy scrolling behaviour, if you're getting + * this behaviour you could use the `saveScrollPercentageMethod` right before loading your data, and we'll + * preserve that scroll position + * + *
    Defaults to 20 + */ + gridOptions.infiniteScrollRowsFromEnd = gridOptions.infiniteScrollRowsFromEnd || 20; + + /** + * @ngdoc property + * @name infiniteScrollUp + * @propertyOf ui.grid.class:GridOptions + * @description Whether you allow infinite scroll up, implying that the first page of data + * you have displayed is in the middle of your data set. If set to true then we trigger the + * needMoreDataTop event when the user hits the top of the scrollbar. + *
    Defaults to false + */ + gridOptions.infiniteScrollUp = gridOptions.infiniteScrollUp === true; + + /** + * @ngdoc property + * @name infiniteScrollDown + * @propertyOf ui.grid.class:GridOptions + * @description Whether you allow infinite scroll down, implying that the first page of data + * you have displayed is in the middle of your data set. If set to true then we trigger the + * needMoreData event when the user hits the bottom of the scrollbar. + *
    Defaults to true + */ + gridOptions.infiniteScrollDown = gridOptions.infiniteScrollDown !== false; + }, + + + /** + * @ngdoc function + * @name setScrollDirections + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description Sets the scrollUp and scrollDown flags, handling nulls and undefined, + * and also sets the grid.suppressParentScroll + * @param {grid} grid the grid we're operating on + * @param {boolean} scrollUp whether there are pages available up - defaults to false + * @param {boolean} scrollDown whether there are pages available down - defaults to true + */ + setScrollDirections: function ( grid, scrollUp, scrollDown ) { + grid.infiniteScroll.scrollUp = ( scrollUp === true ); + grid.suppressParentScrollUp = ( scrollUp === true ); + + grid.infiniteScroll.scrollDown = ( scrollDown !== false); + grid.suppressParentScrollDown = ( scrollDown !== false); + }, + + + /** + * @ngdoc function + * @name handleScroll + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description Called whenever the grid scrolls, determines whether the scroll should + * trigger an infinite scroll request for more data + * @param {object} args the args from the event + */ + handleScroll: function (args) { + // don't request data if already waiting for data, or if source is coming from ui.grid.adjustInfiniteScrollPosition() function + if ( args.grid.infiniteScroll && args.grid.infiniteScroll.dataLoading || args.source === 'ui.grid.adjustInfiniteScrollPosition' ) { + return; + } + + if (args.y) { + + // If the user is scrolling very quickly all the way to the top/bottom, the scroll handler can get confused + // about the direction. First we check if they've gone all the way, and data always is loaded in this case. + if (args.y.percentage === 0) { + args.grid.scrollDirection = uiGridConstants.scrollDirection.UP; + service.loadData(args.grid); + } + else if (args.y.percentage === 1) { + args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN; + service.loadData(args.grid); + } + else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data. + var percentage, + targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length; + + if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) { + percentage = args.y.percentage; + if (percentage <= targetPercentage) { + service.loadData(args.grid); + } + } + else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) { + percentage = 1 - args.y.percentage; + if (percentage <= targetPercentage) { + service.loadData(args.grid); + } + } + } + } + }, + + + /** + * @ngdoc function + * @name loadData + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection + * and whether there are more pages upwards or downwards. It also stores the number of rows that we had previously, + * and clears out any saved scroll position so that we know whether or not the user calls `saveScrollPercentage` + * @param {Grid} grid the grid we're working on + */ + loadData: function (grid) { + // save number of currently visible rows to calculate new scroll position later - we know that we want + // to be at approximately the row we're currently at + grid.infiniteScroll.previousVisibleRows = grid.renderContainers.body.visibleRowCache.length; + grid.infiniteScroll.direction = grid.scrollDirection; + delete grid.infiniteScroll.prevScrollTop; + + if (grid.scrollDirection === uiGridConstants.scrollDirection.UP && grid.infiniteScroll.scrollUp ) { + grid.infiniteScroll.dataLoading = true; + grid.api.infiniteScroll.raise.needLoadMoreDataTop(); + } + else if (grid.scrollDirection === uiGridConstants.scrollDirection.DOWN && grid.infiniteScroll.scrollDown ) { + grid.infiniteScroll.dataLoading = true; + grid.api.infiniteScroll.raise.needLoadMoreData(); + } + }, + + + /** + * @ngdoc function + * @name adjustScroll + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description Once we are informed that data has been loaded, adjust the scroll position to account for that + * addition and to make things look clean. + * + * If we're scrolling up we scroll to the first row of the old data set - + * so we're assuming that you would have gotten to the top of the grid (from the 20% need more data trigger) by + * the time the data comes back. If we're scrolling down we scroll to the last row of the old data set - so we're + * assuming that you would have gotten to the bottom of the grid (from the 80% need more data trigger) by the time + * the data comes back. + * + * Neither of these are good assumptions, but making this a smoother experience really requires + * that trigger to not be a percentage, and to be much closer to the end of the data (say, 5 rows off the end). Even then + * it'd be better still to actually run into the end. But if the data takes a while to come back, they may have scrolled + * somewhere else in the mean-time, in which case they'll get a jump back to the new data. Anyway, this will do for + * now, until someone wants to do better. + * @param {Grid} grid the grid we're working on + * @returns {promise} a promise that is resolved when scrolling has finished + */ + adjustScroll: function(grid) { + var promise = $q.defer(); + $rootScope.$applyAsync(function () { + var viewportHeight, rowHeight, newVisibleRows, oldTop, newTop; + + viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight; + rowHeight = grid.options.rowHeight; + + if ( grid.infiniteScroll.direction === undefined ) { + // called from initialize, tweak our scroll up a little + service.adjustInfiniteScrollPosition(grid, 0); + } + + newVisibleRows = grid.getVisibleRowCount(); + + // in case not enough data is loaded to enable scroller - load more data + var canvasHeight = rowHeight * newVisibleRows; + if (grid.infiniteScroll.scrollDown && (viewportHeight > canvasHeight)) { + grid.api.infiniteScroll.raise.needLoadMoreData(); + } + + if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.UP ) { + oldTop = grid.infiniteScroll.prevScrollTop || 0; + newTop = oldTop + (newVisibleRows - grid.infiniteScroll.previousVisibleRows)*rowHeight; + service.adjustInfiniteScrollPosition(grid, newTop); + $rootScope.$applyAsync( function() { + promise.resolve(); + }); + } + + if ( grid.infiniteScroll.direction === uiGridConstants.scrollDirection.DOWN ) { + newTop = grid.infiniteScroll.prevScrollTop || (grid.infiniteScroll.previousVisibleRows*rowHeight - viewportHeight); + service.adjustInfiniteScrollPosition(grid, newTop); + $rootScope.$applyAsync( function() { + promise.resolve(); + }); + } + }, 0); + + return promise.promise; + }, + + + /** + * @ngdoc function + * @name adjustInfiniteScrollPosition + * @methodOf ui.grid.infiniteScroll.service:uiGridInfiniteScrollService + * @description This function fires 'needLoadMoreData' or 'needLoadMoreDataTop' event based on scrollDirection + * @param {Grid} grid the grid we're working on + * @param {number} scrollTop the position through the grid that we want to scroll to + */ + adjustInfiniteScrollPosition: function (grid, scrollTop) { + var scrollEvent = new ScrollEvent(grid, null, null, 'ui.grid.adjustInfiniteScrollPosition'), + visibleRows = grid.getVisibleRowCount(), + viewportHeight = grid.getViewportHeight() + grid.headerHeight - grid.renderContainers.body.headerHeight - grid.scrollbarHeight, + rowHeight = grid.options.rowHeight, + scrollHeight = visibleRows*rowHeight-viewportHeight; + + // for infinite scroll, if there are pages upwards then never allow it to be at the zero position so the up button can be active + if (scrollTop === 0 && grid.infiniteScroll.scrollUp) { + // using pixels results in a relative scroll, hence we have to use percentage + scrollEvent.y = {pixels: 1}; + } + else { + scrollEvent.y = {percentage: scrollTop/scrollHeight}; + } + grid.scrollContainers('', scrollEvent); + }, + + + /** + * @ngdoc function + * @name dataRemovedTop + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Adjusts the scroll position after you've removed data at the top. You should + * have called `saveScrollPercentage` before you remove the data, and if you're doing this in + * response to a `needMoreData` you should wait until the promise from `loadData` has resolved + * before you start removing data + * @param {Grid} grid the grid we're working on + * @param {boolean} scrollUp flag that there are pages upwards, fire + * infinite scroll events upward + * @param {boolean} scrollDown flag that there are pages downwards, so + * fire infinite scroll events downward + */ + dataRemovedTop: function( grid, scrollUp, scrollDown ) { + var newVisibleRows, oldTop, newTop, rowHeight; + service.setScrollDirections( grid, scrollUp, scrollDown ); + + newVisibleRows = grid.renderContainers.body.visibleRowCache.length; + oldTop = grid.infiniteScroll.prevScrollTop; + rowHeight = grid.options.rowHeight; + + // since we removed from the top, our new scroll row will be the old scroll row less the number + // of rows removed + newTop = oldTop - ( grid.infiniteScroll.previousVisibleRows - newVisibleRows )*rowHeight; + + service.adjustInfiniteScrollPosition( grid, newTop ); + }, + + /** + * @ngdoc function + * @name dataRemovedBottom + * @methodOf ui.grid.infiniteScroll.api:PublicAPI + * @description Adjusts the scroll position after you've removed data at the bottom. You should + * have called `saveScrollPercentage` before you remove the data, and if you're doing this in + * response to a `needMoreData` you should wait until the promise from `loadData` has resolved + * before you start removing data + * @param {Grid} grid the grid we're working on + * @param {boolean} scrollUp flag that there are pages upwards, fire + * infinite scroll events upward + * @param {boolean} scrollDown flag that there are pages downwards, so + * fire infinite scroll events downward + */ + dataRemovedBottom: function( grid, scrollUp, scrollDown ) { + var newTop; + + service.setScrollDirections( grid, scrollUp, scrollDown ); + + newTop = grid.infiniteScroll.prevScrollTop; + + service.adjustInfiniteScrollPosition( grid, newTop ); + } + }; + return service; + }]); + /** + * @ngdoc directive + * @name ui.grid.infiniteScroll.directive:uiGridInfiniteScroll + * @element div + * @restrict A + * + * @description Adds infinite scroll features to grid + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.infiniteScroll']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Alex', car: 'Toyota' }, + { name: 'Sam', car: 'Lexus' } + ]; + + $scope.columnDefs = [ + {name: 'name'}, + {name: 'car'} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + + module.directive('uiGridInfiniteScroll', ['uiGridInfiniteScrollService', + function (uiGridInfiniteScrollService) { + return { + priority: -200, + scope: false, + require: '^uiGrid', + compile: function() { + return { + pre: function($scope, $elm, $attr, uiGridCtrl) { + uiGridInfiniteScrollService.initializeGrid(uiGridCtrl.grid, $scope); + }, + post: function($scope, $elm, $attr) { + } + }; + } + }; + }]); +})(); diff --git a/src/ui-grid.infinite-scroll.min.js b/src/ui-grid.infinite-scroll.min.js new file mode 100644 index 0000000000..8d55ca0697 --- /dev/null +++ b/src/ui-grid.infinite-scroll.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var i=angular.module("ui.grid.infiniteScroll",["ui.grid"]);i.service("uiGridInfiniteScrollService",["gridUtil","$compile","$rootScope","uiGridConstants","ScrollEvent","$q",function(i,o,c,s,t,n){var a={initializeGrid:function(n,i){if(a.defaultGridOptions(n.options),n.options.enableInfiniteScroll){n.infiniteScroll={dataLoading:!1},a.setScrollDirections(n,n.options.infiniteScrollUp,n.options.infiniteScrollDown),n.api.core.on.scrollEnd(i,a.handleScroll);var o={events:{infiniteScroll:{needLoadMoreData:function(i,o){},needLoadMoreDataTop:function(i,o){}}},methods:{infiniteScroll:{dataLoaded:function(i,o){return a.setScrollDirections(n,i,o),a.adjustScroll(n).then(function(){n.infiniteScroll.dataLoading=!1})},resetScroll:function(i,o){a.setScrollDirections(n,i,o),a.adjustInfiniteScrollPosition(n,0)},saveScrollPercentage:function(){n.infiniteScroll.prevScrollTop=n.renderContainers.body.prevScrollTop,n.infiniteScroll.previousVisibleRows=n.getVisibleRowCount()},dataRemovedTop:function(i,o){a.dataRemovedTop(n,i,o)},dataRemovedBottom:function(i,o){a.dataRemovedBottom(n,i,o)},setScrollDirections:function(i,o){a.setScrollDirections(n,i,o)}}}};n.api.registerEventsFromObject(o.events),n.api.registerMethodsFromObject(o.methods)}},defaultGridOptions:function(i){i.enableInfiniteScroll=!1!==i.enableInfiniteScroll,i.infiniteScrollRowsFromEnd=i.infiniteScrollRowsFromEnd||20,i.infiniteScrollUp=!0===i.infiniteScrollUp,i.infiniteScrollDown=!1!==i.infiniteScrollDown},setScrollDirections:function(i,o,n){i.infiniteScroll.scrollUp=!0===o,i.suppressParentScrollUp=!0===o,i.infiniteScroll.scrollDown=!1!==n,i.suppressParentScrollDown=!1!==n},handleScroll:function(i){if(!(i.grid.infiniteScroll&&i.grid.infiniteScroll.dataLoading||"ui.grid.adjustInfiniteScrollPosition"===i.source)&&i.y)if(0===i.y.percentage)i.grid.scrollDirection=s.scrollDirection.UP,a.loadData(i.grid);else if(1===i.y.percentage)i.grid.scrollDirection=s.scrollDirection.DOWN,a.loadData(i.grid);else{var o=i.grid.options.infiniteScrollRowsFromEnd/i.grid.renderContainers.body.visibleRowCache.length;i.grid.scrollDirection===s.scrollDirection.UP?i.y.percentage<=o&&a.loadData(i.grid):i.grid.scrollDirection===s.scrollDirection.DOWN&&1-i.y.percentage<=o&&a.loadData(i.grid)}},loadData:function(i){i.infiniteScroll.previousVisibleRows=i.renderContainers.body.visibleRowCache.length,i.infiniteScroll.direction=i.scrollDirection,delete i.infiniteScroll.prevScrollTop,i.scrollDirection===s.scrollDirection.UP&&i.infiniteScroll.scrollUp?(i.infiniteScroll.dataLoading=!0,i.api.infiniteScroll.raise.needLoadMoreDataTop()):i.scrollDirection===s.scrollDirection.DOWN&&i.infiniteScroll.scrollDown&&(i.infiniteScroll.dataLoading=!0,i.api.infiniteScroll.raise.needLoadMoreData())},adjustScroll:function(l){var t=n.defer();return c.$applyAsync(function(){var i,o,n,e;i=l.getViewportHeight()+l.headerHeight-l.renderContainers.body.headerHeight-l.scrollbarHeight,o=l.options.rowHeight,void 0===l.infiniteScroll.direction&&a.adjustInfiniteScrollPosition(l,0);var r=o*(n=l.getVisibleRowCount());l.infiniteScroll.scrollDown&&rBeta This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs. + * + * This module provides auto-resizing functionality to UI-Grid. + */ + var module = angular.module('ui.grid.autoResize', ['ui.grid']); + + /** + * @ngdoc directive + * @name ui.grid.autoResize.directive:uiGridAutoResize + * @element div + * @restrict A + * + * @description Stacks on top of the ui-grid directive and + * adds the a watch to the grid's height and width which refreshes + * the grid content whenever its dimensions change. + * + */ + module.directive('uiGridAutoResize', ['gridUtil', function(gridUtil) { + return { + require: 'uiGrid', + scope: false, + link: function($scope, $elm, $attrs, uiGridCtrl) { + var debouncedRefresh; + + function getDimensions() { + return { + width: gridUtil.elementWidth($elm), + height: gridUtil.elementHeight($elm) + }; + } + + function refreshGrid(prevWidth, prevHeight, width, height) { + if ($elm[0].offsetParent !== null) { + uiGridCtrl.grid.gridWidth = width; + uiGridCtrl.grid.gridHeight = height; + uiGridCtrl.grid.queueGridRefresh() + .then(function() { + uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevHeight, prevWidth, height, width); + }); + } + } + + debouncedRefresh = gridUtil.debounce(refreshGrid, 400); + + $scope.$watchCollection(getDimensions, function(newValues, oldValues) { + if (!angular.equals(newValues, oldValues)) { + debouncedRefresh(oldValues.width, oldValues.height, newValues.width, newValues.height); + } + }); + } + }; + }]); +})(); + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.cellNav + * + * @description + + #ui.grid.cellNav + + + + This module provides cell navigation functionality to UI-Grid. + */ + var module = angular.module('ui.grid.cellNav', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.cellNav.constant:uiGridCellNavConstants + * + * @description constants available in cellNav + */ + module.constant('uiGridCellNavConstants', { + FEATURE_NAME: 'gridCellNav', + CELL_NAV_EVENT: 'cellNav', + direction: {LEFT: 0, RIGHT: 1, UP: 2, DOWN: 3, PG_UP: 4, PG_DOWN: 5}, + EVENT_TYPE: { + KEYDOWN: 0, + CLICK: 1, + CLEAR: 2 + } + }); + + + module.factory('uiGridCellNavFactory', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', 'GridRowColumn', '$q', + function (gridUtil, uiGridConstants, uiGridCellNavConstants, GridRowColumn, $q) { + /** + * @ngdoc object + * @name ui.grid.cellNav.object:CellNav + * @description returns a CellNav prototype function + * @param {object} rowContainer container for rows + * @param {object} colContainer parent column container + * @param {object} leftColContainer column container to the left of parent + * @param {object} rightColContainer column container to the right of parent + */ + var UiGridCellNav = function UiGridCellNav(rowContainer, colContainer, leftColContainer, rightColContainer) { + this.rows = rowContainer.visibleRowCache; + this.columns = colContainer.visibleColumnCache; + this.leftColumns = leftColContainer ? leftColContainer.visibleColumnCache : []; + this.rightColumns = rightColContainer ? rightColContainer.visibleColumnCache : []; + this.bodyContainer = rowContainer; + }; + + /** returns focusable columns of all containers */ + UiGridCellNav.prototype.getFocusableCols = function () { + var allColumns = this.leftColumns.concat(this.columns, this.rightColumns); + + return allColumns.filter(function (col) { + return col.colDef.allowCellFocus; + }); + }; + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:GridRow + * + * @description GridRow settings for cellNav feature, these are available to be + * set only internally (for example, by other features) + */ + + /** + * @ngdoc object + * @name allowCellFocus + * @propertyOf ui.grid.cellNav.api:GridRow + * @description Enable focus on a cell within this row. If set to false then no cells + * in this row can be focused - group header rows as an example would set this to false. + *
    Defaults to true + */ + /** returns focusable rows */ + UiGridCellNav.prototype.getFocusableRows = function () { + return this.rows.filter(function(row) { + return row.allowCellFocus !== false; + }); + }; + + UiGridCellNav.prototype.getNextRowCol = function (direction, curRow, curCol) { + switch (direction) { + case uiGridCellNavConstants.direction.LEFT: + return this.getRowColLeft(curRow, curCol); + case uiGridCellNavConstants.direction.RIGHT: + return this.getRowColRight(curRow, curCol); + case uiGridCellNavConstants.direction.UP: + return this.getRowColUp(curRow, curCol); + case uiGridCellNavConstants.direction.DOWN: + return this.getRowColDown(curRow, curCol); + case uiGridCellNavConstants.direction.PG_UP: + return this.getRowColPageUp(curRow, curCol); + case uiGridCellNavConstants.direction.PG_DOWN: + return this.getRowColPageDown(curRow, curCol); + } + }; + + UiGridCellNav.prototype.initializeSelection = function () { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + if (focusableCols.length === 0 || focusableRows.length === 0) { + return null; + } + + return new GridRowColumn(focusableRows[0], focusableCols[0]); // return same row + }; + + UiGridCellNav.prototype.getRowColLeft = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 1 + if (curColIndex === -1) { + curColIndex = 1; + } + + var nextColIndex = curColIndex === 0 ? focusableCols.length - 1 : curColIndex - 1; + + // get column to left + if (nextColIndex >= curColIndex) { + // On the first row + // if (curRowIndex === 0 && curColIndex === 0) { + // return null; + // } + if (curRowIndex === 0) { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row + } + else { + // up one row and far right column + return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[nextColIndex]); + } + } + else { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); + } + }; + + + + UiGridCellNav.prototype.getRowColRight = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + var nextColIndex = curColIndex === focusableCols.length - 1 ? 0 : curColIndex + 1; + + if (nextColIndex <= curColIndex) { + if (curRowIndex === focusableRows.length - 1) { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); // return same row + } + else { + // down one row and far left column + return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[nextColIndex]); + } + } + else { + return new GridRowColumn(curRow, focusableCols[nextColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColDown = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + if (curRowIndex === focusableRows.length - 1) { + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row + } + else { + // down one row + return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColPageDown = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + var pageSize = this.bodyContainer.minRowsToRender(); + if (curRowIndex >= focusableRows.length - pageSize) { + return new GridRowColumn(focusableRows[focusableRows.length - 1], focusableCols[curColIndex]); // return last row + } + else { + // down one page + return new GridRowColumn(focusableRows[curRowIndex + pageSize], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColUp = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + if (curRowIndex === 0) { + return new GridRowColumn(curRow, focusableCols[curColIndex]); // return same row + } + else { + // up one row + return new GridRowColumn(focusableRows[curRowIndex - 1], focusableCols[curColIndex]); + } + }; + + UiGridCellNav.prototype.getRowColPageUp = function (curRow, curCol) { + var focusableCols = this.getFocusableCols(); + var focusableRows = this.getFocusableRows(); + var curColIndex = focusableCols.indexOf(curCol); + var curRowIndex = focusableRows.indexOf(curRow); + + // could not find column in focusable Columns so set it to 0 + if (curColIndex === -1) { + curColIndex = 0; + } + + var pageSize = this.bodyContainer.minRowsToRender(); + if (curRowIndex - pageSize < 0) { + return new GridRowColumn(focusableRows[0], focusableCols[curColIndex]); // return first row + } + else { + // up one page + return new GridRowColumn(focusableRows[curRowIndex - pageSize], focusableCols[curColIndex]); + } + }; + return UiGridCellNav; + }]); + + /** + * @ngdoc service + * @name ui.grid.cellNav.service:uiGridCellNavService + * + * @description Services for cell navigation features. If you don't like the key maps we use, + * or the direction cells navigation, override with a service decorator (see angular docs) + */ + module.service('uiGridCellNavService', ['gridUtil', 'uiGridConstants', 'uiGridCellNavConstants', '$q', 'uiGridCellNavFactory', 'GridRowColumn', 'ScrollEvent', + function (gridUtil, uiGridConstants, uiGridCellNavConstants, $q, UiGridCellNav, GridRowColumn, ScrollEvent) { + + var service = { + + initializeGrid: function (grid) { + grid.registerColumnBuilder(service.cellNavColumnBuilder); + + + /** + * @ngdoc object + * @name ui.grid.cellNav.Grid:cellNav + * @description cellNav properties added to grid class + */ + grid.cellNav = {}; + grid.cellNav.lastRowCol = null; + grid.cellNav.focusedCells = []; + + service.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:PublicApi + * + * @description Public Api for cellNav feature + */ + var publicApi = { + events: { + cellNav: { + /** + * @ngdoc event + * @name navigate + * @eventOf ui.grid.cellNav.api:PublicApi + * @description raised when the active cell is changed + *
    +                 *      gridApi.cellNav.on.navigate(scope,function(newRowcol, oldRowCol) {})
    +                 * 
    + * @param {object} newRowCol new position + * @param {object} oldRowCol old position + */ + navigate: function (newRowCol, oldRowCol) {}, + /** + * @ngdoc event + * @name viewPortKeyDown + * @eventOf ui.grid.cellNav.api:PublicApi + * @description is raised when the viewPort receives a keyDown event. Cells never get focus in uiGrid + * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this + * event whenever you need a keydown event on a cell + *
    + * @param {object} event keydown event + * @param {object} rowCol current rowCol position + */ + viewPortKeyDown: function (event, rowCol) {}, + + /** + * @ngdoc event + * @name viewPortKeyPress + * @eventOf ui.grid.cellNav.api:PublicApi + * @description is raised when the viewPort receives a keyPress event. Cells never get focus in uiGrid + * due to the difficulties of setting focus on a cell that is not visible in the viewport. Use this + * event whenever you need a keypress event on a cell + *
    + * @param {object} event keypress event + * @param {object} rowCol current rowCol position + */ + viewPortKeyPress: function (event, rowCol) {} + } + }, + methods: { + cellNav: { + /** + * @ngdoc function + * @name scrollToFocus + * @methodOf ui.grid.cellNav.api:PublicApi + * @description brings the specified row and column into view, and sets focus + * to that cell + * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus + * @param {object} colDef to make visible and set focus + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + scrollToFocus: function (rowEntity, colDef) { + return service.scrollToFocus(grid, rowEntity, colDef); + }, + + /** + * @ngdoc function + * @name getFocusedCell + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns the current (or last if Grid does not have focus) focused row and column + *
    value is null if no selection has occurred + */ + getFocusedCell: function () { + return grid.cellNav.lastRowCol; + }, + + /** + * @ngdoc function + * @name getCurrentSelection + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns an array containing the current selection + *
    array is empty if no selection has occurred + */ + getCurrentSelection: function () { + return grid.cellNav.focusedCells; + }, + + /** + * @ngdoc function + * @name rowColSelectIndex + * @methodOf ui.grid.cellNav.api:PublicApi + * @description returns the index in the order in which the GridRowColumn was selected, returns -1 if the GridRowColumn + * isn't selected + * @param {object} rowCol the rowCol to evaluate + */ + rowColSelectIndex: function (rowCol) { + // return gridUtil.arrayContainsObjectWithProperty(grid.cellNav.focusedCells, 'col.uid', rowCol.col.uid) && + var index = -1; + for (var i = 0; i < grid.cellNav.focusedCells.length; i++) { + if (grid.cellNav.focusedCells[i].col.uid === rowCol.col.uid && + grid.cellNav.focusedCells[i].row.uid === rowCol.row.uid) { + index = i; + break; + } + } + return index; + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + defaultGridOptions: function (gridOptions) { + /** + * @ngdoc object + * @name ui.grid.cellNav.api:GridOptions + * + * @description GridOptions for cellNav feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name modifierKeysToMultiSelectCells + * @propertyOf ui.grid.cellNav.api:GridOptions + * @description Enable multiple cell selection only when using the ctrlKey or shiftKey. + *
    Defaults to false + */ + gridOptions.modifierKeysToMultiSelectCells = gridOptions.modifierKeysToMultiSelectCells === true; + + /** + * @ngdoc array + * @name keyDownOverrides + * @propertyOf ui.grid.cellNav.api:GridOptions + * @description An array of event objects to override on keydown. If an event is overridden, the viewPortKeyDown event will + * be raised with the overridden events, allowing custom keydown behavior. + *
    Defaults to [] + */ + gridOptions.keyDownOverrides = gridOptions.keyDownOverrides || []; + + }, + + /** + * @ngdoc service + * @name decorateRenderContainers + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description decorates grid renderContainers with cellNav functions + */ + decorateRenderContainers: function (grid) { + + var rightContainer = grid.hasRightContainer() ? grid.renderContainers.right : null; + var leftContainer = grid.hasLeftContainer() ? grid.renderContainers.left : null; + + if (leftContainer !== null) { + grid.renderContainers.left.cellNav = new UiGridCellNav(grid.renderContainers.body, leftContainer, rightContainer, grid.renderContainers.body); + } + if (rightContainer !== null) { + grid.renderContainers.right.cellNav = new UiGridCellNav(grid.renderContainers.body, rightContainer, grid.renderContainers.body, leftContainer); + } + + grid.renderContainers.body.cellNav = new UiGridCellNav(grid.renderContainers.body, grid.renderContainers.body, leftContainer, rightContainer); + }, + + /** + * @ngdoc service + * @name getDirection + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description determines which direction to for a given keyDown event + * @returns {uiGridCellNavConstants.direction} direction + */ + getDirection: function (evt) { + if (evt.keyCode === uiGridConstants.keymap.LEFT || + (evt.keyCode === uiGridConstants.keymap.TAB && evt.shiftKey)) { + return uiGridCellNavConstants.direction.LEFT; + } + if (evt.keyCode === uiGridConstants.keymap.RIGHT || + evt.keyCode === uiGridConstants.keymap.TAB) { + return uiGridCellNavConstants.direction.RIGHT; + } + + if (evt.keyCode === uiGridConstants.keymap.UP || + (evt.keyCode === uiGridConstants.keymap.ENTER && evt.shiftKey) ) { + return uiGridCellNavConstants.direction.UP; + } + + if (evt.keyCode === uiGridConstants.keymap.PG_UP) { + return uiGridCellNavConstants.direction.PG_UP; + } + + if (evt.keyCode === uiGridConstants.keymap.DOWN || + evt.keyCode === uiGridConstants.keymap.ENTER && !(evt.ctrlKey || evt.altKey)) { + return uiGridCellNavConstants.direction.DOWN; + } + + if (evt.keyCode === uiGridConstants.keymap.PG_DOWN) { + return uiGridCellNavConstants.direction.PG_DOWN; + } + + return null; + }, + + /** + * @ngdoc service + * @name cellNavColumnBuilder + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @description columnBuilder function that adds cell navigation properties to grid column + * @returns {promise} promise that will load any needed templates when resolved + */ + cellNavColumnBuilder: function (colDef, col, gridOptions) { + var promises = []; + + /** + * @ngdoc object + * @name ui.grid.cellNav.api:ColumnDef + * + * @description Column Definitions for cellNav feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name allowCellFocus + * @propertyOf ui.grid.cellNav.api:ColumnDef + * @description Enable focus on a cell within this column. + *
    Defaults to true + */ + colDef.allowCellFocus = colDef.allowCellFocus === undefined ? true : colDef.allowCellFocus; + + return $q.all(promises); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @name scrollToFocus + * @description Scroll the grid such that the specified + * row and column is in view, and set focus to the cell in that row and column + * @param {Grid} grid the grid you'd like to act upon, usually available + * from gridApi.grid + * @param {object} rowEntity gridOptions.data[] array instance to make visible and set focus to + * @param {object} colDef to make visible and set focus to + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + scrollToFocus: function (grid, rowEntity, colDef) { + var gridRow = null, gridCol = null; + + if (typeof(rowEntity) !== 'undefined' && rowEntity !== null) { + gridRow = grid.getRow(rowEntity); + } + + if (typeof(colDef) !== 'undefined' && colDef !== null) { + gridCol = grid.getColumn(colDef.name ? colDef.name : colDef.field); + } + return grid.api.core.scrollToIfNecessary(gridRow, gridCol).then(function () { + var rowCol = { row: gridRow, col: gridCol }; + + // Broadcast the navigation + if (gridRow !== null && gridCol !== null) { + grid.cellNav.broadcastCellNav(rowCol, null, null); + } + }); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.cellNav.service:uiGridCellNavService + * @name getLeftWidth + * @description Get the current drawn width of the columns in the + * grid up to the numbered column, and add an apportionment for the + * column that we're on. So if we are on column 0, we want to scroll + * 0% (i.e. exclude this column from calc). If we're on the last column + * we want to scroll to 100% (i.e. include this column in the calc). So + * we include (thisColIndex / totalNumberCols) % of this column width + * @param {Grid} grid the grid you'd like to act upon, usually available + * from gridApi.grid + * @param {GridColumn} upToCol the column to total up to and including + */ + getLeftWidth: function (grid, upToCol) { + var width = 0; + + if (!upToCol) { + return width; + } + + var lastIndex = grid.renderContainers.body.visibleColumnCache.indexOf( upToCol ); + + // total column widths up-to but not including the passed in column + grid.renderContainers.body.visibleColumnCache.forEach( function( col, index ) { + if ( index < lastIndex ) { + width += col.drawnWidth; + } + }); + + // pro-rata the final column based on % of total columns. + var percentage = lastIndex === 0 ? 0 : (lastIndex + 1) / grid.renderContainers.body.visibleColumnCache.length; + width += upToCol.drawnWidth * percentage; + + return width; + } + }; + + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.cellNav.directive:uiCellNav + * @element div + * @restrict EA + * + * @description Adds cell navigation features to the grid columns + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.cellNav']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name'}, + {name: 'title'} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridCellnav', ['gridUtil', 'uiGridCellNavService', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', '$timeout', '$compile', 'i18nService', + function (gridUtil, uiGridCellNavService, uiGridCellNavConstants, uiGridConstants, GridRowColumn, $timeout, $compile, i18nService) { + return { + replace: true, + priority: -150, + require: '^uiGrid', + scope: false, + controller: function () {}, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + var _scope = $scope; + + var grid = uiGridCtrl.grid; + uiGridCellNavService.initializeGrid(grid); + + uiGridCtrl.cellNav = {}; + + // Ensure that the object has all of the methods we expect it to + uiGridCtrl.cellNav.makeRowCol = function (obj) { + if (!(obj instanceof GridRowColumn)) { + obj = new GridRowColumn(obj.row, obj.col); + } + return obj; + }; + + uiGridCtrl.cellNav.getActiveCell = function () { + var elms = $elm[0].getElementsByClassName('ui-grid-cell-focus'); + if (elms.length > 0) { + return elms[0]; + } + + return undefined; + }; + + uiGridCtrl.cellNav.broadcastCellNav = grid.cellNav.broadcastCellNav = function (newRowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); + + newRowCol = uiGridCtrl.cellNav.makeRowCol(newRowCol); + + uiGridCtrl.cellNav.broadcastFocus(newRowCol, modifierDown, originEvt); + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol, modifierDown, originEvt); + }; + + uiGridCtrl.cellNav.clearFocus = grid.cellNav.clearFocus = function () { + grid.cellNav.focusedCells = []; + _scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT); + }; + + uiGridCtrl.cellNav.broadcastFocus = function (rowCol, modifierDown, originEvt) { + modifierDown = !(modifierDown === undefined || !modifierDown); + + rowCol = uiGridCtrl.cellNav.makeRowCol(rowCol); + + var row = rowCol.row, + col = rowCol.col; + + var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); + + if (grid.cellNav.lastRowCol === null || rowColSelectIndex === -1 || (grid.cellNav.lastRowCol.col === col && grid.cellNav.lastRowCol.row === row)) { + var newRowCol = new GridRowColumn(row, col); + + if (grid.cellNav.lastRowCol === null || grid.cellNav.lastRowCol.row !== newRowCol.row || grid.cellNav.lastRowCol.col !== newRowCol.col || grid.options.enableCellEditOnFocus) { + grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol, originEvt); + grid.cellNav.lastRowCol = newRowCol; + } + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells && modifierDown) { + grid.cellNav.focusedCells.push(rowCol); + } else { + grid.cellNav.focusedCells = [rowCol]; + } + } else if (grid.options.modifierKeysToMultiSelectCells && modifierDown && + rowColSelectIndex >= 0) { + + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + } + }; + + uiGridCtrl.cellNav.handleKeyDown = function (evt) { + var direction = uiGridCellNavService.getDirection(evt); + if (direction === null) { + return null; + } + + var containerId = 'body'; + if (evt.uiGridTargetRenderContainerId) { + containerId = evt.uiGridTargetRenderContainerId; + } + + // Get the last-focused row+col combo + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol) { + // Figure out which new row+combo we're navigating to + var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col); + var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols(); + var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol); + // Shift+tab on top-left cell should exit cellnav on render container + if ( + // Navigating left + direction === uiGridCellNavConstants.direction.LEFT && + // New col is last col (i.e. wrap around) + rowCol.col === focusableCols[focusableCols.length - 1] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + evt.shiftKey + ) { + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; + } + // Tab on bottom-right cell should exit cellnav on render container + else if ( + direction === uiGridCellNavConstants.direction.RIGHT && + // New col is first col (i.e. wrap around) + rowCol.col === focusableCols[0] && + // Staying on same row, which means we're at first row + rowCol.row === lastRowCol.row && + evt.keyCode === uiGridConstants.keymap.TAB && + !evt.shiftKey + ) { + grid.cellNav.focusedCells.splice(rowColSelectIndex, 1); + uiGridCtrl.cellNav.clearFocus(); + return true; + } + + // Scroll to the new cell, if it's not completely visible within the render container's viewport + grid.scrollToIfNecessary(rowCol.row, rowCol.col).then(function () { + uiGridCtrl.cellNav.broadcastCellNav(rowCol, null, evt); + }); + + + evt.stopPropagation(); + evt.preventDefault(); + + return false; + } + }; + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + var usesAria = true; + + // Detect whether we are using ngAria + // (if ngAria module is not used then the stuff inside addAriaLiveRegion + // is not used and provides extra fluff) + try { + angular.module('ngAria'); + } + catch (err) { + usesAria = false; + } + + function addAriaLiveRegion() { + // Thanks to google docs for the inspiration behind how to do this + // XXX: Why is this entire mess nessasary? + // Because browsers take a lot of coercing to get them to read out live regions + // http://www.paciellogroup.com/blog/2012/06/html5-accessibility-chops-aria-rolealert-browser-support/ + var ariaNotifierDomElt = '
    ' + + ' ' + + '
    '; + + var ariaNotifier = $compile(ariaNotifierDomElt)($scope); + $elm.prepend(ariaNotifier); + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown, originEvt) { + /* + * If the cell nav event was because of a focus event then we don't want to + * change the notifier text. + * Reasoning: Voice Over fires a focus events when moving arround the grid. + * If the screen reader is handing the grid nav properly then we don't need to + * use the alert to notify the user of the movement. + * In all other cases we do want a notification event. + */ + if (originEvt && originEvt.type === 'focus') {return;} + + function setNotifyText(text) { + if (text === ariaNotifier.text().trim()) {return;} + ariaNotifier[0].style.clip = 'rect(0px,0px,0px,0px)'; + /* + * This is how google docs handles clearing the div. Seems to work better than setting the text of the div to '' + */ + ariaNotifier[0].innerHTML = ""; + ariaNotifier[0].style.visibility = 'hidden'; + ariaNotifier[0].style.visibility = 'visible'; + if (text !== '') { + ariaNotifier[0].style.clip = 'auto'; + /* + * The space after the text is something that google docs does. + */ + ariaNotifier[0].appendChild(document.createTextNode(text + " ")); + ariaNotifier[0].style.visibility = 'hidden'; + ariaNotifier[0].style.visibility = 'visible'; + } + } + + function getAppendedColumnHeaderText(col) { + return ', ' + i18nService.getSafeText('headerCell.aria.column') + ' ' + col.displayName; + } + + function getCellDisplayValue(currentRowColumn) { + var prefix = ''; + + if (currentRowColumn.col.field === 'selectionRowHeaderCol') { + // This is the case when the 'selection' feature is used in the grid and the user has moved + // to or inside of the left grid container which holds the checkboxes for selecting rows. + // This is necessary for Accessibility. Without this a screen reader cannot determine if the row + // is or is not currently selected. + prefix = (currentRowColumn.row.isSelected ? i18nService.getSafeText('search.aria.selected') : i18nService.getSafeText('search.aria.notSelected')) + ', '; + } + return prefix + grid.getCellDisplayValue(currentRowColumn.row, currentRowColumn.col); + } + + var values = []; + var currentSelection = grid.api.cellNav.getCurrentSelection(); + for (var i = 0; i < currentSelection.length; i++) { + var cellDisplayValue = getCellDisplayValue(currentSelection[i]) + getAppendedColumnHeaderText(currentSelection[i].col); + values.push(cellDisplayValue); + } + setNotifyText(values.toString()); + }); + } + // Only add the ngAria stuff it will be used + if (usesAria) { + addAriaLiveRegion(); + } + } + }; + } + }; + }]); + + module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile','uiGridCellNavConstants', + function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile, uiGridCellNavConstants) { + return { + replace: true, + priority: -99999, // this needs to run very last + require: ['^uiGrid', 'uiGridRenderContainer', '?^uiGridCellnav'], + scope: false, + compile: function () { + return { + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + renderContainerCtrl = controllers[1], + uiGridCellnavCtrl = controllers[2]; + + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = renderContainerCtrl.containerId; + + var grid = uiGridCtrl.grid; + + // run each time a render container is created + uiGridCellNavService.decorateRenderContainers(grid); + + // focusser only created for body + if (containerId !== 'body') { + return; + } + + if (uiGridCtrl.grid.options.modifierKeysToMultiSelectCells) { + $elm.attr('aria-multiselectable', true); + } + else { + $elm.attr('aria-multiselectable', false); + } + + // add an element with no dimensions that can be used to set focus and capture keystrokes + var focuser = $compile('
    ')($scope); + $elm.append(focuser); + + focuser.on('focus', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (rowCol === null) { + rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null); + if (rowCol.row && rowCol.col) { + uiGridCtrl.cellNav.broadcastCellNav(rowCol); + } + } + }); + + uiGridCellnavCtrl.setAriaActivedescendant = function(id) { + $elm.attr('aria-activedescendant', id); + }; + + uiGridCellnavCtrl.removeAriaActivedescendant = function(id) { + if ($elm.attr('aria-activedescendant') === id) { + $elm.attr('aria-activedescendant', ''); + } + }; + + + uiGridCtrl.focus = function () { + gridUtil.focus.byElement(focuser[0]); + // allow for first time grid focus + }; + + var viewPortKeyDownWasRaisedForRowCol = null; + // Bind to keydown events in the render container + focuser.on('keydown', function (evt) { + evt.uiGridTargetRenderContainerId = containerId; + var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + var raiseViewPortKeyDown = uiGridCtrl.grid.options.keyDownOverrides.some(function (override) { + return Object.keys(override).every( function (property) { + return override[property] === evt[property]; + }); + }); + var result = raiseViewPortKeyDown ? null : uiGridCtrl.cellNav.handleKeyDown(evt); + if (result === null) { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol, uiGridCtrl.cellNav.handleKeyDown); + viewPortKeyDownWasRaisedForRowCol = rowCol; + } + }); + // Bind to keypress events in the render container + // keypress events are needed by edit function so the key press + // that initiated an edit is not lost + // must fire the event in a timeout so the editor can + // initialize and subscribe to the event on another event loop + focuser.on('keypress', function (evt) { + if (viewPortKeyDownWasRaisedForRowCol) { + $timeout(function () { + uiGridCtrl.grid.api.cellNav.raise.viewPortKeyPress(evt, viewPortKeyDownWasRaisedForRowCol); + }, 4); + + viewPortKeyDownWasRaisedForRowCol = null; + } + }); + + $scope.$on('$destroy', function() { + // Remove all event handlers associated with this focuser. + focuser.off(); + }); + } + }; + } + }; + }]); + + module.directive('uiGridViewport', + function () { + return { + replace: true, + priority: -99999, // this needs to run very last + require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'], + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + }, + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + renderContainerCtrl = controllers[1]; + + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + var containerId = renderContainerCtrl.containerId; + // no need to process for other containers + if (containerId !== 'body') { + return; + } + + var grid = uiGridCtrl.grid; + + grid.api.core.on.scrollBegin($scope, function () { + + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { + return; + } + + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; + } + + uiGridCtrl.cellNav.clearFocus(); + + }); + + grid.api.core.on.scrollEnd($scope, function (args) { + // Skip if there's no currently-focused cell + var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell(); + if (lastRowCol === null) { + return; + } + + // if not in my container, move on + // todo: worry about horiz scroll + if (!renderContainerCtrl.colContainer.containsColumn(lastRowCol.col)) { + return; + } + + uiGridCtrl.cellNav.broadcastCellNav(lastRowCol); + }); + + grid.api.cellNav.on.navigate($scope, function () { + // focus again because it can be lost + uiGridCtrl.focus(); + }); + } + }; + } + }; + }); + + /** + * @ngdoc directive + * @name ui.grid.cellNav.directive:uiGridCell + * @element div + * @restrict A + * @description Stacks on top of ui.grid.uiGridCell to provide cell navigation + */ + module.directive('uiGridCell', ['$timeout', '$document', 'uiGridCellNavService', 'gridUtil', 'uiGridCellNavConstants', 'uiGridConstants', 'GridRowColumn', + function ($timeout, $document, uiGridCellNavService, gridUtil, uiGridCellNavConstants, uiGridConstants, GridRowColumn) { + return { + priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell + restrict: 'A', + require: ['^uiGrid', '?^uiGridCellnav'], + scope: false, + link: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + uiGridCellnavCtrl = controllers[1]; + // Skip attaching cell-nav specific logic if the directive is not attached above us + if (!uiGridCtrl.grid.api.cellNav) { return; } + + if (!$scope.col.colDef.allowCellFocus) { + return; + } + + // Convinience local variables + var grid = uiGridCtrl.grid; + $scope.focused = false; + + // Make this cell focusable but only with javascript/a mouse click + $elm.attr('tabindex', -1); + + // When a cell is clicked, broadcast a cellNav event saying that this row+col combo is now focused + $elm.find('div').on('click', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), evt.ctrlKey || evt.metaKey, evt); + + evt.stopPropagation(); + $scope.$apply(); + }); + + + /* + * XXX Hack for screen readers. + * This allows the grid to focus using only the screen reader cursor. + * Since the focus event doesn't include key press information we can't use it + * as our primary source of the event. + */ + $elm.on('mousedown', preventMouseDown); + + // turn on and off for edit events + if (uiGridCtrl.grid.api.edit) { + uiGridCtrl.grid.api.edit.on.beginCellEdit($scope, function () { + $elm.off('mousedown', preventMouseDown); + }); + + uiGridCtrl.grid.api.edit.on.afterCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); + + uiGridCtrl.grid.api.edit.on.cancelCellEdit($scope, function () { + $elm.on('mousedown', preventMouseDown); + }); + } + + // In case we created a new row, and we are the new created row by ngRepeat + // then this cell content might have been selected previously + refreshCellFocus(); + + function preventMouseDown(evt) { + // Prevents the foucus event from firing if the click event is already going to fire. + // If both events fire it will cause bouncing behavior. + evt.preventDefault(); + } + + // You can only focus on elements with a tabindex value + $elm.on('focus', function (evt) { + uiGridCtrl.cellNav.broadcastCellNav(new GridRowColumn($scope.row, $scope.col), false, evt); + evt.stopPropagation(); + $scope.$apply(); + }); + + // This event is fired for all cells. If the cell matches, then focus is set + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus); + + // Refresh cell focus when a new row id added to the grid + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) { + // Clear the focus if it's set to avoid the wrong cell getting focused during + // a short period of time (from now until $timeout function executed) + clearFocus(); + + $scope.$applyAsync(refreshCellFocus); + }, [uiGridConstants.dataChange.ROW]); + + function refreshCellFocus() { + var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) { + return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col); + }); + if (isFocused) { + setFocused(); + } else { + clearFocus(); + } + } + + function setFocused() { + if (!$scope.focused) { + var div = $elm.find('div'); + div.addClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', true); + uiGridCellnavCtrl.setAriaActivedescendant($elm.attr('id')); + $scope.focused = true; + } + } + + function clearFocus() { + if ($scope.focused) { + var div = $elm.find('div'); + div.removeClass('ui-grid-cell-focus'); + $elm.attr('aria-selected', false); + uiGridCellnavCtrl.removeAriaActivedescendant($elm.attr('id')); + $scope.focused = false; + } + } + + $scope.$on('$destroy', function () { + dataChangeDereg(); + + // .off withouth paramaters removes all handlers + $elm.find('div').off(); + $elm.off(); + }); + } + }; + }]); +})(); + +(function () { + 'use strict'; + + /** + * @ngdoc object + * @name ui.grid.service:uiGridConstants + * @description Constants for use across many grid features + * + */ + + + angular.module('ui.grid').constant('uiGridConstants', { + LOG_DEBUG_MESSAGES: true, + LOG_WARN_MESSAGES: true, + LOG_ERROR_MESSAGES: true, + CUSTOM_FILTERS: /CUSTOM_FILTERS/g, + COL_FIELD: /COL_FIELD/g, + MODEL_COL_FIELD: /MODEL_COL_FIELD/g, + TOOLTIP: /title=\"TOOLTIP\"/g, + DISPLAY_CELL_TEMPLATE: /DISPLAY_CELL_TEMPLATE/g, + TEMPLATE_REGEXP: /<.+>/, + FUNC_REGEXP: /(\([^)]*\))?$/, + DOT_REGEXP: /\./g, + APOS_REGEXP: /'/g, + BRACKET_REGEXP: /^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/, + COL_CLASS_PREFIX: 'ui-grid-col', + ENTITY_BINDING: '$$this', + events: { + GRID_SCROLL: 'uiGridScroll', + COLUMN_MENU_SHOWN: 'uiGridColMenuShown', + ITEM_DRAGGING: 'uiGridItemDragStart', // For any item being dragged + COLUMN_HEADER_CLICK: 'uiGridColumnHeaderClick' + }, + // copied from http://www.lsauer.com/2011/08/javascript-keymap-keycodes-in-json.html + keymap: { + TAB: 9, + STRG: 17, + CAPSLOCK: 20, + CTRL: 17, + CTRLRIGHT: 18, + CTRLR: 18, + SHIFT: 16, + RETURN: 13, + ENTER: 13, + BACKSPACE: 8, + BCKSP: 8, + ALT: 18, + ALTR: 17, + ALTRIGHT: 17, + SPACE: 32, + WIN: 91, + MAC: 91, + FN: null, + PG_UP: 33, + PG_DOWN: 34, + UP: 38, + DOWN: 40, + LEFT: 37, + RIGHT: 39, + ESC: 27, + DEL: 46, + F1: 112, + F2: 113, + F3: 114, + F4: 115, + F5: 116, + F6: 117, + F7: 118, + F8: 119, + F9: 120, + F10: 121, + F11: 122, + F12: 123 + }, + /** + * @ngdoc object + * @name ASC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + ASC: 'asc', + /** + * @ngdoc object + * @name DESC + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_sort columnDef.sort} and + * {@link ui.grid.class:GridOptions.columnDef#properties_sortDirectionCycle columnDef.sortDirectionCycle} + * to configure the sorting direction of the column + */ + DESC: 'desc', + + + /** + * @ngdoc object + * @name filter + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_filter columnDef.filter} + * to configure filtering on the column + * + * `SELECT` and `INPUT` are used with the `type` property of the filter, the rest are used to specify + * one of the built-in conditions. + * + * Available `condition` options are: + * - `uiGridConstants.filter.STARTS_WITH` + * - `uiGridConstants.filter.ENDS_WITH` + * - `uiGridConstants.filter.CONTAINS` + * - `uiGridConstants.filter.GREATER_THAN` + * - `uiGridConstants.filter.GREATER_THAN_OR_EQUAL` + * - `uiGridConstants.filter.LESS_THAN` + * - `uiGridConstants.filter.LESS_THAN_OR_EQUAL` + * - `uiGridConstants.filter.NOT_EQUAL` + * + * + * Available `type` options are: + * - `uiGridConstants.filter.SELECT` - use a dropdown box for the cell header filter field + * - `uiGridConstants.filter.INPUT` - use a text box for the cell header filter field + */ + filter: { + STARTS_WITH: 2, + ENDS_WITH: 4, + EXACT: 8, + CONTAINS: 16, + GREATER_THAN: 32, + GREATER_THAN_OR_EQUAL: 64, + LESS_THAN: 128, + LESS_THAN_OR_EQUAL: 256, + NOT_EQUAL: 512, + SELECT: 'select', + INPUT: 'input' + }, + + /** + * @ngdoc object + * @name aggregationTypes + * @propertyOf ui.grid.service:uiGridConstants + * @description Used in {@link ui.grid.class:GridOptions.columnDef#properties_aggregationType columnDef.aggregationType} + * to specify the type of built-in aggregation the column should use. + * + * Available options are: + * - `uiGridConstants.aggregationTypes.sum` - add the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.count` - count the number of rows to produce the aggregated value + * - `uiGridConstants.aggregationTypes.avg` - average the values in this column to produce the aggregated value + * - `uiGridConstants.aggregationTypes.min` - use the minimum value in this column as the aggregated value + * - `uiGridConstants.aggregationTypes.max` - use the maximum value in this column as the aggregated value + */ + aggregationTypes: { + sum: 2, + count: 4, + avg: 8, + min: 16, + max: 32 + }, + + /** + * @ngdoc array + * @name CURRENCY_SYMBOLS + * @propertyOf ui.grid.service:uiGridConstants + * @description A list of all presently circulating currency symbols that was copied from + * https://en.wikipedia.org/wiki/Currency_symbol#List_of_presently-circulating_currency_symbols + * + * Can be used on {@link ui.grid.class:rowSorter} to create a number string regex that ignores currency symbols. + */ + CURRENCY_SYMBOLS: ['¤', '؋', 'Ar', 'Ƀ', '฿', 'B/.', 'Br', 'Bs.', 'Bs.F.', 'GH₵', '¢', 'c', 'Ch.', '₡', 'C$', 'D', 'ден', + 'دج', '.د.ب', 'د.ع', 'JD', 'د.ك', 'ل.د', 'дин', 'د.ت', 'د.م.', 'د.إ', 'Db', '$', '₫', 'Esc', '€', 'ƒ', 'Ft', 'FBu', + 'FCFA', 'CFA', 'Fr', 'FRw', 'G', 'gr', '₲', 'h', '₴', '₭', 'Kč', 'kr', 'kn', 'MK', 'ZK', 'Kz', 'K', 'L', 'Le', 'лв', + 'E', 'lp', 'M', 'KM', 'MT', '₥', 'Nfk', '₦', 'Nu.', 'UM', 'T$', 'MOP$', '₱', 'Pt.', '£', 'ج.م.', 'LL', 'LS', 'P', 'Q', + 'q', 'R', 'R$', 'ر.ع.', 'ر.ق', 'ر.س', '៛', 'RM', 'p', 'Rf.', '₹', '₨', 'SRe', 'Rp', '₪', 'Ksh', 'Sh.So.', 'USh', 'S/', + 'SDR', 'сом', '৳ ', 'WS$', '₮', 'VT', '₩', '¥', 'zł'], + + /** + * @ngdoc object + * @name scrollDirection + * @propertyOf ui.grid.service:uiGridConstants + * @description Set on {@link ui.grid.class:Grid#properties_scrollDirection Grid.scrollDirection}, + * to indicate the direction the grid is currently scrolling in + * + * Available options are: + * - `uiGridConstants.scrollDirection.UP` - set when the grid is scrolling up + * - `uiGridConstants.scrollDirection.DOWN` - set when the grid is scrolling down + * - `uiGridConstants.scrollDirection.LEFT` - set when the grid is scrolling left + * - `uiGridConstants.scrollDirection.RIGHT` - set when the grid is scrolling right + * - `uiGridConstants.scrollDirection.NONE` - set when the grid is not scrolling, this is the default + */ + scrollDirection: { + UP: 'up', + DOWN: 'down', + LEFT: 'left', + RIGHT: 'right', + NONE: 'none' + + }, + + /** + * @ngdoc object + * @name dataChange + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.api:PublicApi#methods_notifyDataChange PublicApi.notifyDataChange}, + * {@link ui.grid.class:Grid#methods_callDataChangeCallbacks Grid.callDataChangeCallbacks}, + * and {@link ui.grid.class:Grid#methods_registerDataChangeCallback Grid.registerDataChangeCallback} + * to specify the type of the event(s). + * + * Available options are: + * - `uiGridConstants.dataChange.ALL` - listeners fired on any of these events, fires listeners on all events. + * - `uiGridConstants.dataChange.EDIT` - fired when the data in a cell is edited + * - `uiGridConstants.dataChange.ROW` - fired when a row is added or removed + * - `uiGridConstants.dataChange.COLUMN` - fired when the column definitions are modified + * - `uiGridConstants.dataChange.OPTIONS` - fired when the grid options are modified + */ + dataChange: { + ALL: 'all', + EDIT: 'edit', + ROW: 'row', + COLUMN: 'column', + OPTIONS: 'options' + }, + + /** + * @ngdoc object + * @name scrollbars + * @propertyOf ui.grid.service:uiGridConstants + * @description Used with {@link ui.grid.class:GridOptions#properties_enableHorizontalScrollbar GridOptions.enableHorizontalScrollbar} + * and {@link ui.grid.class:GridOptions#properties_enableVerticalScrollbar GridOptions.enableVerticalScrollbar} + * to specify the scrollbar policy for that direction. + * + * Available options are: + * - `uiGridConstants.scrollbars.NEVER` - never show scrollbars in this direction + * - `uiGridConstants.scrollbars.ALWAYS` - always show scrollbars in this direction + * - `uiGridConstants.scrollbars.WHEN_NEEDED` - shows scrollbars in this direction when needed + */ + + scrollbars: { + NEVER: 0, + ALWAYS: 1, + WHEN_NEEDED: 2 + } + }); + +})(); + +angular.module('ui.grid').directive('uiGridCell', ['$compile', '$parse', 'gridUtil', 'uiGridConstants', function ($compile, $parse, gridUtil, uiGridConstants) { + return { + priority: 0, + scope: false, + require: '?^uiGrid', + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + function compileTemplate() { + var compiledElementFn = $scope.col.compiledElementFn; + + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + } + + // If the grid controller is present, use it to get the compiled cell template function + if (uiGridCtrl && $scope.col.compiledElementFn) { + compileTemplate(); + } + + // No controller, compile the element manually (for unit tests) + else { + if ( uiGridCtrl && !$scope.col.compiledElementFn ) { + $scope.col.getCompiledElementFn() + .then(function (compiledElementFn) { + compiledElementFn($scope, function(clonedElement, scope) { + $elm.append(clonedElement); + }); + }).catch(angular.noop); + } + else { + var html = $scope.col.cellTemplate + .replace(uiGridConstants.MODEL_COL_FIELD, 'row.entity.' + gridUtil.preEval($scope.col.field)) + .replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + var cellElement = $compile(html)($scope); + $elm.append(cellElement); + } + } + }, + post: function($scope, $elm) { + var initColClass = $scope.col.getColClass(false), + classAdded; + + $elm.addClass(initColClass); + + function updateClass( grid ) { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.cellClass)) { + classAdded = $scope.col.cellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.cellClass; + } + contents.addClass(classAdded); + } + + if ($scope.col.cellClass) { + updateClass(); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN, uiGridConstants.dataChange.EDIT]); + + // watch the col and row to see if they change - which would indicate that we've scrolled or sorted or otherwise + // changed the row/col that this cell relates to, and we need to re-evaluate cell classes and maybe other things + function cellChangeFunction( n, o ) { + if ( n !== o ) { + if ( classAdded || $scope.col.cellClass ) { + updateClass(); + } + + // See if the column's internal class has changed + var newColClass = $scope.col.getColClass(false); + + if (newColClass !== initColClass) { + $elm.removeClass(initColClass); + $elm.addClass(newColClass); + initColClass = newColClass; + } + } + } + + // TODO(c0bra): Turn this into a deep array watch + var rowWatchDereg = $scope.$watch( 'row', cellChangeFunction ); + + function deregisterFunction() { + dataChangeDereg(); + rowWatchDereg(); + } + + $scope.$on('$destroy', deregisterFunction); + $elm.on('$destroy', deregisterFunction); + } + }; + } + }; +}]); + +(function() { + +angular.module('ui.grid') +.service('uiGridColumnMenuService', [ 'i18nService', 'uiGridConstants', 'gridUtil', +function ( i18nService, uiGridConstants, gridUtil ) { +/** + * @ngdoc service + * @name ui.grid.service:uiGridColumnMenuService + * + * @description Services for working with column menus, factored out + * to make the code easier to understand + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name initialize + * @description Sets defaults, puts a reference to the $scope on + * the uiGridController + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {controller} uiGridCtrl the uiGridController for the grid + * we're on + * + */ + initialize: function( $scope, uiGridCtrl ) { + $scope.grid = uiGridCtrl.grid; + + // Store a reference to this link/controller in the main uiGrid controller + // to allow showMenu later + uiGridCtrl.columnMenuScope = $scope; + + // Save whether we're shown or not so the columns can check + $scope.menuShown = false; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name setColMenuItemWatch + * @description Setup a watch on $scope.col.menuItems, and update + * menuItems based on this. $scope.col needs to be set by the column + * before calling the menu. + * @param {$scope} $scope the $scope from the uiGridColumnMenu + */ + setColMenuItemWatch: function ( $scope ) { + var deregFunction = $scope.$watch('col.menuItems', function (n) { + if (typeof(n) !== 'undefined' && n && angular.isArray(n)) { + n.forEach(function (item) { + if (typeof(item.context) === 'undefined' || !item.context) { + item.context = {}; + } + item.context.col = $scope.col; + }); + + $scope.menuItems = $scope.defaultMenuItems.concat(n); + } + else { + $scope.menuItems = $scope.defaultMenuItems; + } + }); + + $scope.$on( '$destroy', deregFunction ); + }, + + getGridOption: function( $scope, option ) { + return typeof($scope.grid) !== 'undefined' && $scope.grid && $scope.grid.options && $scope.grid.options[option]; + }, + + /** + * @ngdoc boolean + * @name enableSorting + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When enabled, this setting adds sort + * widgets to the column header, allowing sorting of the data in the individual column. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name sortable + * @description determines whether this column is sortable + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + sortable: function( $scope ) { + return Boolean( this.getGridOption($scope, 'enableSorting') && typeof($scope.col) !== 'undefined' && $scope.col && $scope.col.enableSorting); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name isActiveSort + * @description determines whether the requested sort direction is current active, to + * allow highlighting in the menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {string} direction the direction that we'd have selected for us to be active + * + */ + isActiveSort: function( $scope, direction ) { + return Boolean(typeof($scope.col) !== 'undefined' && typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined' && $scope.col.sort.direction === direction); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name suppressRemoveSort + * @description determines whether we should suppress the removeSort option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + suppressRemoveSort: function( $scope ) { + return Boolean($scope.col && $scope.col.suppressRemoveSort); + }, + + + /** + * @ngdoc boolean + * @name enableHiding + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description (optional) True by default. When set to false, this setting prevents a user from hiding the column + * using the column menu or the grid menu. + */ + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name hideable + * @description determines whether a column can be hidden, by checking the enableHiding columnDef option + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + hideable: function( $scope ) { + return Boolean( + (this.getGridOption($scope, 'enableHiding') && + typeof($scope.col) !== 'undefined' && $scope.col && + ($scope.col.colDef && $scope.col.colDef.enableHiding !== false || !$scope.col.colDef)) || + (!this.getGridOption($scope, 'enableHiding') && $scope.col && $scope.col.colDef && $scope.col.colDef.enableHiding) + ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getDefaultMenuItems + * @description returns the default menu items for a column menu + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * + */ + getDefaultMenuItems: function( $scope ) { + return [ + { + title: function() {return i18nService.getSafeText('sort.ascending');}, + icon: 'ui-grid-icon-sort-alt-up', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.ASC); + }, + shown: function () { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.ASC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.descending');}, + icon: 'ui-grid-icon-sort-alt-down', + action: function($event) { + $event.stopPropagation(); + $scope.sortColumn($event, uiGridConstants.DESC); + }, + shown: function() { + return service.sortable( $scope ); + }, + active: function() { + return service.isActiveSort( $scope, uiGridConstants.DESC); + } + }, + { + title: function() {return i18nService.getSafeText('sort.remove');}, + icon: 'ui-grid-icon-cancel', + action: function ($event) { + $event.stopPropagation(); + $scope.unsortColumn(); + }, + shown: function() { + return service.sortable( $scope ) && + typeof($scope.col) !== 'undefined' && (typeof($scope.col.sort) !== 'undefined' && + typeof($scope.col.sort.direction) !== 'undefined') && $scope.col.sort.direction !== null && + !service.suppressRemoveSort( $scope ); + } + }, + { + title: function() {return i18nService.getSafeText('column.hide');}, + icon: 'ui-grid-icon-cancel', + shown: function() { + return service.hideable( $scope ); + }, + action: function ($event) { + $event.stopPropagation(); + $scope.hideColumn(); + } + } + ]; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name getColumnElementPosition + * @description gets the position information needed to place the column + * menu below the column header + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + * @returns {hash} containing left, top, offset, height, width + * + */ + getColumnElementPosition: function( $scope, column, $columnElement ) { + var positionData = {}; + + positionData.left = $columnElement[0].offsetLeft; + positionData.top = $columnElement[0].offsetTop; + positionData.parentLeft = $columnElement[0].offsetParent.offsetLeft; + + // Get the grid scrollLeft + positionData.offset = 0; + if (column.grid.options.offsetLeft) { + positionData.offset = column.grid.options.offsetLeft; + } + + positionData.height = gridUtil.elementHeight($columnElement, true); + positionData.width = gridUtil.elementWidth($columnElement, true); + + return positionData; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.service:uiGridColumnMenuService + * @name repositionMenu + * @description Reposition the menu below the new column. If the menu has no child nodes + * (i.e. it's not currently visible) then we guess it's width at 100, we'll be called again + * later to fix it + * @param {$scope} $scope the $scope from the uiGridColumnMenu + * @param {GridColumn} column the column we want to position below + * @param {hash} positionData a hash containing left, top, offset, height, width + * @param {element} $elm the column menu element that we want to reposition + * @param {element} $columnElement the column element that we want to reposition underneath + * + */ + repositionMenu: function( $scope, column, positionData, $elm, $columnElement ) { + var menu = $elm[0].querySelectorAll('.ui-grid-menu'); + + // It's possible that the render container of the column we're attaching to is + // offset from the grid (i.e. pinned containers), we need to get the difference in the offsetLeft + // between the render container and the grid + var renderContainerElm = gridUtil.closestElm($columnElement, '.ui-grid-render-container'), + renderContainerOffset = renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left, + containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft; + + // repositionMenu is now always called after it's visible in the DOM, + // allowing us to simply get the width every time the menu is opened + var myWidth = gridUtil.elementWidth(menu, true), + paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10); + + if ( menu.length !== 0 ) { + var mid = menu[0].querySelectorAll('.ui-grid-menu-mid'); + + if ( mid.length !== 0 ) { + // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side + // Get the column menu right padding + paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10); + $scope.lastMenuPaddingRight = paddingRight; + column.lastMenuPaddingRight = paddingRight; + } + } + + var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight; + + if (left < positionData.offset + myWidth) { + left = Math.max(positionData.left - containerScrollLeft + positionData.parentLeft - paddingRight + myWidth, positionData.offset + myWidth); + } + + $elm.css('left', left + 'px'); + $elm.css('top', (positionData.top + positionData.height) + 'px'); + } + }; + return service; +}]) + + +.directive('uiGridColumnMenu', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridColumnMenuService', '$document', +function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $document) { +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridColumnMenu + * @description Provides the column menu framework, leverages uiGridMenu underneath + * + */ + + return { + priority: 0, + scope: true, + require: '^uiGrid', + templateUrl: 'ui-grid/uiGridColumnMenu', + replace: true, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridColumnMenuService.initialize( $scope, uiGridCtrl ); + + $scope.defaultMenuItems = uiGridColumnMenuService.getDefaultMenuItems( $scope ); + + // Set the menu items for use with the column menu. The user can later add additional items via the watch + $scope.menuItems = $scope.defaultMenuItems; + uiGridColumnMenuService.setColMenuItemWatch( $scope ); + + function updateCurrentColStatus(menuShown) { + if ($scope.col) { + $scope.col.menuShown = menuShown; + } + } + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name showMenu + * @description Shows the column menu. If the menu is already displayed it + * calls the menu to ask it to hide (it will animate), then it repositions the menu + * to the right place whilst hidden (it will make an assumption on menu width), + * then it asks the menu to show (it will animate), then it repositions the menu again + * once we can calculate it's size. + * @param {GridColumn} column the column we want to position below + * @param {element} $columnElement the column element we want to position below + */ + $scope.showMenu = function(column, $columnElement, event) { + // Update the menu status for the current column + updateCurrentColStatus(false); + // Swap to this column + $scope.col = column; + updateCurrentColStatus(true); + + // Get the position information for the column element + var colElementPosition = uiGridColumnMenuService.getColumnElementPosition( $scope, column, $columnElement ); + + if ($scope.menuShown) { + // we want to hide, then reposition, then show, but we want to wait for animations + // we set a variable, and then rely on the menu-hidden event to call the reposition and show + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.hideThenShow = true; + + $scope.$broadcast('hide-menu', { originalEvent: event }); + } else { + $scope.menuShown = true; + + $scope.colElement = $columnElement; + $scope.colElementPosition = colElementPosition; + $scope.$broadcast('show-menu', { originalEvent: event }); + } + }; + + + /** + * @ngdoc method + * @methodOf ui.grid.directive:uiGridColumnMenu + * @name hideMenu + * @description Hides the column menu. + * @param {boolean} broadcastTrigger true if we were triggered by a broadcast + * from the menu itself - in which case don't broadcast again as we'll get + * an infinite loop + */ + $scope.hideMenu = function( broadcastTrigger ) { + $scope.menuShown = false; + updateCurrentColStatus(false); + if ( !broadcastTrigger ) { + $scope.$broadcast('hide-menu'); + } + }; + + + $scope.$on('menu-hidden', function() { + var menuItems = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0]; + + $elm[0].removeAttribute('style'); + + if ( $scope.hideThenShow ) { + delete $scope.hideThenShow; + + $scope.$broadcast('show-menu'); + + $scope.menuShown = true; + } else { + $scope.hideMenu( true ); + + if ($scope.col && $scope.col.visible) { + // Focus on the menu button + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + $scope.col.getColClass()+ ' .ui-grid-column-menu-button', $scope.col.grid, false) + .catch(angular.noop); + } + } + + if (menuItems) { + menuItems.onkeydown = null; + angular.forEach(menuItems.children, function removeHandlers(item) { + item.onkeydown = null; + }); + } + }); + + $scope.$on('menu-shown', function() { + $timeout(function() { + uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); + + var hasVisibleMenuItems = $scope.menuItems.some(function (menuItem) { + return menuItem.shown(); + }); + + // automatically set the focus to the first button element in the now open menu. + if (hasVisibleMenuItems) { + gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true) + .catch(angular.noop); + } + + delete $scope.colElementPosition; + delete $scope.columnElement; + addKeydownHandlersToMenu(); + }); + }); + + + /* Column methods */ + $scope.sortColumn = function (event, dir) { + event.stopPropagation(); + + $scope.grid.sortColumn($scope.col, dir, true) + .then(function () { + $scope.grid.refresh(); + $scope.hideMenu(); + }).catch(angular.noop); + }; + + $scope.unsortColumn = function () { + $scope.col.unsort(); + + $scope.grid.refresh(); + $scope.hideMenu(); + }; + + function addKeydownHandlersToMenu() { + var menu = angular.element($elm[0].querySelector('.ui-grid-menu-items'))[0], + menuItems, + visibleMenuItems = []; + + if (menu) { + menu.onkeydown = function closeMenu(event) { + if (event.keyCode === uiGridConstants.keymap.ESC) { + event.preventDefault(); + $scope.hideMenu(); + } + }; + + menuItems = menu.querySelectorAll('.ui-grid-menu-item:not(.ng-hide)'); + angular.forEach(menuItems, function filterVisibleItems(item) { + if (item.offsetParent !== null) { + this.push(item); + } + }, visibleMenuItems); + + if (visibleMenuItems.length) { + if (visibleMenuItems.length === 1) { + visibleMenuItems[0].onkeydown = function singleItemHandler(event) { + circularFocusHandler(event, true); + }; + } else { + visibleMenuItems[0].onkeydown = function firstItemHandler(event) { + circularFocusHandler(event, false, event.shiftKey, visibleMenuItems.length - 1); + }; + visibleMenuItems[visibleMenuItems.length - 1].onkeydown = function lastItemHandler(event) { + circularFocusHandler(event, false, !event.shiftKey, 0); + }; + } + } + } + + function circularFocusHandler(event, isSingleItem, shiftKeyStatus, index) { + if (event.keyCode === uiGridConstants.keymap.TAB) { + if (isSingleItem) { + event.preventDefault(); + } else if (shiftKeyStatus) { + event.preventDefault(); + visibleMenuItems[index].focus(); + } + } + } + } + + // Since we are hiding this column the default hide action will fail so we need to focus somewhere else. + var setFocusOnHideColumn = function() { + $timeout(function() { + // Get the UID of the first + var focusToGridMenu = function() { + return gridUtil.focus.byId('grid-menu', $scope.grid); + }; + + var thisIndex; + $scope.grid.columns.some(function(element, index) { + if (angular.equals(element, $scope.col)) { + thisIndex = index; + return true; + } + }); + + var previousVisibleCol; + // Try and find the next lower or nearest column to focus on + $scope.grid.columns.some(function(element, index) { + if (!element.visible) { + return false; + } // This columns index is below the current column index + else if ( index < thisIndex) { + previousVisibleCol = element; + } // This elements index is above this column index and we haven't found one that is lower + else if ( index > thisIndex && !previousVisibleCol) { + // This is the next best thing + previousVisibleCol = element; + // We've found one so use it. + return true; + } // We've reached an element with an index above this column and the previousVisibleCol variable has been set + else if (index > thisIndex && previousVisibleCol) { + // We are done. + return true; + } + }); + // If found then focus on it + if (previousVisibleCol) { + var colClass = previousVisibleCol.getColClass(); + gridUtil.focus.bySelector($document, '.ui-grid-header-cell.' + colClass+ ' .ui-grid-header-cell-primary-focus', true).then(angular.noop, function(reason) { + if (reason !== 'canceled') { // If this is canceled then don't perform the action + // The fallback action is to focus on the grid menu + return focusToGridMenu(); + } + }).catch(angular.noop); + } else { + // Fallback action to focus on the grid menu + focusToGridMenu(); + } + }); + }; + + $scope.hideColumn = function () { + $scope.col.colDef.visible = false; + $scope.col.visible = false; + + $scope.grid.queueGridRefresh(); + $scope.hideMenu(); + $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + $scope.grid.api.core.raise.columnVisibilityChanged( $scope.col ); + + // We are hiding so the default action of focusing on the button that opened this menu will fail. + setFocusOnHideColumn(); + }; + }, + + controller: ['$scope', function ($scope) { + var self = this; + + $scope.$watch('menuItems', function (n) { + self.menuItems = n; + }); + }] + }; +}]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) { + + return { + compile: function() { + return { + pre: function ($scope, $elm) { + $scope.col.updateFilters = function( filterable ) { + $elm.children().remove(); + if ( filterable ) { + var template = $scope.col.filterHeaderTemplate; + if (template === undefined && $scope.col.providedFilterHeaderTemplate !== '') { + if ($scope.col.filterHeaderTemplatePromise) { + $scope.col.filterHeaderTemplatePromise.then(function () { + template = $scope.col.filterHeaderTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + } + }; + + $scope.$on( '$destroy', function() { + delete $scope.col.filterable; + delete $scope.col.updateFilters; + }); + }, + post: function ($scope, $elm) { + $scope.aria = i18nService.getSafeText('headerCell.aria'); + $scope.removeFilter = function(colFilter, index) { + colFilter.term = null; + // Set the focus to the filter input after the action disables the button + gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index); + }; + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooterCell', ['$timeout', 'gridUtil', 'uiGridConstants', '$compile', + function ($timeout, gridUtil, uiGridConstants, $compile) { + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + replace: true, + require: '^uiGrid', + compile: function compile() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.footerCellTemplate; + + if (template === undefined && $scope.col.providedFooterCellTemplate !== '') { + if ($scope.col.footerCellTemplatePromise) { + $scope.col.footerCellTemplatePromise.then(function () { + template = $scope.col.footerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // $elm.addClass($scope.col.getColClass(false)); + $scope.grid = uiGridCtrl.grid; + + var initColClass = $scope.col.getColClass(false); + + $elm.addClass(initColClass); + + // apply any footerCellClass + var classAdded; + + var updateClass = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.footerCellClass)) { + classAdded = $scope.col.footerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.footerCellClass; + } + contents.addClass(classAdded); + }; + + if ($scope.col.footerCellClass) { + updateClass(); + } + + $scope.col.updateAggregationValue(); + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateClass, [uiGridConstants.dataChange.COLUMN]); + + // listen for visible rows change and update aggregation values + $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); + $scope.grid.api.core.on.rowsRendered( $scope, updateClass ); + $scope.$on( '$destroy', dataChangeDereg ); + } + }; + } + }; + }]); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').directive('uiGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', function ($templateCache, $compile, uiGridConstants, gridUtil, $timeout) { + + return { + restrict: 'EA', + replace: true, + // priority: 1000, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function ($elm, $attrs) { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + containerCtrl.footer = $elm; + + var footerTemplate = $scope.grid.options.footerTemplate; + gridUtil.getTemplate(footerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.append(newElm); + + if (containerCtrl) { + // Inject a reference to the footer viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }).catch(angular.noop); + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-footer link'); + + var grid = uiGridCtrl.grid; + + // Don't animate footer cells + gridUtil.disableAnimations($elm); + + containerCtrl.footer = $elm; + + var footerViewport = $elm[0].getElementsByClassName('ui-grid-footer-viewport')[0]; + if (footerViewport) { + containerCtrl.footerViewport = footerViewport; + } + } + }; + } + }; + }]); + +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridGridFooter', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', + function($templateCache, $compile, uiGridConstants, gridUtil) { + return { + restrict: 'EA', + replace: true, + require: '^uiGrid', + scope: true, + compile: function() { + return { + pre: function($scope, $elm, $attrs, uiGridCtrl) { + $scope.grid = uiGridCtrl.grid; + + var footerTemplate = $scope.grid.options.gridFooterTemplate; + + gridUtil.getTemplate(footerTemplate) + .then(function(contents) { + var template = angular.element(contents), + newElm = $compile(template)($scope); + + $elm.append(newElm); + }).catch(angular.noop); + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', '$rootScope', + function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService, $rootScope) { + // Do stuff after mouse has been down this many ms on the header cell + var mousedownTimeout = 500, + changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa + + return { + priority: 0, + scope: { + col: '=', + row: '=', + renderIndex: '=' + }, + require: ['^uiGrid', '^uiGridRenderContainer'], + replace: true, + compile: function() { + return { + pre: function ($scope, $elm) { + var template = $scope.col.headerCellTemplate; + if (template === undefined && $scope.col.providedHeaderCellTemplate !== '') { + if ($scope.col.headerCellTemplatePromise) { + $scope.col.headerCellTemplatePromise.then(function () { + template = $scope.col.headerCellTemplate; + $elm.append($compile(template)($scope)); + }); + } + } + else { + $elm.append($compile(template)($scope)); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var renderContainerCtrl = controllers[1]; + + $scope.i18n = { + headerCell: i18nService.getSafeText('headerCell'), + sort: i18nService.getSafeText('sort') + }; + $scope.isSortPriorityVisible = function() { + // show sort priority if column is sorted and there is at least one other sorted column + return $scope.col && $scope.col.sort && angular.isNumber($scope.col.sort.priority) && $scope.grid.columns.some(function(element, index) { + return angular.isNumber(element.sort.priority) && element !== $scope.col; + }); + }; + $scope.getSortDirectionAriaLabel = function() { + var col = $scope.col; + // Trying to recreate this sort of thing but it was getting messy having it in the template. + // Sort direction {{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending': 'none')}}. + // {{col.sort.priority ? {{columnPriorityText}} {{col.sort.priority}} : ''} + var label = col.sort && col.sort.direction === uiGridConstants.ASC ? $scope.i18n.sort.ascending : ( col.sort && col.sort.direction === uiGridConstants.DESC ? $scope.i18n.sort.descending : $scope.i18n.sort.none); + + if ($scope.isSortPriorityVisible()) { + label = label + '. ' + $scope.i18n.headerCell.priority + ' ' + (col.sort.priority + 1); + } + return label; + }; + + $scope.grid = uiGridCtrl.grid; + + $scope.renderContainer = uiGridCtrl.grid.renderContainers[renderContainerCtrl.containerId]; + + var initColClass = $scope.col.getColClass(false); + $elm.addClass(initColClass); + + // Hide the menu by default + $scope.menuShown = false; + $scope.col.menuShown = false; + + // Put asc and desc sort directions in scope + $scope.asc = uiGridConstants.ASC; + $scope.desc = uiGridConstants.DESC; + + // Store a reference to menu element + var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); + + + // apply any headerCellClass + var classAdded, + previousMouseX; + + // filter watchers + var filterDeregisters = []; + + + /* + * Our basic approach here for event handlers is that we listen for a down event (mousedown or touchstart). + * Once we have a down event, we need to work out whether we have a click, a drag, or a + * hold. A click would sort the grid (if sortable). A drag would be used by moveable, so + * we ignore it. A hold would open the menu. + * + * So, on down event, we put in place handlers for move and up events, and a timer. If the + * timer expires before we see a move or up, then we have a long press and hence a column menu open. + * If the up happens before the timer, then we have a click, and we sort if the column is sortable. + * If a move happens before the timer, then we are doing column move, so we do nothing, the moveable feature + * will handle it. + * + * To deal with touch enabled devices that also have mice, we only create our handlers when + * we get the down event, and we create the corresponding handlers - if we're touchstart then + * we get touchmove and touchend, if we're mousedown then we get mousemove and mouseup. + * + * We also suppress the click action whilst this is happening - otherwise after the mouseup there + * will be a click event and that can cause the column menu to close + * + */ + $scope.downFn = function( event ) { + event.stopPropagation(); + + if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { + event = event.originalEvent; + } + + // Don't show the menu if it's not the left button + if (event.button && event.button !== 0) { + return; + } + previousMouseX = event.pageX; + + $scope.mousedownStartTime = (new Date()).getTime(); + $scope.mousedownTimeout = $timeout(function() { }, mousedownTimeout); + + $scope.mousedownTimeout.then(function () { + if ( $scope.colMenu ) { + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); + } + }).catch(angular.noop); + + uiGridCtrl.fireEvent(uiGridConstants.events.COLUMN_HEADER_CLICK, {event: event, columnName: $scope.col.colDef.name}); + + $scope.offAllEvents(); + if ( event.type === 'touchstart') { + $document.on('touchend', $scope.upFn); + $document.on('touchmove', $scope.moveFn); + } else if ( event.type === 'mousedown' ) { + $document.on('mouseup', $scope.upFn); + $document.on('mousemove', $scope.moveFn); + } + }; + + $scope.upFn = function( event ) { + event.stopPropagation(); + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + + var mousedownEndTime = (new Date()).getTime(); + var mousedownTime = mousedownEndTime - $scope.mousedownStartTime; + + if (mousedownTime > mousedownTimeout) { + // long click, handled above with mousedown + } + else { + // short click + if ( $scope.sortable ) { + $scope.handleClick(event); + } + } + }; + + $scope.handleKeyDown = function(event) { + if (event.keyCode === 32 || event.keyCode === 13) { + event.preventDefault(); + $scope.handleClick(event); + } + }; + + $scope.moveFn = function( event ) { + // Chrome is known to fire some bogus move events. + var changeValue = event.pageX - previousMouseX; + if ( changeValue === 0 ) { return; } + + // we're a move, so do nothing and leave for column move (if enabled) to take over + $timeout.cancel($scope.mousedownTimeout); + $scope.offAllEvents(); + $scope.onDownEvents(event.type); + }; + + $scope.clickFn = function ( event ) { + event.stopPropagation(); + $contentsElm.off('click', $scope.clickFn); + }; + + + $scope.offAllEvents = function() { + $contentsElm.off('touchstart', $scope.downFn); + $contentsElm.off('mousedown', $scope.downFn); + + $document.off('touchend', $scope.upFn); + $document.off('mouseup', $scope.upFn); + + $document.off('touchmove', $scope.moveFn); + $document.off('mousemove', $scope.moveFn); + + $contentsElm.off('click', $scope.clickFn); + }; + + $scope.onDownEvents = function( type ) { + // If there is a previous event, then wait a while before + // activating the other mode - i.e. if the last event was a touch event then + // don't enable mouse events for a wee while (500ms or so) + // Avoids problems with devices that emulate mouse events when you have touch events + + switch (type) { + case 'touchmove': + case 'touchend': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $timeout(function() { + $contentsElm.on('mousedown', $scope.downFn); + }, changeModeTimeout); + break; + case 'mousemove': + case 'mouseup': + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('mousedown', $scope.downFn); + $timeout(function() { + $contentsElm.on('touchstart', $scope.downFn); + }, changeModeTimeout); + break; + default: + $contentsElm.on('click', $scope.clickFn); + $contentsElm.on('touchstart', $scope.downFn); + $contentsElm.on('mousedown', $scope.downFn); + } + }; + + var setFilter = function (updateFilters) { + if ( updateFilters ) { + if ( typeof($scope.col.updateFilters) !== 'undefined' ) { + $scope.col.updateFilters($scope.col.filterable); + } + + // if column is filterable add a filter watcher + if ($scope.col.filterable) { + $scope.col.filters.forEach( function(filter, i) { + filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { + if (n !== o) { + uiGridCtrl.grid.api.core.raise.filterChanged( $scope.col ); + uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + uiGridCtrl.grid.queueGridRefresh(); + } + })); + }); + $scope.$on('$destroy', function() { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + }); + } else { + filterDeregisters.forEach( function(filterDeregister) { + filterDeregister(); + }); + } + } + }; + + var updateHeaderOptions = function() { + var contents = $elm; + + if ( classAdded ) { + contents.removeClass( classAdded ); + classAdded = null; + } + + if (angular.isFunction($scope.col.headerCellClass)) { + classAdded = $scope.col.headerCellClass($scope.grid, $scope.row, $scope.col, $scope.rowRenderIndex, $scope.colRenderIndex); + } + else { + classAdded = $scope.col.headerCellClass; + } + contents.addClass(classAdded); + + $scope.$applyAsync(function() { + var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ? + $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body']; + $scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu && + $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ]; + }); + + // Figure out whether this column is sortable or not + $scope.sortable = Boolean($scope.col.enableSorting); + + // Figure out whether this column is filterable or not + var oldFilterable = $scope.col.filterable; + $scope.col.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); + + setFilter(oldFilterable !== $scope.col.filterable); + + // figure out whether we support column menus + $scope.colMenu = ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && + $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false); + + /** + * @ngdoc property + * @name enableColumnMenu + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description if column menus are enabled, controls the column menus for this specific + * column (i.e. if gridOptions.enableColumnMenus, then you can control column menus + * using this option. If gridOptions.enableColumnMenus === false then you get no column + * menus irrespective of the value of this option ). Defaults to true. + * + * By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS: + * + *
    +               *  .ui-grid-column-menu-button {
    +               *    display: block;
    +               *  }
    +               * 
    + */ + /** + * @ngdoc property + * @name enableColumnMenus + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description Override for column menus everywhere - if set to false then you get no + * column menus. Defaults to true. + * + */ + + $scope.offAllEvents(); + + if ($scope.sortable || $scope.colMenu) { + $scope.onDownEvents(); + + $scope.$on('$destroy', function () { + $scope.offAllEvents(); + }); + } + }; + + updateHeaderOptions(); + + if ($scope.col.filterContainer === 'columnMenu' && $scope.col.filterable) { + $rootScope.$on('menu-shown', function() { + $scope.$applyAsync(function () { + setFilter($scope.col.filterable); + }); + }); + } + + // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs + var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]); + + $scope.$on( '$destroy', dataChangeDereg ); + + $scope.handleClick = function(event) { + // If the shift key is being held down, add this column to the sort + // Sort this column then rebuild the grid's rows + uiGridCtrl.grid.sortColumn($scope.col, event.shiftKey) + .then(function () { + if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); } + uiGridCtrl.grid.refresh(); + }).catch(angular.noop); + }; + + $scope.headerCellArrowKeyDown = function(event) { + if (event.keyCode === uiGridConstants.keymap.SPACE || event.keyCode === uiGridConstants.keymap.ENTER) { + event.preventDefault(); + $scope.toggleMenu(event); + } + }; + + $scope.toggleMenu = function(event) { + event.stopPropagation(); + + // If the menu is already showing and we're the column the menu is on + if (uiGridCtrl.columnMenuScope.menuShown && uiGridCtrl.columnMenuScope.col === $scope.col) { + // ... hide it + uiGridCtrl.columnMenuScope.hideMenu(); + } + // If the menu is NOT showing or is showing in a different column + else { + // ... show it on our column + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm); + } + }; + } + }; + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridHeader', ['$templateCache', '$compile', 'uiGridConstants', 'gridUtil', '$timeout', 'ScrollEvent', + function($templateCache, $compile, uiGridConstants, gridUtil, $timeout, ScrollEvent) { + var defaultTemplate = 'ui-grid/ui-grid-header', + emptyTemplate = 'ui-grid/ui-grid-no-header'; + + return { + restrict: 'EA', + replace: true, + require: ['^uiGrid', '^uiGridRenderContainer'], + scope: true, + compile: function() { + return { + pre: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0], + containerCtrl = controllers[1]; + + $scope.grid = uiGridCtrl.grid; + $scope.colContainer = containerCtrl.colContainer; + + updateHeaderReferences(); + + var headerTemplate; + if (!$scope.grid.options.showHeader) { + headerTemplate = emptyTemplate; + } + else { + headerTemplate = ($scope.grid.options.headerTemplate) ? $scope.grid.options.headerTemplate : defaultTemplate; + } + + gridUtil.getTemplate(headerTemplate) + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + $elm.replaceWith(newElm); + + // And update $elm to be the new element + $elm = newElm; + + updateHeaderReferences(); + + if (containerCtrl) { + // Inject a reference to the header viewport (if it exists) into the grid controller for use in the horizontal scroll handler below + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + + + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + angular.element(headerViewport).on('scroll', scrollHandler); + $scope.$on('$destroy', function () { + angular.element(headerViewport).off('scroll', scrollHandler); + }); + } + } + + $scope.grid.queueRefresh(); + }).catch(angular.noop); + + function updateHeaderReferences() { + containerCtrl.header = containerCtrl.colContainer.header = $elm; + + var headerCanvases = $elm[0].getElementsByClassName('ui-grid-header-canvas'); + + if (headerCanvases.length > 0) { + containerCtrl.headerCanvas = containerCtrl.colContainer.headerCanvas = headerCanvases[0]; + } + else { + containerCtrl.headerCanvas = null; + } + } + + function scrollHandler() { + if (uiGridCtrl.grid.isScrollingHorizontally) { + return; + } + var newScrollLeft = gridUtil.normalizeScrollLeft(containerCtrl.headerViewport, uiGridCtrl.grid); + var horizScrollPercentage = containerCtrl.colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(uiGridCtrl.grid, null, containerCtrl.colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + uiGridCtrl.grid.scrollContainers(null, scrollEvent); + } + }, + + post: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + // gridUtil.logDebug('ui-grid-header link'); + + var grid = uiGridCtrl.grid; + + // Don't animate header cells + gridUtil.disableAnimations($elm); + + function updateColumnWidths() { + // this styleBuilder always runs after the renderContainer, so we can rely on the column widths + // already being populated correctly + + var columnCache = containerCtrl.colContainer.visibleColumnCache; + + // Build the CSS + // uiGridCtrl.grid.columns.forEach(function (column) { + var ret = ''; + var canvasWidth = 0; + columnCache.forEach(function (column) { + ret = ret + column.getColClassDefinition(); + canvasWidth += column.drawnWidth; + }); + + containerCtrl.colContainer.canvasWidth = canvasWidth; + + // Return the styles back to buildStyles which pops them into the `customStyles` scope variable + return ret; + } + + containerCtrl.header = $elm; + + var headerViewport = $elm[0].getElementsByClassName('ui-grid-header-viewport')[0]; + if (headerViewport) { + containerCtrl.headerViewport = headerViewport; + } + + // todo: remove this if by injecting gridCtrl into unit tests + if (uiGridCtrl) { + uiGridCtrl.grid.registerStyleComputation({ + priority: 15, + func: updateColumnWidths + }); + } + } + }; + } + }; + }]); +})(); + +(function() { + +angular.module('ui.grid') +.service('uiGridGridMenuService', [ 'gridUtil', 'i18nService', 'uiGridConstants', function( gridUtil, i18nService, uiGridConstants ) { + /** + * @ngdoc service + * @name ui.grid.uiGridGridMenuService + * + * @description Methods for working with the grid menu + */ + + var service = { + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name initialize + * @description Sets up the gridMenu. Most importantly, sets our + * scope onto the grid object as grid.gridMenuScope, allowing us + * to operate when passed only the grid. Second most importantly, + * we register the 'addToGridMenu' and 'removeFromGridMenu' methods + * on the core api. + * @param {$scope} $scope the scope of this gridMenu + * @param {Grid} grid the grid to which this gridMenu is associated + */ + initialize: function( $scope, grid ) { + grid.gridMenuScope = $scope; + $scope.grid = grid; + $scope.registeredMenuItems = []; + + // not certain this is needed, but would be bad to create a memory leak + $scope.$on('$destroy', function() { + if ( $scope.grid && $scope.grid.gridMenuScope ) { + $scope.grid.gridMenuScope = null; + } + if ( $scope.grid ) { + $scope.grid = null; + } + if ( $scope.registeredMenuItems ) { + $scope.registeredMenuItems = null; + } + }); + + $scope.registeredMenuItems = []; + + /** + * @ngdoc function + * @name addToGridMenu + * @methodOf ui.grid.api:PublicApi + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} items menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + grid.api.registerMethod( 'core', 'addToGridMenu', service.addToGridMenu ); + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.api:PublicApi + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + grid.api.registerMethod( 'core', 'removeFromGridMenu', service.removeFromGridMenu ); + }, + + + /** + * @ngdoc function + * @name addToGridMenu + * @propertyOf ui.grid.uiGridGridMenuService + * @description add items to the grid menu. Used by features + * to add their menu items if they are enabled, can also be used by + * end users to add menu items. This method has the advantage of allowing + * remove again, which can simplify management of which items are included + * in the menu when. (Noting that in most cases the shown and active functions + * provide a better way to handle visibility of menu items) + * @param {Grid} grid the grid on which we are acting + * @param {array} menuItems menu items in the format as described in the tutorial, with + * the added note that if you want to use remove you must also specify an `id` field, + * which is provided when you want to remove an item. The id should be unique. + * + */ + addToGridMenu: function( grid, menuItems ) { + if ( !angular.isArray( menuItems ) ) { + gridUtil.logError( 'addToGridMenu: menuItems must be an array, and is not, not adding any items'); + } else { + if ( grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems ? grid.gridMenuScope.registeredMenuItems : []; + grid.gridMenuScope.registeredMenuItems = grid.gridMenuScope.registeredMenuItems.concat( menuItems ); + } else { + gridUtil.logError( 'Asked to addToGridMenu, but gridMenuScope not present. Timing issue? Please log issue with ui-grid'); + } + } + }, + + + /** + * @ngdoc function + * @name removeFromGridMenu + * @methodOf ui.grid.uiGridGridMenuService + * @description Remove an item from the grid menu based on a provided id. Assumes + * that the id is unique, removes only the last instance of that id. Does nothing if + * the specified id is not found. If there is no gridMenuScope or registeredMenuItems + * then do nothing silently - the desired result is those menu items not be present and they + * aren't. + * @param {Grid} grid the grid on which we are acting + * @param {string} id the id we'd like to remove from the menu + * + */ + removeFromGridMenu: function( grid, id ) { + var foundIndex = -1; + + if ( grid && grid.gridMenuScope ) { + grid.gridMenuScope.registeredMenuItems.forEach( function( value, index ) { + if ( value.id === id ) { + if (foundIndex > -1) { + gridUtil.logError( 'removeFromGridMenu: found multiple items with the same id, removing only the last' ); + } else { + + foundIndex = index; + } + } + }); + } + + if ( foundIndex > -1 ) { + grid.gridMenuScope.registeredMenuItems.splice( foundIndex, 1 ); + } + }, + + + /** + * @ngdoc array + * @name gridMenuCustomItems + * @propertyOf ui.grid.class:GridOptions + * @description (optional) An array of menu items that should be added to + * the gridMenu. Follow the format documented in the tutorial for column + * menu customisation. The context provided to the action function will + * include context.grid. An alternative if working with dynamic menus is to use the + * provided api - core.addToGridMenu and core.removeFromGridMenu, which handles + * some of the management of items for you. + * + */ + /** + * @ngdoc boolean + * @name gridMenuShowHideColumns + * @propertyOf ui.grid.class:GridOptions + * @description true by default, whether the grid menu should allow hide/show + * of columns + * + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name getMenuItems + * @description Decides the menu items to show in the menu. This is a + * combination of: + * + * - the default menu items that are always included, + * - any menu items that have been provided through the addMenuItem api. These + * are typically added by features within the grid + * - any menu items included in grid.options.gridMenuCustomItems. These can be + * changed dynamically, as they're always recalculated whenever we show the + * menu + * @param {$scope} $scope the scope of this gridMenu, from which we can find all + * the information that we need + * @returns {Array} an array of menu items that can be shown + */ + getMenuItems: function( $scope ) { + var menuItems = [ + // this is where we add any menu items we want to always include + ]; + + if ( $scope.grid.options.gridMenuCustomItems ) { + if ( !angular.isArray( $scope.grid.options.gridMenuCustomItems ) ) { + gridUtil.logError( 'gridOptions.gridMenuCustomItems must be an array, and is not'); + } else { + menuItems = menuItems.concat( $scope.grid.options.gridMenuCustomItems ); + } + } + + var clearFilters = [{ + title: i18nService.getSafeText('gridMenu.clearAllFilters'), + action: function ($event) { + $scope.grid.clearAllFilters(); + }, + shown: function() { + return $scope.grid.options.enableFiltering; + }, + order: 100 + }]; + menuItems = menuItems.concat( clearFilters ); + + menuItems = menuItems.concat( $scope.registeredMenuItems ); + + if ( $scope.grid.options.gridMenuShowHideColumns !== false ) { + menuItems = menuItems.concat( service.showHideColumns( $scope ) ); + } + + menuItems.sort(function(a, b) { + return a.order - b.order; + }); + + return menuItems; + }, + + + /** + * @ngdoc array + * @name gridMenuTitleFilter + * @propertyOf ui.grid.class:GridOptions + * @description (optional) A function that takes a title string + * (usually the col.displayName), and converts it into a display value. The function + * must return either a string or a promise. + * + * Used for internationalization of the grid menu column names - for angular-translate + * you can pass $translate as the function, for i18nService you can pass getSafeText as the + * function + * @example + *
    +     *   gridOptions = {
    +     *     gridMenuTitleFilter: $translate
    +     *   }
    +     * 
    + */ + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name showHideColumns + * @description Adds two menu items for each of the columns in columnDefs. One + * menu item for hide, one menu item for show. Each is visible when appropriate + * (show when column is not visible, hide when column is visible). Each toggles + * the visible property on the columnDef using toggleColumnVisibility + * @param {$scope} $scope of a gridMenu, which contains a reference to the grid + */ + showHideColumns: function( $scope ) { + var showHideColumns = []; + if ( !$scope.grid.options.columnDefs || $scope.grid.options.columnDefs.length === 0 || $scope.grid.columns.length === 0 ) { + return showHideColumns; + } + + function isColumnVisible(colDef) { + return colDef.visible === true || colDef.visible === undefined; + } + + function getColumnIcon(colDef) { + return isColumnVisible(colDef) ? 'ui-grid-icon-ok' : 'ui-grid-icon-cancel'; + } + + $scope.grid.options.gridMenuTitleFilter = $scope.grid.options.gridMenuTitleFilter ? $scope.grid.options.gridMenuTitleFilter : function( title ) { return title; }; + + $scope.grid.options.columnDefs.forEach( function( colDef, index ) { + if ( $scope.grid.options.enableHiding !== false && colDef.enableHiding !== false || colDef.enableHiding ) { + // add hide menu item - shows an OK icon as we only show when column is already visible + var menuItem = { + icon: getColumnIcon(colDef), + action: function($event) { + $event.stopPropagation(); + + service.toggleColumnVisibility( this.context.gridCol ); + + if ($event.target && $event.target.firstChild) { + if (angular.element($event.target)[0].nodeName === 'I') { + $event.target.className = getColumnIcon(this.context.gridCol.colDef); + } + else { + $event.target.firstChild.className = getColumnIcon(this.context.gridCol.colDef); + } + } + }, + shown: function() { + return this.context.gridCol.colDef.enableHiding !== false; + }, + context: { gridCol: $scope.grid.getColumn(colDef.name || colDef.field) }, + leaveOpen: true, + order: 301 + index + }; + service.setMenuItemTitle( menuItem, colDef, $scope.grid ); + showHideColumns.push( menuItem ); + } + }); + + // add header for columns + if ( showHideColumns.length ) { + showHideColumns.unshift({ + title: i18nService.getSafeText('gridMenu.columns'), + order: 300, + templateUrl: 'ui-grid/ui-grid-menu-header-item' + }); + } + + return showHideColumns; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name setMenuItemTitle + * @description Handles the response from gridMenuTitleFilter, adding it directly to the menu + * item if it returns a string, otherwise waiting for the promise to resolve or reject then + * putting the result into the title + * @param {object} menuItem the menuItem we want to put the title on + * @param {object} colDef the colDef from which we can get displayName, name or field + * @param {Grid} grid the grid, from which we can get the options.gridMenuTitleFilter + * + */ + setMenuItemTitle: function( menuItem, colDef, grid ) { + var title = grid.options.gridMenuTitleFilter( colDef.displayName || gridUtil.readableColumnName(colDef.name) || colDef.field ); + + if ( typeof(title) === 'string' ) { + menuItem.title = title; + } else if ( title.then ) { + // must be a promise + menuItem.title = ""; + title.then( function( successValue ) { + menuItem.title = successValue; + }, function( errorValue ) { + menuItem.title = errorValue; + }).catch(angular.noop); + } else { + gridUtil.logError('Expected gridMenuTitleFilter to return a string or a promise, it has returned neither, bad config'); + menuItem.title = 'badconfig'; + } + }, + + /** + * @ngdoc method + * @methodOf ui.grid.uiGridGridMenuService + * @name toggleColumnVisibility + * @description Toggles the visibility of an individual column. Expects to be + * provided a context that has on it a gridColumn, which is the column that + * we'll operate upon. We change the visibility, and refresh the grid as appropriate + * @param {GridColumn} gridCol the column that we want to toggle + * + */ + toggleColumnVisibility: function( gridCol ) { + gridCol.colDef.visible = !( gridCol.colDef.visible === true || gridCol.colDef.visible === undefined ); + + gridCol.grid.refresh(); + gridCol.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + gridCol.grid.api.core.raise.columnVisibilityChanged( gridCol ); + } + }; + + return service; +}]) + +.directive('uiGridMenuButton', ['gridUtil', 'uiGridConstants', 'uiGridGridMenuService', 'i18nService', +function (gridUtil, uiGridConstants, uiGridGridMenuService, i18nService) { + + return { + priority: 0, + scope: true, + require: ['^uiGrid'], + templateUrl: 'ui-grid/ui-grid-menu-button', + replace: true, + + link: function ($scope, $elm, $attrs, controllers) { + var uiGridCtrl = controllers[0]; + + // For the aria label + $scope.i18n = { + aria: i18nService.getSafeText('gridMenu.aria') + }; + + uiGridGridMenuService.initialize($scope, uiGridCtrl.grid); + + $scope.shown = false; + + $scope.toggleOnKeydown = function(event) { + if ( + event.keyCode === uiGridConstants.keymap.ENTER || + event.keyCode === uiGridConstants.keymap.SPACE || + (event.keyCode === uiGridConstants.keymap.ESC && $scope.shown) + ) { + $scope.toggleMenu(); + } + }; + + $scope.toggleMenu = function () { + if ( $scope.shown ) { + $scope.$broadcast('hide-menu'); + $scope.shown = false; + } else { + $scope.menuItems = uiGridGridMenuService.getMenuItems( $scope ); + $scope.$broadcast('show-menu'); + $scope.shown = true; + } + }; + + $scope.$on('menu-hidden', function() { + $scope.shown = false; + gridUtil.focus.bySelector($elm, '.ui-grid-icon-container'); + }); + } + }; +}]); +})(); + +(function() { + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGridMenu + * @element style + * @restrict A + * + * @description + * Allows us to interpolate expressions in ` + I am in a box. + + + + xit('should apply the right class to the element', function () { + element(by.css('.blah')).getCssValue('border-top-width') + .then(function(c) { + expect(c).toContain('1px'); + }); + }); + + + */ + + + angular.module('ui.grid').directive('uiGridStyle', ['gridUtil', '$interpolate', function(gridUtil, $interpolate) { + return { + link: function($scope, $elm) { + var interpolateFn = $interpolate($elm.text(), true); + + if (interpolateFn) { + $scope.$watch(interpolateFn, function(value) { + $elm.text(value); + }); + } + } + }; + }]); +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridViewport', ['gridUtil', 'ScrollEvent', + function(gridUtil, ScrollEvent) { + return { + replace: true, + scope: {}, + controllerAs: 'Viewport', + templateUrl: 'ui-grid/uiGridViewport', + require: ['^uiGrid', '^uiGridRenderContainer'], + link: function($scope, $elm, $attrs, controllers) { + // gridUtil.logDebug('viewport post-link'); + + var uiGridCtrl = controllers[0]; + var containerCtrl = controllers[1]; + + $scope.containerCtrl = containerCtrl; + + var rowContainer = containerCtrl.rowContainer; + var colContainer = containerCtrl.colContainer; + + var grid = uiGridCtrl.grid; + + $scope.grid = uiGridCtrl.grid; + + // Put the containers in scope so we can get rows and columns from them + $scope.rowContainer = containerCtrl.rowContainer; + $scope.colContainer = containerCtrl.colContainer; + + // Register this viewport with its container + containerCtrl.viewport = $elm; + + /** + * @ngdoc function + * @name customScroller + * @methodOf ui.grid.class:GridOptions + * @description (optional) uiGridViewport.on('scroll', scrollHandler) by default. + * A function that allows you to provide your own scroller function. It is particularly helpful if you want to use third party scrollers + * as this allows you to do that. + * + * + *
    Example
    + *
    +           *   $scope.gridOptions = {
    +           *       customScroller: function myScrolling(uiGridViewport, scrollHandler) {
    +           *           uiGridViewport.on('scroll', function myScrollingOverride(event) {
    +           *               // Do something here
    +           *
    +           *               scrollHandler(event);
    +           *           });
    +           *       }
    +           *   };
    +           * 
    + * @param {object} uiGridViewport Element being scrolled. (this gets passed in by the grid). + * @param {function} scrollHandler Function that needs to be called when scrolling happens. (this gets passed in by the grid). + */ + if (grid && grid.options && grid.options.customScroller) { + grid.options.customScroller($elm, scrollHandler); + } else { + $elm.on('scroll', scrollHandler); + } + + var ignoreScroll = false; + + function scrollHandler() { + var newScrollTop = $elm[0].scrollTop; + var newScrollLeft = gridUtil.normalizeScrollLeft($elm, grid); + + var vertScrollPercentage = rowContainer.scrollVertical(newScrollTop); + var horizScrollPercentage = colContainer.scrollHorizontal(newScrollLeft); + + var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.ViewPortScroll); + scrollEvent.newScrollLeft = newScrollLeft; + scrollEvent.newScrollTop = newScrollTop; + if ( horizScrollPercentage > -1 ) { + scrollEvent.x = { percentage: horizScrollPercentage }; + } + + if ( vertScrollPercentage > -1 ) { + scrollEvent.y = { percentage: vertScrollPercentage }; + } + + grid.scrollContainers($scope.$parent.containerId, scrollEvent); + } + + if ($scope.$parent.bindScrollVertical) { + grid.addVerticalScrollSync($scope.$parent.containerId, syncVerticalScroll); + } + + if ($scope.$parent.bindScrollHorizontal) { + grid.addHorizontalScrollSync($scope.$parent.containerId, syncHorizontalScroll); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'header', syncHorizontalHeader); + grid.addHorizontalScrollSync($scope.$parent.containerId + 'footer', syncHorizontalFooter); + } + + function syncVerticalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + $elm[0].scrollTop = scrollEvent.getNewScrollTop(rowContainer,containerCtrl.viewport); + } + + function syncHorizontalScroll(scrollEvent) { + containerCtrl.prevScrollArgs = scrollEvent; + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + $elm[0].scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + + function syncHorizontalHeader(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.headerViewport) { + containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + function syncHorizontalFooter(scrollEvent) { + var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport); + + if (containerCtrl.footerViewport) { + containerCtrl.footerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); + } + } + + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); + }, + controller: ['$scope', function ($scope) { + this.rowStyle = function () { + var rowContainer = $scope.rowContainer; + var colContainer = $scope.colContainer; + + var styles = {}; + + if (rowContainer.currentTopRow !== 0) { + // top offset based on hidden rows count + var translateY = "translateY("+ (rowContainer.currentTopRow * rowContainer.grid.options.rowHeight) +"px)"; + + styles['transform'] = translateY; + styles['-webkit-transform'] = translateY; + styles['-ms-transform'] = translateY; + } + + if (colContainer.currentFirstColumn !== 0) { + if (colContainer.grid.isRTL()) { + styles['margin-right'] = colContainer.columnOffset + 'px'; + } + else { + styles['margin-left'] = colContainer.columnOffset + 'px'; + } + } + + return styles; + }; + }] + }; + } + ]); + +})(); + +(function() { + angular.module('ui.grid') + .directive('uiGridVisible', function uiGridVisibleAction() { + return function($scope, $elm, $attr) { + $scope.$watch($attr.uiGridVisible, function(visible) { + $elm[visible ? 'removeClass' : 'addClass']('ui-grid-invisible'); + }); + }; + }); +})(); + +(function () { + 'use strict'; + + angular.module('ui.grid').controller('uiGridController', ['$scope', '$element', '$attrs', 'gridUtil', '$q', 'uiGridConstants', + 'gridClassFactory', '$parse', '$compile', + function ($scope, $elm, $attrs, gridUtil, $q, uiGridConstants, + gridClassFactory, $parse, $compile) { + // gridUtil.logDebug('ui-grid controller'); + var self = this; + var deregFunctions = []; + + self.grid = gridClassFactory.createGrid($scope.uiGrid); + + // assign $scope.$parent if appScope not already assigned + self.grid.appScope = self.grid.appScope || $scope.$parent; + + $elm.addClass('grid' + self.grid.id); + self.grid.rtl = gridUtil.getStyles($elm[0])['direction'] === 'rtl'; + + + // angular.extend(self.grid.options, ); + + // all properties of grid are available on scope + $scope.grid = self.grid; + + if ($attrs.uiGridColumns) { + deregFunctions.push( $attrs.$observe('uiGridColumns', function(value) { + self.grid.options.columnDefs = angular.isString(value) ? angular.fromJson(value) : value; + self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + + self.grid.refreshCanvas(true); + }).catch(angular.noop); + }) ); + } + + // prevents an error from being thrown when the array is not defined yet and fastWatch is on + function getSize(array) { + return array ? array.length : 0; + } + + // if fastWatch is set we watch only the length and the reference, not every individual object + if (self.grid.options.fastWatch) { + self.uiGrid = $scope.uiGrid; + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watch($scope.uiGrid.data, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { + if ( self.grid.appScope[$scope.uiGrid.data] ) { + return self.grid.appScope[$scope.uiGrid.data].length; + } else { + return undefined; + } + }, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.data); }, function() { dataWatchFunction($scope.uiGrid.data); }) ); + } + deregFunctions.push( $scope.$parent.$watch(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + deregFunctions.push( $scope.$parent.$watch(function() { return getSize($scope.uiGrid.columnDefs); }, function() { columnDefsWatchFunction($scope.uiGrid.columnDefs); }) ); + } else { + if (angular.isString($scope.uiGrid.data)) { + deregFunctions.push( $scope.$parent.$watchCollection($scope.uiGrid.data, dataWatchFunction) ); + } else { + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.data; }, dataWatchFunction) ); + } + deregFunctions.push( $scope.$parent.$watchCollection(function() { return $scope.uiGrid.columnDefs; }, columnDefsWatchFunction) ); + } + + + function columnDefsWatchFunction(n, o) { + if (n && n !== o) { + self.grid.options.columnDefs = $scope.uiGrid.columnDefs; + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.COLUMN, { + orderByColumnDefs: true, + preCompileCellTemplates: true + }); + } + } + + var mostRecentData; + + function dataWatchFunction(newData) { + // gridUtil.logDebug('dataWatch fired'); + var promises = []; + + if ( self.grid.options.fastWatch ) { + if (angular.isString($scope.uiGrid.data)) { + newData = self.grid.appScope.$eval($scope.uiGrid.data); + } else { + newData = $scope.uiGrid.data; + } + } + + mostRecentData = newData; + + if (newData) { + // columns length is greater than the number of row header columns, which don't count because they're created automatically + var hasColumns = self.grid.columns.length > (self.grid.rowHeaderColumns ? self.grid.rowHeaderColumns.length : 0); + + if ( + // If we have no columns + !hasColumns && + // ... and we don't have a ui-grid-columns attribute, which would define columns for us + !$attrs.uiGridColumns && + // ... and we have no pre-defined columns + self.grid.options.columnDefs.length === 0 && + // ... but we DO have data + newData.length > 0 + ) { + // ... then build the column definitions from the data that we have + self.grid.buildColumnDefsFromData(newData); + } + + // If we haven't built columns before and either have some columns defined or some data defined + if (!hasColumns && (self.grid.options.columnDefs.length > 0 || newData.length > 0)) { + // Build the column set, then pre-compile the column cell templates + promises.push(self.grid.buildColumns() + .then(function() { + self.grid.preCompileCellTemplates(); + }).catch(angular.noop)); + } + + $q.all(promises).then(function() { + // use most recent data, rather than the potentially outdated data passed into watcher handler + self.grid.modifyRows(mostRecentData) + .then(function () { + // if (self.viewport) { + self.grid.redrawInPlace(true); + // } + + $scope.$evalAsync(function() { + self.grid.refreshCanvas(true); + self.grid.callDataChangeCallbacks(uiGridConstants.dataChange.ROW); + }); + }).catch(angular.noop); + }).catch(angular.noop); + } + } + + var styleWatchDereg = $scope.$watch(function () { return self.grid.styleComputations; }, function() { + self.grid.refreshCanvas(true); + }); + + $scope.$on('$destroy', function() { + deregFunctions.forEach( function( deregFn ) { deregFn(); }); + styleWatchDereg(); + }); + + self.fireEvent = function(eventName, args) { + args = args || {}; + + // Add the grid to the event arguments if it's not there + if (angular.isUndefined(args.grid)) { + args.grid = self.grid; + } + + $scope.$broadcast(eventName, args); + }; + + self.innerCompile = function innerCompile(elm) { + $compile(elm)($scope); + }; + }]); + +/** + * @ngdoc directive + * @name ui.grid.directive:uiGrid + * @element div + * @restrict EA + * @param {Object} uiGrid Options for the grid to use + * + * @description Create a very basic grid. + * + * @example + + + var app = angular.module('app', ['ui.grid']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + }]); + + +
    +
    +
    +
    +
    + */ +angular.module('ui.grid').directive('uiGrid', uiGridDirective); + +uiGridDirective.$inject = ['$window', 'gridUtil', 'uiGridConstants']; +function uiGridDirective($window, gridUtil, uiGridConstants) { + return { + templateUrl: 'ui-grid/ui-grid', + scope: { + uiGrid: '=' + }, + replace: true, + transclude: true, + controller: 'uiGridController', + compile: function () { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + // Initialize scrollbars (TODO: move to controller??) + uiGridCtrl.scrollbars = []; + grid.element = $elm; + + + // See if the grid has a rendered width, if not, wait a bit and try again + var sizeCheckInterval = 100; // ms + var maxSizeChecks = 20; // 2 seconds total + var sizeChecks = 0; + + // Setup (event listeners) the grid + setup(); + + // And initialize it + init(); + + // Mark rendering complete so API events can happen + grid.renderingComplete(); + + // If the grid doesn't have size currently, wait for a bit to see if it gets size + checkSize(); + + /*-- Methods --*/ + + function checkSize() { + // If the grid has no width and we haven't checked more than times, check again in milliseconds + if ($elm[0].offsetWidth <= 0 && sizeChecks < maxSizeChecks) { + setTimeout(checkSize, sizeCheckInterval); + sizeChecks++; + } else { + $scope.$applyAsync(init); + } + } + + // Setup event listeners and watchers + function setup() { + var deregisterLeftWatcher, deregisterRightWatcher; + + // Bind to window resize events + angular.element($window).on('resize', gridResize); + + // Unbind from window resize events when the grid is destroyed + $elm.on('$destroy', function () { + angular.element($window).off('resize', gridResize); + deregisterLeftWatcher(); + deregisterRightWatcher(); + }); + + // If we add a left container after render, we need to watch and react + deregisterLeftWatcher = $scope.$watch(function () { return grid.hasLeftContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + + // If we add a right container after render, we need to watch and react + deregisterRightWatcher = $scope.$watch(function () { return grid.hasRightContainer();}, function (newValue, oldValue) { + if (newValue === oldValue) { + return; + } + grid.refreshCanvas(true); + }); + } + + // Initialize the directive + function init() { + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + + // Default canvasWidth to the grid width, in case we don't get any column definitions to calculate it from + grid.canvasWidth = uiGridCtrl.grid.gridWidth; + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + // If the grid isn't tall enough to fit a single row, it's kind of useless. Resize it to fit a minimum number of rows + if (grid.gridHeight - grid.scrollbarHeight <= grid.options.rowHeight && grid.options.enableMinHeightCheck) { + autoAdjustHeight(); + } + + // Run initial canvas refresh + grid.refreshCanvas(true); + } + + // Set the grid's height ourselves in the case that its height would be unusably small + function autoAdjustHeight() { + // Figure out the new height + var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight; + var headerHeight = grid.options.showHeader ? grid.options.headerRowHeight : 0; + var footerHeight = grid.calcFooterHeight(); + + var scrollbarHeight = 0; + if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) { + scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + var maxNumberOfFilters = 0; + // Calculates the maximum number of filters in the columns + angular.forEach(grid.options.columnDefs, function(col) { + if (col.hasOwnProperty('filter')) { + if (maxNumberOfFilters < 1) { + maxNumberOfFilters = 1; + } + } + else if (col.hasOwnProperty('filters')) { + if (maxNumberOfFilters < col.filters.length) { + maxNumberOfFilters = col.filters.length; + } + } + }); + + if (grid.options.enableFiltering && !maxNumberOfFilters) { + var allColumnsHaveFilteringTurnedOff = grid.options.columnDefs.length && grid.options.columnDefs.every(function(col) { + return col.enableFiltering === false; + }); + + if (!allColumnsHaveFilteringTurnedOff) { + maxNumberOfFilters = 1; + } + } + + var filterHeight = maxNumberOfFilters * headerHeight; + + var newHeight = headerHeight + contentHeight + footerHeight + scrollbarHeight + filterHeight; + + $elm.css('height', newHeight + 'px'); + + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + } + + // Resize the grid on window resize events + function gridResize() { + if (!gridUtil.isVisible($elm)) { + return; + } + grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm); + grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); + + grid.refreshCanvas(true); + } + } + }; + } + }; +} +})(); + +(function() { + 'use strict'; + + angular.module('ui.grid').directive('uiGridPinnedContainer', ['gridUtil', function (gridUtil) { + return { + restrict: 'EA', + replace: true, + template: '
    ' + + '
    ' + + '
    ', + scope: { + side: '=uiGridPinnedContainer' + }, + require: '^uiGrid', + compile: function compile() { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + // gridUtil.logDebug('ui-grid-pinned-container ' + $scope.side + ' link'); + + var grid = uiGridCtrl.grid; + + var myWidth = 0; + + $elm.addClass('ui-grid-pinned-container-' + $scope.side); + + // Monkey-patch the viewport width function + if ($scope.side === 'left' || $scope.side === 'right') { + grid.renderContainers[$scope.side].getViewportWidth = monkeyPatchedGetViewportWidth; + } + + function monkeyPatchedGetViewportWidth() { + /*jshint validthis: true */ + var self = this; + + var viewportWidth = 0; + self.visibleColumnCache.forEach(function (column) { + viewportWidth += column.drawnWidth; + }); + + var adjustment = self.getViewportAdjustment(); + + viewportWidth = viewportWidth + adjustment.width; + + return viewportWidth; + } + + function updateContainerWidth() { + if ($scope.side === 'left' || $scope.side === 'right') { + var cols = grid.renderContainers[$scope.side].visibleColumnCache; + var width = 0; + for (var i = 0; i < cols.length; i++) { + var col = cols[i]; + width += col.drawnWidth || col.width || 0; + } + + return width; + } + } + + function updateContainerDimensions() { + var ret = ''; + + // Column containers + if ($scope.side === 'left' || $scope.side === 'right') { + myWidth = updateContainerWidth(); + + // gridUtil.logDebug('myWidth', myWidth); + + // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it + $elm.attr('style', null); + + // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; + + ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } '; + } + + return ret; + } + + grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { + myWidth = updateContainerWidth(); + + // Subtract our own width + adjustment.width -= myWidth; + adjustment.side = $scope.side; + + return adjustment; + }); + + // Register style computation to adjust for columns in `side`'s render container + grid.registerStyleComputation({ + priority: 15, + func: updateContainerDimensions + }); + } + }; + } + }; + }]); +})(); + +(function () { + angular.module('ui.grid').config(['$provide', function($provide) { + $provide.decorator('i18nService', ['$delegate', function($delegate) { + $delegate.add('en', { + headerCell: { + aria: { + defaultFilterLabel: 'Filter for column', + removeFilter: 'Remove Filter', + columnMenuButtonLabel: 'Column Menu', + column: 'Column' + }, + priority: 'Priority:', + filterLabel: "Filter for column: " + }, + aggregate: { + label: 'items' + }, + groupPanel: { + description: 'Drag a column header here and drop it to group by that column.' + }, + search: { + aria: { + selected: 'Row selected', + notSelected: 'Row not selected' + }, + placeholder: 'Search...', + showingItems: 'Showing Items:', + selectedItems: 'Selected Items:', + totalItems: 'Total Items:', + size: 'Page Size:', + first: 'First Page', + next: 'Next Page', + previous: 'Previous Page', + last: 'Last Page' + }, + selection: { + aria: { + row: 'Row' + }, + selectAll: 'Select All', + displayName: 'Row Selection Checkbox' + }, + menu: { + text: 'Choose Columns:' + }, + sort: { + ascending: 'Sort Ascending', + descending: 'Sort Descending', + none: 'Sort None', + remove: 'Remove Sort' + }, + column: { + hide: 'Hide Column' + }, + aggregation: { + count: 'total rows: ', + sum: 'total: ', + avg: 'avg: ', + min: 'min: ', + max: 'max: ' + }, + pinning: { + pinLeft: 'Pin Left', + pinRight: 'Pin Right', + unpin: 'Unpin' + }, + columnMenu: { + close: 'Close' + }, + gridMenu: { + aria: { + buttonLabel: 'Grid Menu' + }, + columns: 'Columns:', + importerTitle: 'Import file', + exporterAllAsCsv: 'Export all data as csv', + exporterVisibleAsCsv: 'Export visible data as csv', + exporterSelectedAsCsv: 'Export selected data as csv', + exporterAllAsPdf: 'Export all data as pdf', + exporterVisibleAsPdf: 'Export visible data as pdf', + exporterSelectedAsPdf: 'Export selected data as pdf', + exporterAllAsExcel: 'Export all data as excel', + exporterVisibleAsExcel: 'Export visible data as excel', + exporterSelectedAsExcel: 'Export selected data as excel', + clearAllFilters: 'Clear all filters' + }, + importer: { + noHeaders: 'Column names were unable to be derived, does the file have a header?', + noObjects: 'Objects were not able to be derived, was there data in the file other than headers?', + invalidCsv: 'File was unable to be processed, is it valid CSV?', + invalidJson: 'File was unable to be processed, is it valid Json?', + jsonNotArray: 'Imported json file must contain an array, aborting.' + }, + pagination: { + aria: { + pageToFirst: 'Page to first', + pageBack: 'Page back', + pageSelected: 'Selected page', + pageForward: 'Page forward', + pageToLast: 'Page to last' + }, + sizes: 'items per page', + totalItems: 'items', + through: 'through', + of: 'of' + }, + grouping: { + group: 'Group', + ungroup: 'Ungroup', + aggregate_count: 'Agg: Count', + aggregate_sum: 'Agg: Sum', + aggregate_max: 'Agg: Max', + aggregate_min: 'Agg: Min', + aggregate_avg: 'Agg: Avg', + aggregate_remove: 'Agg: Remove' + }, + validate: { + error: 'Error:', + minLength: 'Value should be at least THRESHOLD characters long.', + maxLength: 'Value should be at most THRESHOLD characters long.', + required: 'A value is needed.' + } + }); + return $delegate; + }]); + }]); +})(); + +(function() { + +angular.module('ui.grid') +.factory('Grid', ['$q', '$compile', '$parse', 'gridUtil', 'uiGridConstants', 'GridOptions', 'GridColumn', 'GridRow', 'GridApi', 'rowSorter', 'rowSearcher', 'GridRenderContainer', '$timeout','ScrollEvent', + function($q, $compile, $parse, gridUtil, uiGridConstants, GridOptions, GridColumn, GridRow, GridApi, rowSorter, rowSearcher, GridRenderContainer, $timeout, ScrollEvent) { + + /** + * @ngdoc object + * @name ui.grid.api:PublicApi + * @description Public Api for the core grid features + * + */ + + /** + * @ngdoc function + * @name ui.grid.class:Grid + * @description Grid is the main viewModel. Any properties or methods needed to maintain state are defined in + * this prototype. One instance of Grid is created per Grid directive instance. + * @param {object} options Object map of options to pass into the grid. An 'id' property is expected. + */ + var Grid = function Grid(options) { + var self = this; + // Get the id out of the options, then remove it + if (options !== undefined && typeof(options.id) !== 'undefined' && options.id) { + if (!/^[_a-zA-Z0-9-]+$/.test(options.id)) { + throw new Error("Grid id '" + options.id + '" is invalid. It must follow CSS selector syntax rules.'); + } + } + else { + throw new Error('No ID provided. An ID must be given when creating a grid.'); + } + + self.id = options.id; + delete options.id; + + // Get default options + self.options = GridOptions.initialize( options ); + + /** + * @ngdoc object + * @name appScope + * @propertyOf ui.grid.class:Grid + * @description reference to the application scope (the parent scope of the ui-grid element). Assigned in ui-grid controller + *
    + * use gridOptions.appScopeProvider to override the default assignment of $scope.$parent with any reference + */ + self.appScope = self.options.appScopeProvider; + + self.headerHeight = self.options.headerRowHeight; + + + /** + * @ngdoc object + * @name footerHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total footer height gridFooter + columnFooter + */ + self.footerHeight = self.calcFooterHeight(); + + + /** + * @ngdoc object + * @name columnFooterHeight + * @propertyOf ui.grid.class:Grid + * @description returns the total column footer height + */ + self.columnFooterHeight = self.calcColumnFooterHeight(); + + self.rtl = false; + self.gridHeight = 0; + self.gridWidth = 0; + self.columnBuilders = []; + self.rowBuilders = []; + self.rowsProcessors = []; + self.columnsProcessors = []; + self.styleComputations = []; + self.viewportAdjusters = []; + self.rowHeaderColumns = []; + self.dataChangeCallbacks = {}; + self.verticalScrollSyncCallBackFns = {}; + self.horizontalScrollSyncCallBackFns = {}; + + // self.visibleRowCache = []; + + // Set of 'render' containers for self grid, which can render sets of rows + self.renderContainers = {}; + + // Create a + self.renderContainers.body = new GridRenderContainer('body', self); + + self.cellValueGetterCache = {}; + + // Cached function to use with custom row templates + self.getRowTemplateFn = null; + + + // representation of the rows on the grid. + // these are wrapped references to the actual data rows (options.data) + self.rows = []; + + // represents the columns on the grid + self.columns = []; + + /** + * @ngdoc boolean + * @name isScrollingVertically + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling vertically. Set to false via debounced method + */ + self.isScrollingVertically = false; + + /** + * @ngdoc boolean + * @name isScrollingHorizontally + * @propertyOf ui.grid.class:Grid + * @description set to true when Grid is scrolling horizontally. Set to false via debounced method + */ + self.isScrollingHorizontally = false; + + /** + * @ngdoc property + * @name scrollDirection + * @propertyOf ui.grid.class:Grid + * @description set one of the {@link ui.grid.service:uiGridConstants#properties_scrollDirection uiGridConstants.scrollDirection} + * values (UP, DOWN, LEFT, RIGHT, NONE), which tells us which direction we are scrolling. + * Set to NONE via debounced method + */ + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + + // if true, grid will not respond to any scroll events + self.disableScrolling = false; + + + function vertical (scrollEvent) { + self.isScrollingVertically = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedVertical = gridUtil.debounce(vertical, self.options.scrollDebounce); + var debouncedVerticalMinDelay = gridUtil.debounce(vertical, 0); + + function horizontal (scrollEvent) { + self.isScrollingHorizontally = false; + self.api.core.raise.scrollEnd(scrollEvent); + self.scrollDirection = uiGridConstants.scrollDirection.NONE; + } + + var debouncedHorizontal = gridUtil.debounce(horizontal, self.options.scrollDebounce); + var debouncedHorizontalMinDelay = gridUtil.debounce(horizontal, 0); + + + /** + * @ngdoc function + * @name flagScrollingVertically + * @methodOf ui.grid.class:Grid + * @description sets isScrollingVertically to true and sets it to false in a debounced function + */ + self.flagScrollingVertically = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingVertically = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedVerticalMinDelay(scrollEvent); + } + else { + debouncedVertical(scrollEvent); + } + }; + + /** + * @ngdoc function + * @name flagScrollingHorizontally + * @methodOf ui.grid.class:Grid + * @description sets isScrollingHorizontally to true and sets it to false in a debounced function + */ + self.flagScrollingHorizontally = function(scrollEvent) { + if (!self.isScrollingVertically && !self.isScrollingHorizontally) { + self.api.core.raise.scrollBegin(scrollEvent); + } + self.isScrollingHorizontally = true; + if (self.options.scrollDebounce === 0 || !scrollEvent.withDelay) { + debouncedHorizontalMinDelay(scrollEvent); + } + else { + debouncedHorizontal(scrollEvent); + } + }; + + self.scrollbarHeight = 0; + self.scrollbarWidth = 0; + if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarHeight = gridUtil.getScrollbarWidth(); + } + + if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) { + self.scrollbarWidth = gridUtil.getScrollbarWidth(); + } + + self.api = new GridApi(self); + + /** + * @ngdoc function + * @name refresh + * @methodOf ui.grid.api:PublicApi + * @description Refresh the rendered grid on screen. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + * If you only want to resize the grid, not regenerate all the rows + * and columns, you should consider directly calling refreshCanvas instead. + * + * @param {boolean} [rowsAltered] Optional flag for refreshing when the number of rows has changed + */ + self.api.registerMethod( 'core', 'refresh', this.refresh ); + + /** + * @ngdoc function + * @name queueGridRefresh + * @methodOf ui.grid.api:PublicApi + * @description Request a refresh of the rendered grid on screen, if multiple + * calls to queueGridRefresh are made within a digest cycle only one will execute. + * The refresh method re-runs both the columnProcessors and the + * rowProcessors, as well as calling refreshCanvas to update all + * the grid sizing. In general you should prefer to use queueGridRefresh + * instead, which is basically a debounced version of refresh. + * + */ + self.api.registerMethod( 'core', 'queueGridRefresh', this.queueGridRefresh ); + + /** + * @ngdoc function + * @name refreshRows + * @methodOf ui.grid.api:PublicApi + * @description Runs only the rowProcessors, columns remain as they were. + * It then calls redrawInPlace and refreshCanvas, which adjust the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'refreshRows', this.refreshRows ); + + /** + * @ngdoc function + * @name queueRefresh + * @methodOf ui.grid.api:PublicApi + * @description Requests execution of refreshCanvas, if multiple requests are made + * during a digest cycle only one will run. RefreshCanvas updates the grid sizing. + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'queueRefresh', this.queueRefresh ); + + /** + * @ngdoc function + * @name handleWindowResize + * @methodOf ui.grid.api:PublicApi + * @description Trigger a grid resize, normally this would be picked + * up by a watch on window size, but in some circumstances it is necessary + * to call this manually + * @returns {promise} promise that is resolved when render completes? + * + */ + self.api.registerMethod( 'core', 'handleWindowResize', this.handleWindowResize ); + + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.api:PublicApi + * @description adds a row header column to the grid + * @param {object} column def + * @param {number} order Determines order of header column on grid. Lower order means header + * is positioned to the left of higher order headers + * + */ + self.api.registerMethod( 'core', 'addRowHeaderColumn', this.addRowHeaderColumn ); + + /** + * @ngdoc function + * @name scrollToIfNecessary + * @methodOf ui.grid.api:PublicApi + * @description Scrolls the grid to make a certain row and column combo visible, + * in the case that it is not completely visible on the screen already. + * @param {GridRow} gridRow row to make visible + * @param {GridColumn} gridCol column to make visible + * @returns {promise} a promise that is resolved when scrolling is complete + * + */ + self.api.registerMethod( 'core', 'scrollToIfNecessary', function(gridRow, gridCol) { return self.scrollToIfNecessary(gridRow, gridCol);} ); + + /** + * @ngdoc function + * @name scrollTo + * @methodOf ui.grid.api:PublicApi + * @description Scroll the grid such that the specified + * row and column is in view + * @param {object} rowEntity gridOptions.data[] array instance to make visible + * @param {object} colDef to make visible + * @returns {promise} a promise that is resolved after any scrolling is finished + */ + self.api.registerMethod( 'core', 'scrollTo', function (rowEntity, colDef) { return self.scrollTo(rowEntity, colDef);} ); + + /** + * @ngdoc function + * @name registerRowsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "rows processor" function. When the rows are updated, + * the grid calls each registered "rows processor", which has a chance + * to alter the set of rows (sorting, etc) as long as the count is not + * modified. + * + * @param {function(renderedRowsToProcess, columns )} processorFunction rows processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated rows list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject rows processors at intermediate priorities. Lower priority rowsProcessors run earlier. + * + * At present allRowsVisible is running at 50, sort manipulations running at 60-65, filter is running at 100, + * sort is at 200, grouping and treeview at 400-410, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerRowsProcessor', this.registerRowsProcessor ); + + /** + * @ngdoc function + * @name registerColumnsProcessor + * @methodOf ui.grid.api:PublicApi + * @description + * Register a "columns processor" function. When the columns are updated, + * the grid calls each registered "columns processor", which has a chance + * to alter the set of columns as long as the count is not + * modified. + * + * @param {function(renderedColumnsToProcess, rows )} processorFunction columns processor function, which + * is run in the context of the grid (i.e. this for the function will be the grid), and must + * return the updated columns list, which is passed to the next processor in the chain + * @param {number} priority the priority of this processor. In general we try to do them in 100s to leave room + * for other people to inject columns processors at intermediate priorities. Lower priority columnsProcessors run earlier. + * + * At present allRowsVisible is running at 50, filter is running at 100, sort is at 200, grouping at 400, selectable rows at 500, pagination at 900 (pagination will generally want to be last) + */ + self.api.registerMethod( 'core', 'registerColumnsProcessor', this.registerColumnsProcessor ); + + /** + * @ngdoc function + * @name sortHandleNulls + * @methodOf ui.grid.api:PublicApi + * @description A null handling method that can be used when building custom sort + * functions + * @example + *
    +     *   mySortFn = function(a, b) {
    +     *   var nulls = $scope.gridApi.core.sortHandleNulls(a, b);
    +     *   if ( nulls !== null ) {
    +     *     return nulls;
    +     *   } else {
    +     *     // your code for sorting here
    +     *   };
    +     * 
    + * @param {object} a sort value a + * @param {object} b sort value b + * @returns {number} null if there were no nulls/undefineds, otherwise returns + * a sort value that should be passed back from the sort function + * + */ + self.api.registerMethod( 'core', 'sortHandleNulls', rowSorter.handleNulls ); + + /** + * @ngdoc function + * @name sortChanged + * @methodOf ui.grid.api:PublicApi + * @description The sort criteria on one or more columns has + * changed. Provides as parameters the grid and the output of + * getColumnSorting, which is an array of gridColumns + * that have sorting on them, sorted in priority order. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the grid and an array of + * columns with sorts on them, in priority order. + * + * @example + *
    +     *      gridApi.core.on.sortChanged( $scope, function(grid, sortColumns) {
    +     *        // do something
    +     *      });
    +     * 
    + */ + self.api.registerEvent( 'core', 'sortChanged' ); + + /** + * @ngdoc function + * @name columnVisibilityChanged + * @methodOf ui.grid.api:PublicApi + * @description The visibility of a column has changed, + * the column itself is passed out as a parameter of the event. + * + * @param {$scope} scope The scope of the controller. This is used to deregister this event when the scope is destroyed. + * @param {Function} callBack Will be called when the event is emited. The function passes back the GridCol that has changed. + * + * @example + *
    +     *      gridApi.core.on.columnVisibilityChanged( $scope, function (column) {
    +     *        // do something
    +     *      } );
    +     * 
    + */ + self.api.registerEvent( 'core', 'columnVisibilityChanged' ); + + /** + * @ngdoc method + * @name notifyDataChange + * @methodOf ui.grid.api:PublicApi + * @description Notify the grid that a data or config change has occurred, + * where that change isn't something the grid was otherwise noticing. This + * might be particularly relevant where you've changed values within the data + * and you'd like cell classes to be re-evaluated, or changed config within + * the columnDef and you'd like headerCellClasses to be re-evaluated. + * @param {string} type one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS), which tells us which refreshes to fire. + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + self.api.registerMethod( 'core', 'notifyDataChange', this.notifyDataChange ); + + /** + * @ngdoc method + * @name clearAllFilters + * @methodOf ui.grid.api:PublicApi + * @description Clears all filters and optionally refreshes the visible rows. + * @param {object} refreshRows Defaults to true. + * @param {object} clearConditions Defaults to false. + * @param {object} clearFlags Defaults to false. + * @returns {promise} If `refreshRows` is true, returns a promise of the rows refreshing. + */ + self.api.registerMethod('core', 'clearAllFilters', this.clearAllFilters); + + self.registerDataChangeCallback( self.columnRefreshCallback, [uiGridConstants.dataChange.COLUMN]); + self.registerDataChangeCallback( self.processRowsCallback, [uiGridConstants.dataChange.EDIT]); + self.registerDataChangeCallback( self.updateFooterHeightCallback, [uiGridConstants.dataChange.OPTIONS]); + + self.registerStyleComputation({ + priority: 10, + func: self.getFooterStyles + }); + }; + + Grid.prototype.calcFooterHeight = function () { + if (!this.hasFooter()) { + return 0; + } + + var height = 0; + if (this.options.showGridFooter) { + height += this.options.gridFooterHeight; + } + + height += this.calcColumnFooterHeight(); + + return height; + }; + + Grid.prototype.calcColumnFooterHeight = function () { + var height = 0; + + if (this.options.showColumnFooter) { + height += this.options.columnFooterHeight; + } + + return height; + }; + + Grid.prototype.getFooterStyles = function () { + var style = '.grid' + this.id + ' .ui-grid-footer-aggregates-row { height: ' + this.options.columnFooterHeight + 'px; }'; + style += ' .grid' + this.id + ' .ui-grid-footer-info { height: ' + this.options.gridFooterHeight + 'px; }'; + return style; + }; + + Grid.prototype.hasFooter = function () { + return this.options.showGridFooter || this.options.showColumnFooter; + }; + + /** + * @ngdoc function + * @name isRTL + * @methodOf ui.grid.class:Grid + * @description Returns true if grid is RightToLeft + */ + Grid.prototype.isRTL = function () { + return this.rtl; + }; + + + /** + * @ngdoc function + * @name registerColumnBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates columns from column definitions, the columnbuilders will be called to add + * additional properties to the column. + * @param {function(colDef, col, gridOptions)} columnBuilder function to be called + */ + Grid.prototype.registerColumnBuilder = function registerColumnBuilder(columnBuilder) { + this.columnBuilders.push(columnBuilder); + }; + + /** + * @ngdoc function + * @name buildColumnDefsFromData + * @methodOf ui.grid.class:Grid + * @description Populates columnDefs from the provided data + * @param {function(colDef, col, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.buildColumnDefsFromData = function (dataRows) { + this.options.columnDefs = gridUtil.getColumnsFromData(dataRows, this.options.excludeProperties); + }; + + /** + * @ngdoc function + * @name registerRowBuilder + * @methodOf ui.grid.class:Grid + * @description When the build creates rows from gridOptions.data, the rowBuilders will be called to add + * additional properties to the row. + * @param {function(row, gridOptions)} rowBuilder function to be called + */ + Grid.prototype.registerRowBuilder = function registerRowBuilder(rowBuilder) { + this.rowBuilders.push(rowBuilder); + }; + + /** + * @ngdoc function + * @name registerDataChangeCallback + * @methodOf ui.grid.class:Grid + * @description When a data change occurs, the data change callbacks of the specified type + * will be called. The rules are: + * + * - when the data watch fires, that is considered a ROW change (the data watch only notices + * added or removed rows) + * - when the api is called to inform us of a change, the declared type of that change is used + * - when a cell edit completes, the EDIT callbacks are triggered + * - when the columnDef watch fires, the COLUMN callbacks are triggered + * - when the options watch fires, the OPTIONS callbacks are triggered + * + * For a given event: + * - ALL calls ROW, EDIT, COLUMN, OPTIONS and ALL callbacks + * - ROW calls ROW and ALL callbacks + * - EDIT calls EDIT and ALL callbacks + * - COLUMN calls COLUMN and ALL callbacks + * - OPTIONS calls OPTIONS and ALL callbacks + * + * @param {function(grid)} callback function to be called + * @param {array} types the types of data change you want to be informed of. Values from + * the {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values ( ALL, EDIT, ROW, COLUMN, OPTIONS ). Optional and defaults to ALL + * @returns {function} deregister function - a function that can be called to deregister this callback + */ + Grid.prototype.registerDataChangeCallback = function registerDataChangeCallback(callback, types, _this) { + var self = this, + uid = gridUtil.nextUid(); + + if ( !types ) { + types = [uiGridConstants.dataChange.ALL]; + } + if ( !Array.isArray(types)) { + gridUtil.logError("Expected types to be an array or null in registerDataChangeCallback, value passed was: " + types ); + } + this.dataChangeCallbacks[uid] = { callback: callback, types: types, _this: _this }; + + return function() { + delete self.dataChangeCallbacks[uid]; + }; + }; + + /** + * @ngdoc function + * @name callDataChangeCallbacks + * @methodOf ui.grid.class:Grid + * @description Calls the callbacks based on the type of data change that + * has occurred. Always calls the ALL callbacks, calls the ROW, EDIT, COLUMN and OPTIONS callbacks if the + * event type is matching, or if the type is ALL. + * @param {string} type the type of event that occurred - one of the + * {@link ui.grid.service:uiGridConstants#properties_dataChange uiGridConstants.dataChange} + * values (ALL, ROW, EDIT, COLUMN, OPTIONS) + */ + Grid.prototype.callDataChangeCallbacks = function callDataChangeCallbacks(type, options) { + angular.forEach( this.dataChangeCallbacks, function( callback, uid ) { + if ( callback.types.indexOf( uiGridConstants.dataChange.ALL ) !== -1 || + callback.types.indexOf( type ) !== -1 || + type === uiGridConstants.dataChange.ALL ) { + if (callback._this) { + callback.callback.apply(callback._this, this, options); + } + else { + callback.callback(this, options); + } + } + }, this); + }; + + /** + * @ngdoc function + * @name notifyDataChange + * @methodOf ui.grid.class:Grid + * @description Notifies us that a data change has occurred, used in the public + * api for users to tell us when they've changed data or some other event that + * our watches cannot pick up + * @param {string} type the type of event that occurred - one of the + * uiGridConstants.dataChange values (ALL, ROW, EDIT, COLUMN, OPTIONS) + * + * - ALL: listeners fired on any of these events, fires listeners on all events. + * - ROW: fired when a row is added or removed. + * - EDIT: fired when the data in a cell is edited. + * - COLUMN: fired when the column definitions are modified. + * - OPTIONS: fired when the grid options are modified. + */ + Grid.prototype.notifyDataChange = function notifyDataChange(type) { + var constants = uiGridConstants.dataChange; + + if ( type === constants.ALL || + type === constants.COLUMN || + type === constants.EDIT || + type === constants.ROW || + type === constants.OPTIONS ) { + this.callDataChangeCallbacks( type ); + } + else { + gridUtil.logError("Notified of a data change, but the type was not recognised, so no action taken, type was: " + type); + } + }; + + /** + * @ngdoc function + * @name columnRefreshCallback + * @methodOf ui.grid.class:Grid + * @description refreshes the grid when a column refresh + * is notified, which triggers handling of the visible flag. + * This is called on uiGridConstants.dataChange.COLUMN, and is + * registered as a dataChangeCallback in grid.js + * @param {object} grid The grid object. + * @param {object} options Any options passed into the callback. + */ + Grid.prototype.columnRefreshCallback = function columnRefreshCallback(grid, options) { + grid.buildColumns(options); + grid.queueGridRefresh(); + }; + + /** + * @ngdoc function + * @name processRowsCallback + * @methodOf ui.grid.class:Grid + * @description calls the row processors, specifically + * intended to reset the sorting when an edit is called, + * registered as a dataChangeCallback on uiGridConstants.dataChange.EDIT + * @param {object} grid The grid object. + */ + Grid.prototype.processRowsCallback = function processRowsCallback( grid ) { + grid.queueGridRefresh(); + }; + + + /** + * @ngdoc function + * @name updateFooterHeightCallback + * @methodOf ui.grid.class:Grid + * @description recalculates the footer height, + * registered as a dataChangeCallback on uiGridConstants.dataChange.OPTIONS + * @param {object} grid The grid object. + */ + Grid.prototype.updateFooterHeightCallback = function updateFooterHeightCallback( grid ) { + grid.footerHeight = grid.calcFooterHeight(); + grid.columnFooterHeight = grid.calcColumnFooterHeight(); + }; + + + /** + * @ngdoc function + * @name getColumn + * @methodOf ui.grid.class:Grid + * @description returns a grid column for the column name + * @param {string} name column name + */ + Grid.prototype.getColumn = function getColumn(name) { + var columns = this.columns.filter(function (column) { + return column.colDef.name === name; + }); + + return columns.length > 0 ? columns[0] : null; + }; + + /** + * @ngdoc function + * @name getColDef + * @methodOf ui.grid.class:Grid + * @description returns a grid colDef for the column name + * @param {string} name column.field + */ + Grid.prototype.getColDef = function getColDef(name) { + var colDefs = this.options.columnDefs.filter(function (colDef) { + return colDef.name === name; + }); + return colDefs.length > 0 ? colDefs[0] : null; + }; + + /** + * @ngdoc function + * @name assignTypes + * @methodOf ui.grid.class:Grid + * @description uses the first row of data to assign colDef.type for any types not defined. + */ + /** + * @ngdoc property + * @name type + * @propertyOf ui.grid.class:GridOptions.columnDef + * @description the type of the column, used in sorting. If not provided then the + * grid will guess the type. Add this only if the grid guessing is not to your + * satisfaction. One of: + * - 'string' + * - 'boolean' + * - 'number' + * - 'date' + * - 'object' + * - 'numberStr' + * Note that if you choose date, your dates should be in a javascript date type + * + */ + Grid.prototype.assignTypes = function() { + var self = this; + + self.options.columnDefs.forEach(function (colDef, index) { + // Assign colDef type if not specified + if (!colDef.type) { + var col = new GridColumn(colDef, index, self); + var firstRow = self.rows.length > 0 ? self.rows[0] : null; + if (firstRow) { + colDef.type = gridUtil.guessType(self.getCellValue(firstRow, col)); + } + else { + colDef.type = 'string'; + } + } + }); + }; + + + /** + * @ngdoc function + * @name isRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description returns true if the column is a row Header + * @param {object} column column + */ + Grid.prototype.isRowHeaderColumn = function isRowHeaderColumn(column) { + return this.rowHeaderColumns.indexOf(column) !== -1; + }; + + /** + * @ngdoc function + * @name addRowHeaderColumn + * @methodOf ui.grid.class:Grid + * @description adds a row header column to the grid + * @param {object} colDef Column definition object. + * @param {float} order Number that indicates where the column should be placed in the grid. + * @param {boolean} stopColumnBuild Prevents the buildColumn callback from being triggered. This is useful to improve + * performance of the grid during initial load. + */ + Grid.prototype.addRowHeaderColumn = function addRowHeaderColumn(colDef, order, stopColumnBuild) { + var self = this; + + // default order + if (order === undefined) { + order = 0; + } + + var rowHeaderCol = new GridColumn(colDef, gridUtil.nextUid(), self); + rowHeaderCol.isRowHeader = true; + if (self.isRTL()) { + self.createRightContainer(); + rowHeaderCol.renderContainer = 'right'; + } + else { + self.createLeftContainer(); + rowHeaderCol.renderContainer = 'left'; + } + + // relies on the default column builder being first in array, as it is instantiated + // as part of grid creation + self.columnBuilders[0](colDef,rowHeaderCol,self.options) + .then(function() { + rowHeaderCol.enableFiltering = false; + rowHeaderCol.enableSorting = false; + rowHeaderCol.enableHiding = false; + rowHeaderCol.headerPriority = order; + self.rowHeaderColumns.push(rowHeaderCol); + self.rowHeaderColumns = self.rowHeaderColumns.sort(function (a, b) { + return a.headerPriority - b.headerPriority; + }); + + if (!stopColumnBuild) { + self.buildColumns() + .then(function() { + self.preCompileCellTemplates(); + self.queueGridRefresh(); + }).catch(angular.noop); + } + }).catch(angular.noop); + }; + + /** + * @ngdoc function + * @name getOnlyDataColumns + * @methodOf ui.grid.class:Grid + * @description returns all columns except for rowHeader columns + */ + Grid.prototype.getOnlyDataColumns = function getOnlyDataColumns() { + var self = this, + cols = []; + + self.columns.forEach(function (col) { + if (self.rowHeaderColumns.indexOf(col) === -1) { + cols.push(col); + } + }); + return cols; + }; + + /** + * @ngdoc function + * @name buildColumns + * @methodOf ui.grid.class:Grid + * @description creates GridColumn objects from the columnDefinition. Calls each registered + * columnBuilder to further process the column + * @param {object} opts An object contains options to use when building columns + * + * * **orderByColumnDefs**: defaults to **false**. When true, `buildColumns` will reorder existing columns according to the order within the column definitions. + * + * @returns {Promise} a promise to load any needed column resources + */ + Grid.prototype.buildColumns = function buildColumns(opts) { + var options = { + orderByColumnDefs: false + }; + + angular.extend(options, opts); + + // gridUtil.logDebug('buildColumns'); + var self = this; + var builderPromises = []; + var headerOffset = self.rowHeaderColumns.length; + var i; + + // Remove any columns for which a columnDef cannot be found + // Deliberately don't use forEach, as it doesn't like splice being called in the middle + // Also don't cache columns.length, as it will change during this operation + for (i = 0; i < self.columns.length; i++) { + if (!self.getColDef(self.columns[i].name)) { + self.columns.splice(i, 1); + i--; + } + } + + // add row header columns to the grid columns array _after_ columns without columnDefs have been removed + // rowHeaderColumns is ordered by priority so insert in reverse + for (var j = self.rowHeaderColumns.length - 1; j >= 0; j--) { + self.columns.unshift(self.rowHeaderColumns[j]); + } + + // look at each column def, and update column properties to match. If the column def + // doesn't have a column, then splice in a new gridCol + self.options.columnDefs.forEach(function (colDef, index) { + self.preprocessColDef(colDef); + var col = self.getColumn(colDef.name); + + if (!col) { + col = new GridColumn(colDef, gridUtil.nextUid(), self); + self.columns.splice(index + headerOffset, 0, col); + } + else { + // tell updateColumnDef that the column was pre-existing + col.updateColumnDef(colDef, false); + } + + self.columnBuilders.forEach(function (builder) { + builderPromises.push(builder.call(self, colDef, col, self.options)); + }); + }); + + /*** Reorder columns if necessary ***/ + if (!!options.orderByColumnDefs) { + // Create a shallow copy of the columns as a cache + var columnCache = self.columns.slice(0); + + // We need to allow for the "row headers" when mapping from the column defs array to the columns array + // If we have a row header in columns[0] and don't account for it we'll overwrite it with the column in columnDefs[0] + + // Go through all the column defs, use the shorter of columns length and colDefs.length because if a user has given two columns the same name then + // columns will be shorter than columnDefs. In this situation we'll avoid an error, but the user will still get an unexpected result + var len = Math.min(self.options.columnDefs.length, self.columns.length); + for (i = 0; i < len; i++) { + // If the column at this index has a different name than the column at the same index in the column defs... + if (self.columns[i + headerOffset].name !== self.options.columnDefs[i].name) { + // Replace the one in the cache with the appropriate column + columnCache[i + headerOffset] = self.getColumn(self.options.columnDefs[i].name); + } + else { + // Otherwise just copy over the one from the initial columns + columnCache[i + headerOffset] = self.columns[i + headerOffset]; + } + } + + // Empty out the columns array, non-destructively + self.columns.length = 0; + + // And splice in the updated, ordered columns from the cache + Array.prototype.splice.apply(self.columns, [0, 0].concat(columnCache)); + } + + return $q.all(builderPromises).then(function() { + if (self.rows.length > 0) { + self.assignTypes(); + } + if (options.preCompileCellTemplates) { + self.preCompileCellTemplates(); + } + }).catch(angular.noop); + }; + + Grid.prototype.preCompileCellTemplate = function(col) { + var self = this; + var html = col.cellTemplate.replace(uiGridConstants.MODEL_COL_FIELD, self.getQualifiedColField(col)); + html = html.replace(uiGridConstants.COL_FIELD, 'grid.getCellValue(row, col)'); + + col.compiledElementFn = $compile(html); + + if (col.compiledElementFnDefer) { + col.compiledElementFnDefer.resolve(col.compiledElementFn); + } + }; + +/** + * @ngdoc function + * @name preCompileCellTemplates + * @methodOf ui.grid.class:Grid + * @description precompiles all cell templates + */ + Grid.prototype.preCompileCellTemplates = function() { + var self = this; + self.columns.forEach(function (col) { + if ( col.cellTemplate ) { + self.preCompileCellTemplate( col ); + } else if ( col.cellTemplatePromise ) { + col.cellTemplatePromise.then( function() { + self.preCompileCellTemplate( col ); + }).catch(angular.noop); + } + }); + }; + + /** + * @ngdoc function + * @name getGridQualifiedColField + * @methodOf ui.grid.class:Grid + * @description Returns the $parse-able accessor for a column within its $scope + * @param {GridColumn} col col object + */ + Grid.prototype.getQualifiedColField = function (col) { + var base = 'row.entity'; + if ( col.field === uiGridConstants.ENTITY_BINDING ) { + return base; + } + return gridUtil.preEval(base + '.' + col.field); + }; + + /** + * @ngdoc function + * @name createLeftContainer + * @methodOf ui.grid.class:Grid + * @description creates the left render container if it doesn't already exist + */ + Grid.prototype.createLeftContainer = function() { + if (!this.hasLeftContainer()) { + this.renderContainers.left = new GridRenderContainer('left', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name createRightContainer + * @methodOf ui.grid.class:Grid + * @description creates the right render container if it doesn't already exist + */ + Grid.prototype.createRightContainer = function() { + if (!this.hasRightContainer()) { + this.renderContainers.right = new GridRenderContainer('right', this, { disableColumnOffset: true }); + } + }; + + /** + * @ngdoc function + * @name hasLeftContainer + * @methodOf ui.grid.class:Grid + * @description returns true if leftContainer exists + */ + Grid.prototype.hasLeftContainer = function() { + return this.renderContainers.left !== undefined; + }; + + /** + * @ngdoc function + * @name hasRightContainer + * @methodOf ui.grid.class:Grid + * @description returns true if rightContainer exists + */ + Grid.prototype.hasRightContainer = function() { + return this.renderContainers.right !== undefined; + }; + + + /** + * undocumented function + * @name preprocessColDef + * @methodOf ui.grid.class:Grid + * @description defaults the name property from field to maintain backwards compatibility with 2.x + * validates that name or field is present + */ + Grid.prototype.preprocessColDef = function preprocessColDef(colDef) { + var self = this; + + if (!colDef.field && !colDef.name) { + throw new Error('colDef.name or colDef.field property is required'); + } + + // maintain backwards compatibility with 2.x + // field was required in 2.x. now name is required + if (colDef.name === undefined && colDef.field !== undefined) { + // See if the column name already exists: + var newName = colDef.field, + counter = 2; + while (self.getColumn(newName)) { + newName = colDef.field + counter.toString(); + counter++; + } + colDef.name = newName; + } + }; + + // Return a list of items that exist in the `n` array but not the `o` array. Uses optional property accessors passed as third & fourth parameters + Grid.prototype.newInN = function newInN(o, n, oAccessor, nAccessor) { + var self = this; + + var t = []; + for (var i = 0; i < n.length; i++) { + var nV = nAccessor ? n[i][nAccessor] : n[i]; + + var found = false; + for (var j = 0; j < o.length; j++) { + var oV = oAccessor ? o[j][oAccessor] : o[j]; + if (self.options.rowEquality(nV, oV)) { + found = true; + break; + } + } + if (!found) { + t.push(nV); + } + } + + return t; + }; + + /** + * @ngdoc function + * @name getRow + * @methodOf ui.grid.class:Grid + * @description returns the GridRow that contains the rowEntity + * @param {object} rowEntity the gridOptions.data array element instance + * @param {array} lookInRows [optional] the rows to look in - if not provided then + * looks in grid.rows + */ + Grid.prototype.getRow = function getRow(rowEntity, lookInRows) { + var self = this; + + lookInRows = typeof(lookInRows) === 'undefined' ? self.rows : lookInRows; + + var rows = lookInRows.filter(function (row) { + return self.options.rowEquality(row.entity, rowEntity); + }); + return rows.length > 0 ? rows[0] : null; + }; + + + /** + * @ngdoc function + * @name modifyRows + * @methodOf ui.grid.class:Grid + * @description creates or removes GridRow objects from the newRawData array. Calls each registered + * rowBuilder to further process the row + * @param {array} newRawData Modified set of data + * + * This method aims to achieve three things: + * 1. the resulting rows array is in the same order as the newRawData, we'll call + * rowsProcessors immediately after to sort the data anyway + * 2. if we have row hashing available, we try to use the rowHash to find the row + * 3. no memory leaks - rows that are no longer in newRawData need to be garbage collected + * + * The basic logic flow makes use of the newRawData, oldRows and oldHash, and creates + * the newRows and newHash + * + * ``` + * newRawData.forEach newEntity + * if (hashing enabled) + * check oldHash for newEntity + * else + * look for old row directly in oldRows + * if !oldRowFound // must be a new row + * create newRow + * append to the newRows and add to newHash + * run the processors + * ``` + * + * Rows are identified using the hashKey if configured. If not configured, then rows + * are identified using the gridOptions.rowEquality function + * + * This method is useful when trying to select rows immediately after loading data without + * using a $timeout/$interval, e.g.: + * + * $scope.gridOptions.data = someData; + * $scope.gridApi.grid.modifyRows($scope.gridOptions.data); + * $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]); + * + * OR to persist row selection after data update (e.g. rows selected, new data loaded, want + * originally selected rows to be re-selected)) + */ + Grid.prototype.modifyRows = function modifyRows(newRawData) { + var self = this; + var oldRows = self.rows.slice(0); + var oldRowHash = self.rowHashMap || self.createRowHashMap(); + var allRowsSelected = true; + self.rowHashMap = self.createRowHashMap(); + self.rows.length = 0; + + newRawData.forEach( function( newEntity, i ) { + var newRow, oldRow; + + if ( self.options.enableRowHashing ) { + // if hashing is enabled, then this row will be in the hash if we already know about it + oldRow = oldRowHash.get( newEntity ); + } else { + // otherwise, manually search the oldRows to see if we can find this row + oldRow = self.getRow(newEntity, oldRows); + } + + // update newRow to have an entity + if ( oldRow ) { + newRow = oldRow; + newRow.entity = newEntity; + } + + // if we didn't find the row, it must be new, so create it + if ( !newRow ) { + newRow = self.processRowBuilders(new GridRow(newEntity, i, self)); + } + + self.rows.push( newRow ); + self.rowHashMap.put( newEntity, newRow ); + if (!newRow.isSelected) { + allRowsSelected = false; + } + }); + + if (self.selection && self.rows.length) { + self.selection.selectAll = allRowsSelected; + } + + self.assignTypes(); + + var p1 = $q.when(self.processRowsProcessors(self.rows)) + .then(function (renderableRows) { + return self.setVisibleRows(renderableRows); + }).catch(angular.noop); + + var p2 = $q.when(self.processColumnsProcessors(self.columns)) + .then(function (renderableColumns) { + return self.setVisibleColumns(renderableColumns); + }).catch(angular.noop); + + return $q.all([p1, p2]); + }; + + + /** + * Private Undocumented Method + * @name addRows + * @methodOf ui.grid.class:Grid + * @description adds the newRawData array of rows to the grid and calls all registered + * rowBuilders. this keyword will reference the grid + */ + Grid.prototype.addRows = function addRows(newRawData) { + var self = this, + existingRowCount = self.rows.length; + + for (var i = 0; i < newRawData.length; i++) { + var newRow = self.processRowBuilders(new GridRow(newRawData[i], i + existingRowCount, self)); + + if (self.options.enableRowHashing) { + var found = self.rowHashMap.get(newRow.entity); + if (found) { + found.row = newRow; + } + } + + self.rows.push(newRow); + } + }; + + /** + * @ngdoc function + * @name processRowBuilders + * @methodOf ui.grid.class:Grid + * @description processes all RowBuilders for the gridRow + * @param {GridRow} gridRow reference to gridRow + * @returns {GridRow} the gridRow with all additional behavior added + */ + Grid.prototype.processRowBuilders = function processRowBuilders(gridRow) { + var self = this; + + self.rowBuilders.forEach(function (builder) { + builder.call(self, gridRow, self.options); + }); + + return gridRow; + }; + + /** + * @ngdoc function + * @name registerStyleComputation + * @methodOf ui.grid.class:Grid + * @description registered a styleComputation function + * + * If the function returns a value it will be appended into the grid's `
    " + ); + + + $templateCache.put('ui-grid/uiGridCell', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/uiGridColumnMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridFooterCell', + "
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    " + ); + + + $templateCache.put('ui-grid/uiGridHeaderCell', + "
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
     
    " + ); + + + $templateCache.put('ui-grid/uiGridMenu', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridMenuItem', + "" + ); + + + $templateCache.put('ui-grid/uiGridRenderContainer', + "
    " + ); + + + $templateCache.put('ui-grid/uiGridViewport', + "
    " + ); + + + $templateCache.put('ui-grid/cellEditor', + "
    " + ); + + + $templateCache.put('ui-grid/dropdownEditor', + "
    " + ); + + + $templateCache.put('ui-grid/fileChooserEditor', + "
    " + ); + + + $templateCache.put('ui-grid/emptyBaseLayerContainer', + "
    " + ); + + + $templateCache.put('ui-grid/expandableRow', + "
    " + ); + + + $templateCache.put('ui-grid/expandableRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/expandableScrollFiller', + "
     
    " + ); + + + $templateCache.put('ui-grid/expandableTopRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/csvLink', + "LINK_LABEL" + ); + + + $templateCache.put('ui-grid/importerMenuItem', + "
  • " + ); + + + $templateCache.put('ui-grid/importerMenuItemContainer', + "
    " + ); + + + $templateCache.put('ui-grid/pagination', + "
    0\">/ {{ paginationApi.getTotalPages() }}
    1 && !grid.options.useCustomPagination\">  {{sizesLabel}}
    {{grid.options.paginationPageSize}} {{sizesLabel}}
    0\">{{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    " + ); + + + $templateCache.put('ui-grid/columnResizer', + "
    " + ); + + + $templateCache.put('ui-grid/gridFooterSelectedItems', + "({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})" + ); + + + $templateCache.put('ui-grid/selectionHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeaderButtons', + "
     
    " + ); + + + $templateCache.put('ui-grid/selectionSelectAllButtons', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseExpandAllButtons', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeaderButtons', + "
    -1 }\" tabindex=\"0\" ng-keydown=\"treeButtonKeyDown(row, $event)\" ng-click=\"treeButtonClick(row, $event)\">  
    " + ); + + + $templateCache.put('ui-grid/cellTitleValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/cellTooltipValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + +}]); diff --git a/src/ui-grid.min.css b/src/ui-grid.min.css new file mode 100644 index 0000000000..d242cd1205 --- /dev/null +++ b/src/ui-grid.min.css @@ -0,0 +1,4 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */.ui-grid{border:1px solid #d4d4d4;box-sizing:content-box;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-transform:translateZ(0);-moz-transform:translateZ(0);-o-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0)}.ui-grid-vertical-bar{position:absolute;right:0;width:0}.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar,.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{width:1px}.ui-grid-scrollbar-placeholder{background-color:transparent}.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-header-cell:last-child .ui-grid-vertical-bar{right:-1px;width:1px;background-color:#d4d4d4}.ui-grid-clearfix:before,.ui-grid-clearfix:after{content:"";display:table}.ui-grid-clearfix:after{clear:both}.ui-grid-invisible{visibility:hidden}.ui-grid-contents-wrapper{position:relative;height:100%;width:100%}.ui-grid-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0, 0, 0, 0);border:0}.ui-grid-icon-button{background-color:transparent;border:none;padding:0}.clickable{cursor:pointer}.ui-grid-top-panel-background{background-color:#f3f3f3}.ui-grid-header{border-bottom:1px solid #d4d4d4;box-sizing:border-box}.ui-grid-top-panel{position:relative;overflow:hidden;font-weight:bold;background-color:#f3f3f3;-webkit-border-top-right-radius:-1px;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:-1px;-moz-border-radius-topright:-1px;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:-1px;border-top-right-radius:-1px;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:-1px;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-header-viewport{overflow:hidden}.ui-grid-header-canvas:before,.ui-grid-header-canvas:after{content:"";display:-ms-flexbox;display:flex;line-height:0}.ui-grid-header-canvas:after{clear:both}.ui-grid-header-cell-wrapper{position:relative;display:-ms-flexbox;display:flex;box-sizing:border-box;height:100%;width:100%}.ui-grid-header-cell-row{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap}.ui-grid-header-cell{position:relative;box-sizing:border-box;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:0}.ui-grid-header-cell:last-child{border-right:0}.ui-grid-header-cell .sortable{cursor:pointer}.ui-grid-header-cell .ui-grid-sort-priority-number{margin-left:-8px}.ui-grid-header-cell>div{-ms-flex-basis:100%;flex-basis:100%}.ui-grid-header .ui-grid-vertical-bar{top:0;bottom:0}.ui-grid-column-menu-button{position:absolute;right:1px;top:0}.ui-grid-column-menu-button .ui-grid-icon-angle-down{vertical-align:sub}.ui-grid-header-cell-last-col .ui-grid-cell-contents,.ui-grid-header-cell-last-col .ui-grid-filter-container,.ui-grid-header-cell-last-col .ui-grid-column-menu-button,.ui-grid-header-cell-last-col+.ui-grid-column-resizer.right{margin-right:13px}.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-cell-contents,.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-filter-container,.ui-grid-render-container-right .ui-grid-header-cell-last-col .ui-grid-column-menu-button,.ui-grid-render-container-right .ui-grid-header-cell-last-col+.ui-grid-column-resizer.right{margin-right:28px}.ui-grid-column-menu{position:absolute}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transition:all .04s linear;-moz-transition:all .04s linear;-o-transition:all .04s linear;transition:all .04s linear;display:block !important}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transform:translateY(-100%);-moz-transform:translateY(-100%);-o-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active{-webkit-transform:translateY(0);-moz-transform:translateY(0);-o-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0)}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transition:all .04s linear;-moz-transition:all .04s linear;-o-transition:all .04s linear;transition:all .04s linear;display:block !important}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add.ng-hide-add-active,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove{-webkit-transform:translateY(-100%);-moz-transform:translateY(-100%);-o-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-add,.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid.ng-hide-remove.ng-hide-remove-active{-webkit-transform:translateY(0);-moz-transform:translateY(0);-o-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0)}.ui-grid-filter-container{padding:4px 10px;position:relative}.ui-grid-filter-container .ui-grid-filter-button{position:absolute;top:0;bottom:0;right:0}.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]{position:absolute;top:50%;line-height:32px;margin-top:-16px;right:10px;opacity:.66}.ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]:hover{opacity:1}.ui-grid-filter-container .ui-grid-filter-button-select{position:absolute;top:0;bottom:0;right:0}.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]{position:absolute;top:50%;line-height:32px;margin-top:-16px;right:0px;opacity:.66}.ui-grid-filter-container .ui-grid-filter-button-select [class^="ui-grid-icon"]:hover{opacity:1}input[type="text"].ui-grid-filter-input{box-sizing:border-box;padding:0 18px 0 0;margin:0;width:100%;border:1px solid #d4d4d4;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}input[type="text"].ui-grid-filter-input:hover{border:1px solid #d4d4d4}select.ui-grid-filter-select{padding:0;margin:0;border:0;width:90%;border:1px solid #d4d4d4;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}select.ui-grid-filter-select:hover{border:1px solid #d4d4d4}.ui-grid-filter-cancel-button-hidden select.ui-grid-filter-select{width:100%}.ui-grid-render-container{position:inherit;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-render-container:focus{outline:none}.ui-grid-viewport{min-height:20px;position:relative;overflow-y:scroll;-webkit-overflow-scrolling:touch}.ui-grid-viewport:focus{outline:none !important}.ui-grid-canvas{position:relative;padding-top:1px;min-height:1px}.ui-grid-row{clear:both}.ui-grid-row:nth-child(odd) .ui-grid-cell{background-color:#fdfdfd}.ui-grid-row:nth-child(even) .ui-grid-cell{background-color:#f3f3f3}.ui-grid-row:last-child .ui-grid-cell{border-bottom-color:#d4d4d4;border-bottom-style:solid}.ui-grid-row:hover>[ui-grid-row]>.ui-grid-cell:hover .ui-grid-cell,.ui-grid-row:nth-child(odd):hover .ui-grid-cell,.ui-grid-row:nth-child(even):hover .ui-grid-cell{background-color:#d5eaee}.ui-grid-no-row-overlay{position:absolute;top:0;bottom:0;left:0;right:0;margin:10%;background-color:#f3f3f3;-webkit-border-top-right-radius:0;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:0;border-top-right-radius:0;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:0;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #d4d4d4;font-size:2em;text-align:center}.ui-grid-no-row-overlay>*{position:absolute;display:table;margin:auto 0;width:100%;top:0;bottom:0;left:0;right:0;opacity:.66}.ui-grid-cell{overflow:hidden;float:left;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;box-sizing:border-box}.ui-grid-cell:last-child{border-right:0}.ui-grid-cell-contents{padding:5px;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;white-space:nowrap;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;overflow:hidden;height:100%}.ui-grid-cell-contents-hidden{visibility:hidden;width:0;height:0;display:none}.ui-grid-row .ui-grid-cell.ui-grid-row-header-cell{background-color:#F0F0EE;border-bottom:solid 1px #d4d4d4}.ui-grid-cell-empty{display:inline-block;width:10px;height:10px}.ui-grid-footer-info{padding:5px 10px}.ui-grid-footer-panel-background{background-color:#f3f3f3}.ui-grid-footer-panel{position:relative;border-bottom:1px solid #d4d4d4;border-top:1px solid #d4d4d4;overflow:hidden;font-weight:bold;background-color:#f3f3f3;-webkit-border-top-right-radius:-1px;-webkit-border-bottom-right-radius:0;-webkit-border-bottom-left-radius:0;-webkit-border-top-left-radius:-1px;-moz-border-radius-topright:-1px;-moz-border-radius-bottomright:0;-moz-border-radius-bottomleft:0;-moz-border-radius-topleft:-1px;border-top-right-radius:-1px;border-bottom-right-radius:0;border-bottom-left-radius:0;border-top-left-radius:-1px;-moz-background-clip:padding-box;-webkit-background-clip:padding-box;background-clip:padding-box}.ui-grid-grid-footer{float:left;width:100%}.ui-grid-footer-viewport,.ui-grid-footer-canvas{height:100%}.ui-grid-footer-viewport{overflow:hidden}.ui-grid-footer-canvas{position:relative}.ui-grid-footer-canvas:before,.ui-grid-footer-canvas:after{content:"";display:table;line-height:0}.ui-grid-footer-canvas:after{clear:both}.ui-grid-footer-cell-wrapper{position:relative;display:table;box-sizing:border-box;height:100%}.ui-grid-footer-cell-row{display:table-row}.ui-grid-footer-cell{overflow:hidden;background-color:inherit;border-right:1px solid;border-color:#d4d4d4;box-sizing:border-box;display:table-cell}.ui-grid-footer-cell:last-child{border-right:0}.ui-grid-menu-button{z-index:2;position:absolute;right:0;top:0;background:#f3f3f3;border:0;border-left:1px solid #d4d4d4;border-bottom:1px solid #d4d4d4;cursor:pointer;height:32px;font-weight:normal}.ui-grid-menu-button .ui-grid-icon-container{margin-top:5px;margin-left:2px}.ui-grid-menu-button .ui-grid-menu{right:0}.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid{overflow:scroll}.ui-grid-menu{overflow:hidden;max-width:320px;z-index:2;position:absolute;right:100%;padding:0 10px 20px 10px;cursor:pointer;box-sizing:border-box}.ui-grid-menu-item{width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-grid-menu .ui-grid-menu-inner{background:#fff;border:1px solid #d4d4d4;position:relative;white-space:nowrap;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0}.ui-grid-menu .ui-grid-menu-inner ul{margin:0;padding:0;list-style-type:none}.ui-grid-menu .ui-grid-menu-inner ul li{padding:0}.ui-grid-menu .ui-grid-menu-inner ul li .ui-grid-menu-item{color:#000;min-width:100%;padding:8px;text-align:left;background:transparent;border:none;cursor:default}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item{cursor:pointer}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:hover,.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item:focus{background-color:#b3c4c7}.ui-grid-menu .ui-grid-menu-inner ul li button.ui-grid-menu-item.ui-grid-menu-item-active{background-color:#9cb2b6}.ui-grid-menu .ui-grid-menu-inner ul li:not(:last-child)>.ui-grid-menu-item{border-bottom:1px solid #d4d4d4}.ui-grid-sortarrow{right:5px;position:absolute;width:20px;top:0;bottom:0;background-position:center}.ui-grid-sortarrow.down{-webkit-transform:rotate(180deg);-moz-transform:rotate(180deg);-o-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}@font-face{font-family:'ui-grid';src:url('fonts/ui-grid.eot');src:url('fonts/ui-grid.eot#iefix') format('embedded-opentype'),url('fonts/ui-grid.woff') format('woff'),url('fonts/ui-grid.ttf') format('truetype'),url('fonts/ui-grid.svg?#ui-grid') format('svg');font-weight:normal;font-style:normal}[class^="ui-grid-icon"]:before,[class*=" ui-grid-icon"]:before{font-family:"ui-grid";font-style:normal;font-weight:normal;speak:none;display:inline-block;text-decoration:inherit;width:1em;margin-right:.2em;text-align:center;font-variant:normal;text-transform:none;line-height:1em;margin-left:.2em}.ui-grid-icon-blank::before{width:1em;content:' '}.ui-grid-icon-plus-squared:before{content:'\c350'}.ui-grid-icon-minus-squared:before{content:'\c351'}.ui-grid-icon-search:before{content:'\c352'}.ui-grid-icon-cancel:before{content:'\c353'}.ui-grid-icon-info-circled:before{content:'\c354'}.ui-grid-icon-lock:before{content:'\c355'}.ui-grid-icon-lock-open:before{content:'\c356'}.ui-grid-icon-pencil:before{content:'\c357'}.ui-grid-icon-down-dir:before{content:'\c358'}.ui-grid-icon-up-dir:before{content:'\c359'}.ui-grid-icon-left-dir:before{content:'\c35a'}.ui-grid-icon-right-dir:before{content:'\c35b'}.ui-grid-icon-left-open:before{content:'\c35c'}.ui-grid-icon-right-open:before{content:'\c35d'}.ui-grid-icon-angle-down:before{content:'\c35e'}.ui-grid-icon-filter:before{content:'\c35f'}.ui-grid-icon-sort-alt-up:before{content:'\c360'}.ui-grid-icon-sort-alt-down:before{content:'\c361'}.ui-grid-icon-ok:before{content:'\c362'}.ui-grid-icon-menu:before{content:'\c363'}.ui-grid-icon-indent-left:before{content:'\e800'}.ui-grid-icon-indent-right:before{content:'\e801'}.ui-grid-icon-spin5:before{content:'\ea61'}.ui-grid[dir=rtl] .ui-grid-header-cell,.ui-grid[dir=rtl] .ui-grid-footer-cell,.ui-grid[dir=rtl] .ui-grid-cell{float:right !important}.ui-grid[dir=rtl] .ui-grid-column-menu-button{position:absolute;left:1px;top:0;right:inherit}.ui-grid[dir=rtl] .ui-grid-cell:first-child,.ui-grid[dir=rtl] .ui-grid-header-cell:first-child,.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child{border-right:0}.ui-grid[dir=rtl] .ui-grid-cell:last-child,.ui-grid[dir=rtl] .ui-grid-header-cell:last-child{border-right:1px solid #d4d4d4;border-left:0}.ui-grid[dir=rtl] .ui-grid-header-cell:first-child .ui-grid-vertical-bar,.ui-grid[dir=rtl] .ui-grid-footer-cell:first-child .ui-grid-vertical-bar,.ui-grid[dir=rtl] .ui-grid-cell:first-child .ui-grid-vertical-bar{width:0}.ui-grid[dir=rtl] .ui-grid-menu-button{z-index:2;position:absolute;left:0;right:auto;background:#f3f3f3;border:1px solid #d4d4d4;cursor:pointer;min-height:27px;font-weight:normal}.ui-grid[dir=rtl] .ui-grid-menu-button .ui-grid-menu{left:0;right:auto}.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button{right:initial;left:0}.ui-grid[dir=rtl] .ui-grid-filter-container .ui-grid-filter-button [class^="ui-grid-icon"]{right:initial;left:10px}.ui-grid-animate-spin{-moz-animation:ui-grid-spin 2s infinite linear;-o-animation:ui-grid-spin 2s infinite linear;-webkit-animation:ui-grid-spin 2s infinite linear;animation:ui-grid-spin 2s infinite linear;display:inline-block}@-moz-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-webkit-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-o-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@-ms-keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes ui-grid-spin{0%{-moz-transform:rotate(0deg);-o-transform:rotate(0deg);-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(359deg);-o-transform:rotate(359deg);-webkit-transform:rotate(359deg);transform:rotate(359deg)}}.ui-grid-cell-focus{outline:0;background-color:#b3c4c7}.ui-grid-focuser{position:absolute;left:0;top:0;z-index:-1;width:100%;height:100%}.ui-grid-focuser:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-offscreen{display:block;position:absolute;left:-10000px;top:-10000px;clip:rect(0, 0, 0, 0)}.ui-grid-cell input{border-radius:inherit;padding:0;width:100%;color:inherit;height:auto;font:inherit;outline:none}.ui-grid-cell input:focus{color:inherit;outline:none}.ui-grid-cell input[type="checkbox"]{margin:9px 0 0 6px;width:auto}.ui-grid-cell input.ng-invalid{border:1px solid #fc8f8f}.ui-grid-cell input.ng-valid{border:1px solid #d4d4d4}.ui-grid-viewport .ui-grid-empty-base-layer-container{position:absolute;overflow:hidden;pointer-events:none;z-index:-1}.expandableRow .ui-grid-row:nth-child(odd) .ui-grid-cell{background-color:#fdfdfd}.expandableRow .ui-grid-row:nth-child(even) .ui-grid-cell{background-color:#f3f3f3}.ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell{pointer-events:none}.ui-grid-expandable-buttons-cell i{pointer-events:all}.scrollFiller{float:left;border:1px solid #d4d4d4}.ui-grid-tree-header-row{font-weight:bold !important}.movingColumn{position:absolute;top:0;border:1px solid #d4d4d4;box-shadow:inset 0 0 14px rgba(0,0,0,0.2)}.movingColumn .ui-grid-icon-angle-down{display:none}.ui-grid-pager-panel{display:flex;justify-content:space-between;align-items:center;position:absolute;left:0;bottom:0;width:100%;padding-top:3px;padding-bottom:3px;box-sizing:content-box}.ui-grid-pager-container{float:left}.ui-grid-pager-control{padding:5px 0;display:flex;flex-flow:row nowrap;align-items:center;margin-right:10px;margin-left:10px;min-width:135px;float:left}.ui-grid-pager-control button,.ui-grid-pager-control span,.ui-grid-pager-control input{margin-right:4px}.ui-grid-pager-control button{height:25px;min-width:26px;display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;touch-action:manipulation;cursor:pointer;background:#f3f3f3;border:1px solid #ccc;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#eee}.ui-grid-pager-control button:hover{border-color:#adadad;text-decoration:none}.ui-grid-pager-control button:focus{border-color:#8c8c8c;text-decoration:none;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.ui-grid-pager-control button:active{border-color:#adadad;outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.ui-grid-pager-control button:active:focus{outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.ui-grid-pager-control button:active:hover,.ui-grid-pager-control button:active:focus{background-color:#c8c8c8;border-color:#8c8c8c}.ui-grid-pager-control button:hover,.ui-grid-pager-control button:focus,.ui-grid-pager-control button:active{color:#eee;background:#dadada}.ui-grid-pager-control button[disabled]{cursor:not-allowed;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none}.ui-grid-pager-control button[disabled]:hover,.ui-grid-pager-control button[disabled]:focus{background-color:#f3f3f3;border-color:#ccc}.ui-grid-pager-control input{display:inline;height:26px;width:50px;vertical-align:top;color:#555555;background:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.ui-grid-pager-control input:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-pager-control input[disabled],.ui-grid-pager-control input[readonly],.ui-grid-pager-control input::-moz-placeholder{opacity:1}.ui-grid-pager-control input::-moz-placeholder,.ui-grid-pager-control input:-ms-input-placeholder,.ui-grid-pager-control input::-webkit-input-placeholder{color:#999}.ui-grid-pager-control input::-ms-expand{border:0;background-color:transparent}.ui-grid-pager-control input[disabled],.ui-grid-pager-control input[readonly]{background-color:#eeeeee}.ui-grid-pager-control input[disabled]{cursor:not-allowed}.ui-grid-pager-control .ui-grid-pager-max-pages-number{vertical-align:bottom}.ui-grid-pager-control .ui-grid-pager-max-pages-number>*{vertical-align:bottom}.ui-grid-pager-control .ui-grid-pager-max-pages-number abbr{border-bottom:none;text-decoration:none}.ui-grid-pager-control .first-bar{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-left:-3px}.ui-grid-pager-control .first-bar-rtl{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-right:-7px}.ui-grid-pager-control .first-triangle{width:0;height:0;border-style:solid;border-width:5px 8.7px 5px 0;border-color:transparent #4d4d4d transparent transparent;margin-left:2px}.ui-grid-pager-control .next-triangle{margin-left:1px}.ui-grid-pager-control .prev-triangle{margin-left:0}.ui-grid-pager-control .last-triangle{width:0;height:0;border-style:solid;border-width:5px 0 5px 8.7px;border-color:transparent transparent transparent #4d4d4d;margin-left:-1px}.ui-grid-pager-control .last-bar{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-left:1px}.ui-grid-pager-control .last-bar-rtl{width:10px;border-left:2px solid #4d4d4d;margin-top:-6px;height:12px;margin-right:-11px}.ui-grid-pager-row-count-picker{float:left;padding:5px 10px}.ui-grid-pager-row-count-picker select{color:#555555;background:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px;height:25px;width:67px;display:inline;vertical-align:middle}.ui-grid-pager-row-count-picker select:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)}.ui-grid-pager-row-count-picker select[disabled],.ui-grid-pager-row-count-picker select[readonly],.ui-grid-pager-row-count-picker select::-moz-placeholder{opacity:1}.ui-grid-pager-row-count-picker select::-moz-placeholder,.ui-grid-pager-row-count-picker select:-ms-input-placeholder,.ui-grid-pager-row-count-picker select::-webkit-input-placeholder{color:#999}.ui-grid-pager-row-count-picker select::-ms-expand{border:0;background-color:transparent}.ui-grid-pager-row-count-picker select[disabled],.ui-grid-pager-row-count-picker select[readonly]{background-color:#eeeeee}.ui-grid-pager-row-count-picker select[disabled]{cursor:not-allowed}.ui-grid-pager-row-count-picker .ui-grid-pager-row-count-label{margin-top:3px}.ui-grid-pager-count-container{float:right;margin-top:4px;min-width:50px}.ui-grid-pager-count-container .ui-grid-pager-count{margin-right:10px;margin-left:10px;float:right}.ui-grid-pager-count-container .ui-grid-pager-count abbr{border-bottom:none;text-decoration:none}.ui-grid-pinned-container{position:absolute;display:inline;top:0}.ui-grid-pinned-container.ui-grid-pinned-container-left{float:left;left:0}.ui-grid-pinned-container.ui-grid-pinned-container-right{float:right;right:0}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child{box-sizing:border-box;border-right:1px solid;border-width:1px;border-right-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:last-child{box-sizing:border-box;border-right:1px solid;border-width:1px;border-right-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar,.ui-grid-pinned-container .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{width:1px}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-left .ui-grid-header-cell:last-child .ui-grid-vertical-bar{right:-1px;width:1px;background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:first-child{box-sizing:border-box;border-left:1px solid;border-width:1px;border-left-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:first-child{box-sizing:border-box;border-left:1px solid;border-width:1px;border-left-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar,.ui-grid-pinned-container .ui-grid-cell:not(:first-child) .ui-grid-vertical-bar{width:1px}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-header-cell:not(:first-child) .ui-grid-vertical-bar{background-color:#d4d4d4}.ui-grid-pinned-container.ui-grid-pinned-container-right .ui-grid-cell:not(:last-child) .ui-grid-vertical-bar{background-color:#aeaeae}.ui-grid-pinned-container.ui-grid-pinned-container-first .ui-grid-header-cell:first-child .ui-grid-vertical-bar{left:-1px;width:1px;background-color:#aeaeae}.ui-grid-column-resizer{top:0;bottom:0;width:5px;position:absolute;cursor:col-resize}.ui-grid-column-resizer.left{left:0}.ui-grid-column-resizer.right{right:0}.ui-grid-header-cell:last-child .ui-grid-column-resizer.right{border-right:1px solid #d4d4d4}.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.right{border-right:0}.ui-grid[dir=rtl] .ui-grid-header-cell:last-child .ui-grid-column-resizer.left{border-left:1px solid #d4d4d4}.ui-grid.column-resizing{cursor:col-resize;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.ui-grid.column-resizing .ui-grid-resize-overlay{position:absolute;top:0;height:100%;width:1px;background-color:#aeaeae}.ui-grid-row-saving .ui-grid-cell{color:#848484 !important}.ui-grid-row-dirty .ui-grid-cell{color:#610B38}.ui-grid-row-error .ui-grid-cell{color:#FF0000 !important}.ui-grid-row.ui-grid-row-selected>[ui-grid-row]>.ui-grid-cell{background-color:#C9DDE1}.ui-grid-disable-selection{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.ui-grid-selection-row-header-buttons{display:flex;align-items:center;height:100%;cursor:pointer}.ui-grid-selection-row-header-buttons::before{opacity:.1}.ui-grid-selection-row-header-buttons.ui-grid-row-selected::before,.ui-grid-selection-row-header-buttons.ui-grid-all-selected::before{opacity:1}.ui-grid-tree-row-header-buttons.ui-grid-tree-header{cursor:pointer;opacity:1}.ui-grid-tree-header-row{font-weight:bold !important}.ui-grid-tree-header-row .ui-grid-cell.ui-grid-disable-selection.ui-grid-row-header-cell{pointer-events:all}.ui-grid-cell-contents.invalid{border:1px solid #fc8f8f} \ No newline at end of file diff --git a/src/ui-grid.min.js b/src/ui-grid.min.js new file mode 100644 index 0000000000..72bf5cc732 --- /dev/null +++ b/src/ui-grid.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";angular.module("ui.grid.i18n",[]),angular.module("ui.grid",["ui.grid.i18n"])}(),function(){"use strict";angular.module("ui.grid.autoResize",["ui.grid"]).directive("uiGridAutoResize",["gridUtil",function(i){return{require:"uiGrid",scope:!1,link:function(e,n,t,o){var r;r=i.debounce(function(e,t,r,i){null!==n[0].offsetParent&&(o.grid.gridWidth=r,o.grid.gridHeight=i,o.grid.queueGridRefresh().then(function(){o.grid.api.core.raise.gridDimensionChanged(t,e,i,r)}))},400),e.$watchCollection(function(){return{width:i.elementWidth(n),height:i.elementHeight(n)}},function(e,t){angular.equals(e,t)||r(t.width,t.height,e.width,e.height)})}}}])}(),function(){"use strict";var e=angular.module("ui.grid.cellNav",["ui.grid"]);e.constant("uiGridCellNavConstants",{FEATURE_NAME:"gridCellNav",CELL_NAV_EVENT:"cellNav",direction:{LEFT:0,RIGHT:1,UP:2,DOWN:3,PG_UP:4,PG_DOWN:5},EVENT_TYPE:{KEYDOWN:0,CLICK:1,CLEAR:2}}),e.factory("uiGridCellNavFactory",["gridUtil","uiGridConstants","uiGridCellNavConstants","GridRowColumn","$q",function(e,t,i,l,r){var n=function(e,t,r,i){this.rows=e.visibleRowCache,this.columns=t.visibleColumnCache,this.leftColumns=r?r.visibleColumnCache:[],this.rightColumns=i?i.visibleColumnCache:[],this.bodyContainer=e};return n.prototype.getFocusableCols=function(){return this.leftColumns.concat(this.columns,this.rightColumns).filter(function(e){return e.colDef.allowCellFocus})},n.prototype.getFocusableRows=function(){return this.rows.filter(function(e){return!1!==e.allowCellFocus})},n.prototype.getNextRowCol=function(e,t,r){switch(e){case i.direction.LEFT:return this.getRowColLeft(t,r);case i.direction.RIGHT:return this.getRowColRight(t,r);case i.direction.UP:return this.getRowColUp(t,r);case i.direction.DOWN:return this.getRowColDown(t,r);case i.direction.PG_UP:return this.getRowColPageUp(t,r);case i.direction.PG_DOWN:return this.getRowColPageDown(t,r)}},n.prototype.initializeSelection=function(){var e=this.getFocusableCols(),t=this.getFocusableRows();return 0===e.length||0===t.length?null:new l(t[0],e[0])},n.prototype.getRowColLeft=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);-1===n&&(n=1);var a=0===n?r.length-1:n-1;return new l(n<=a?0===o?e:i[o-1]:e,r[a])},n.prototype.getRowColRight=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);-1===n&&(n=0);var a=n===r.length-1?0:n+1;return a<=n?o===i.length-1?new l(e,r[a]):new l(i[o+1],r[a]):new l(e,r[a])},n.prototype.getRowColDown=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);return-1===n&&(n=0),o===i.length-1?new l(e,r[n]):new l(i[o+1],r[n])},n.prototype.getRowColPageDown=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);-1===n&&(n=0);var a=this.bodyContainer.minRowsToRender();return o>=i.length-a?new l(i[i.length-1],r[n]):new l(i[o+a],r[n])},n.prototype.getRowColUp=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);return-1===n&&(n=0),new l(0===o?e:i[o-1],r[n])},n.prototype.getRowColPageUp=function(e,t){var r=this.getFocusableCols(),i=this.getFocusableRows(),n=r.indexOf(t),o=i.indexOf(e);-1===n&&(n=0);var a=this.bodyContainer.minRowsToRender();return new l(o-a<0?i[0]:i[o-a],r[n])},n}]),e.service("uiGridCellNavService",["gridUtil","uiGridConstants","uiGridCellNavConstants","$q","uiGridCellNavFactory","GridRowColumn","ScrollEvent",function(e,t,r,i,n,o,a){var l={initializeGrid:function(i){i.registerColumnBuilder(l.cellNavColumnBuilder),i.cellNav={},i.cellNav.lastRowCol=null,i.cellNav.focusedCells=[],l.defaultGridOptions(i.options);var e={events:{cellNav:{navigate:function(e,t){},viewPortKeyDown:function(e,t){},viewPortKeyPress:function(e,t){}}},methods:{cellNav:{scrollToFocus:function(e,t){return l.scrollToFocus(i,e,t)},getFocusedCell:function(){return i.cellNav.lastRowCol},getCurrentSelection:function(){return i.cellNav.focusedCells},rowColSelectIndex:function(e){for(var t=-1,r=0;r ',g=a(n)(e),t.prepend(g),e.$on(c.CELL_NAV_EVENT,function(e,t,r,i){if(!i||"focus"!==i.type){for(var n,o,a,l,s=[],d=p.api.cellNav.getCurrentSelection(),c=0;c')(e);t.append(d),d.on("focus",function(e){e.uiGridTargetRenderContainerId=l;var t=n.grid.api.cellNav.getFocusedCell();null===t&&(t=n.grid.renderContainers[l].cellNav.getNextRowCol(m.direction.DOWN,null,null)).row&&t.col&&n.cellNav.broadcastCellNav(t)}),a.setAriaActivedescendant=function(e){t.attr("aria-activedescendant",e)},a.removeAriaActivedescendant=function(e){t.attr("aria-activedescendant")===e&&t.attr("aria-activedescendant","")},n.focus=function(){g.focus.byElement(d[0])};var c=null;d.on("keydown",function(r){r.uiGridTargetRenderContainerId=l;var e=n.grid.api.cellNav.getFocusedCell();null===(n.grid.options.keyDownOverrides.some(function(t){return Object.keys(t).every(function(e){return t[e]===r[e]})})?null:n.cellNav.handleKeyDown(r))&&(n.grid.api.cellNav.raise.viewPortKeyDown(r,e,n.cellNav.handleKeyDown),c=e)}),d.on("keypress",function(e){c&&(u(function(){n.grid.api.cellNav.raise.viewPortKeyPress(e,c)},4),c=null)}),e.$on("$destroy",function(){d.off()})}}}}}}}]),e.directive("uiGridViewport",function(){return{replace:!0,priority:-99999,require:["^uiGrid","^uiGridRenderContainer","?^uiGridCellnav"],scope:!1,compile:function(){return{pre:function(e,t,r,i){},post:function(e,t,r,i){var n=i[0],o=i[1];if(n.grid.api.cellNav&&"body"===o.containerId){var a=n.grid;a.api.core.on.scrollBegin(e,function(){var e=n.grid.api.cellNav.getFocusedCell();null!==e&&o.colContainer.containsColumn(e.col)&&n.cellNav.clearFocus()}),a.api.core.on.scrollEnd(e,function(e){var t=n.grid.api.cellNav.getFocusedCell();null!==t&&o.colContainer.containsColumn(t.col)&&n.cellNav.broadcastCellNav(t)}),a.api.cellNav.on.navigate(e,function(){n.focus()})}}}}}}),e.directive("uiGridCell",["$timeout","$document","uiGridCellNavService","gridUtil","uiGridCellNavConstants","uiGridConstants","GridRowColumn",function(e,t,r,i,u,g,p){return{priority:-150,restrict:"A",require:["^uiGrid","?^uiGridCellnav"],scope:!1,link:function(r,t,e,i){var n=i[0],o=i[1];if(n.grid.api.cellNav&&r.col.colDef.allowCellFocus){var a=n.grid;r.focused=!1,t.attr("tabindex",-1),t.find("div").on("click",function(e){n.cellNav.broadcastCellNav(new p(r.row,r.col),e.ctrlKey||e.metaKey,e),e.stopPropagation(),r.$apply()}),t.on("mousedown",s),n.grid.api.edit&&(n.grid.api.edit.on.beginCellEdit(r,function(){t.off("mousedown",s)}),n.grid.api.edit.on.afterCellEdit(r,function(){t.on("mousedown",s)}),n.grid.api.edit.on.cancelCellEdit(r,function(){t.on("mousedown",s)})),d(),t.on("focus",function(e){n.cellNav.broadcastCellNav(new p(r.row,r.col),!1,e),e.stopPropagation(),r.$apply()}),r.$on(u.CELL_NAV_EVENT,d);var l=n.grid.registerDataChangeCallback(function(e){c(),r.$applyAsync(d)},[g.dataChange.ROW]);r.$on("$destroy",function(){l(),t.find("div").off(),t.off()})}function s(e){e.preventDefault()}function d(){a.cellNav.focusedCells.some(function(e,t){return e.row===r.row&&e.col===r.col})?function(){if(!r.focused){var e=t.find("div");e.addClass("ui-grid-cell-focus"),t.attr("aria-selected",!0),o.setAriaActivedescendant(t.attr("id")),r.focused=!0}}():c()}function c(){r.focused&&(t.find("div").removeClass("ui-grid-cell-focus"),t.attr("aria-selected",!1),o.removeAriaActivedescendant(t.attr("id")),r.focused=!1)}}}}])}(),function(){"use strict";angular.module("ui.grid").constant("uiGridConstants",{LOG_DEBUG_MESSAGES:!0,LOG_WARN_MESSAGES:!0,LOG_ERROR_MESSAGES:!0,CUSTOM_FILTERS:/CUSTOM_FILTERS/g,COL_FIELD:/COL_FIELD/g,MODEL_COL_FIELD:/MODEL_COL_FIELD/g,TOOLTIP:/title=\"TOOLTIP\"/g,DISPLAY_CELL_TEMPLATE:/DISPLAY_CELL_TEMPLATE/g,TEMPLATE_REGEXP:/<.+>/,FUNC_REGEXP:/(\([^)]*\))?$/,DOT_REGEXP:/\./g,APOS_REGEXP:/'/g,BRACKET_REGEXP:/^(.*)((?:\s*\[\s*\d+\s*\]\s*)|(?:\s*\[\s*"(?:[^"\\]|\\.)*"\s*\]\s*)|(?:\s*\[\s*'(?:[^'\\]|\\.)*'\s*\]\s*))(.*)$/,COL_CLASS_PREFIX:"ui-grid-col",ENTITY_BINDING:"$$this",events:{GRID_SCROLL:"uiGridScroll",COLUMN_MENU_SHOWN:"uiGridColMenuShown",ITEM_DRAGGING:"uiGridItemDragStart",COLUMN_HEADER_CLICK:"uiGridColumnHeaderClick"},keymap:{TAB:9,STRG:17,CAPSLOCK:20,CTRL:17,CTRLRIGHT:18,CTRLR:18,SHIFT:16,RETURN:13,ENTER:13,BACKSPACE:8,BCKSP:8,ALT:18,ALTR:17,ALTRIGHT:17,SPACE:32,WIN:91,MAC:91,FN:null,PG_UP:33,PG_DOWN:34,UP:38,DOWN:40,LEFT:37,RIGHT:39,ESC:27,DEL:46,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123},ASC:"asc",DESC:"desc",filter:{STARTS_WITH:2,ENDS_WITH:4,EXACT:8,CONTAINS:16,GREATER_THAN:32,GREATER_THAN_OR_EQUAL:64,LESS_THAN:128,LESS_THAN_OR_EQUAL:256,NOT_EQUAL:512,SELECT:"select",INPUT:"input"},aggregationTypes:{sum:2,count:4,avg:8,min:16,max:32},CURRENCY_SYMBOLS:["¤","؋","Ar","Ƀ","฿","B/.","Br","Bs.","Bs.F.","GH₵","¢","c","Ch.","₡","C$","D","ден","دج",".د.ب","د.ع","JD","د.ك","ل.د","дин","د.ت","د.م.","د.إ","Db","$","₫","Esc","€","ƒ","Ft","FBu","FCFA","CFA","Fr","FRw","G","gr","₲","h","₴","₭","Kč","kr","kn","MK","ZK","Kz","K","L","Le","лв","E","lp","M","KM","MT","₥","Nfk","₦","Nu.","UM","T$","MOP$","₱","Pt.","£","ج.م.","LL","LS","P","Q","q","R","R$","ر.ع.","ر.ق","ر.س","៛","RM","p","Rf.","₹","₨","SRe","Rp","₪","Ksh","Sh.So.","USh","S/","SDR","сом","৳\t","WS$","₮","VT","₩","¥","zł"],scrollDirection:{UP:"up",DOWN:"down",LEFT:"left",RIGHT:"right",NONE:"none"},dataChange:{ALL:"all",EDIT:"edit",ROW:"row",COLUMN:"column",OPTIONS:"options"},scrollbars:{NEVER:0,ALWAYS:1,WHEN_NEEDED:2}})}(),angular.module("ui.grid").directive("uiGridCell",["$compile","$parse","gridUtil","uiGridConstants",function(a,e,l,s){return{priority:0,scope:!1,require:"?^uiGrid",compile:function(){return{pre:function(t,r,e,i){if(i&&t.col.compiledElementFn)(0,t.col.compiledElementFn)(t,function(e,t){r.append(e)});else if(i&&!t.col.compiledElementFn)t.col.getCompiledElementFn().then(function(e){e(t,function(e,t){r.append(e)})}).catch(angular.noop);else{var n=t.col.cellTemplate.replace(s.MODEL_COL_FIELD,"row.entity."+l.preEval(t.col.field)).replace(s.COL_FIELD,"grid.getCellValue(row, col)"),o=a(n)(t);r.append(o)}},post:function(i,n){var o,a=i.col.getColClass(!1);function l(e){var t=n;o&&(t.removeClass(o),o=null),o=angular.isFunction(i.col.cellClass)?i.col.cellClass(i.grid,i.row,i.col,i.rowRenderIndex,i.colRenderIndex):i.col.cellClass,t.addClass(o)}n.addClass(a),i.col.cellClass&&l();var e=i.grid.registerDataChangeCallback(l,[s.dataChange.COLUMN,s.dataChange.EDIT]);var t=i.$watch("row",function(e,t){if(e!==t){(o||i.col.cellClass)&&l();var r=i.col.getColClass(!1);r!==a&&(n.removeClass(a),n.addClass(r),a=r)}});function r(){e(),t()}i.$on("$destroy",r),n.on("$destroy",r)}}}}}]),angular.module("ui.grid").service("uiGridColumnMenuService",["i18nService","uiGridConstants","gridUtil",function(e,r,g){var i={initialize:function(e,t){e.grid=t.grid,(t.columnMenuScope=e).menuShown=!1},setColMenuItemWatch:function(t){var e=t.$watch("col.menuItems",function(e){void 0!==e&&e&&angular.isArray(e)?(e.forEach(function(e){void 0!==e.context&&e.context||(e.context={}),e.context.col=t.col}),t.menuItems=t.defaultMenuItems.concat(e)):t.menuItems=t.defaultMenuItems});t.$on("$destroy",e)},getGridOption:function(e,t){return void 0!==e.grid&&e.grid&&e.grid.options&&e.grid.options[t]},sortable:function(e){return Boolean(this.getGridOption(e,"enableSorting")&&void 0!==e.col&&e.col&&e.col.enableSorting)},isActiveSort:function(e,t){return Boolean(void 0!==e.col&&void 0!==e.col.sort&&void 0!==e.col.sort.direction&&e.col.sort.direction===t)},suppressRemoveSort:function(e){return Boolean(e.col&&e.col.suppressRemoveSort)},hideable:function(e){return Boolean(this.getGridOption(e,"enableHiding")&&void 0!==e.col&&e.col&&(e.col.colDef&&!1!==e.col.colDef.enableHiding||!e.col.colDef)||!this.getGridOption(e,"enableHiding")&&e.col&&e.col.colDef&&e.col.colDef.enableHiding)},getDefaultMenuItems:function(t){return[{title:function(){return e.getSafeText("sort.ascending")},icon:"ui-grid-icon-sort-alt-up",action:function(e){e.stopPropagation(),t.sortColumn(e,r.ASC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.ASC)}},{title:function(){return e.getSafeText("sort.descending")},icon:"ui-grid-icon-sort-alt-down",action:function(e){e.stopPropagation(),t.sortColumn(e,r.DESC)},shown:function(){return i.sortable(t)},active:function(){return i.isActiveSort(t,r.DESC)}},{title:function(){return e.getSafeText("sort.remove")},icon:"ui-grid-icon-cancel",action:function(e){e.stopPropagation(),t.unsortColumn()},shown:function(){return i.sortable(t)&&void 0!==t.col&&void 0!==t.col.sort&&void 0!==t.col.sort.direction&&null!==t.col.sort.direction&&!i.suppressRemoveSort(t)}},{title:function(){return e.getSafeText("column.hide")},icon:"ui-grid-icon-cancel",shown:function(){return i.hideable(t)},action:function(e){e.stopPropagation(),t.hideColumn()}}]},getColumnElementPosition:function(e,t,r){var i={};return i.left=r[0].offsetLeft,i.top=r[0].offsetTop,i.parentLeft=r[0].offsetParent.offsetLeft,i.offset=0,t.grid.options.offsetLeft&&(i.offset=t.grid.options.offsetLeft),i.height=g.elementHeight(r,!0),i.width=g.elementWidth(r,!0),i},repositionMenu:function(e,t,r,i,n){var o=i[0].querySelectorAll(".ui-grid-menu"),a=g.closestElm(n,".ui-grid-render-container"),l=a.getBoundingClientRect().left-e.grid.element[0].getBoundingClientRect().left,s=a.querySelectorAll(".ui-grid-viewport")[0].scrollLeft,d=g.elementWidth(o,!0),c=t.lastMenuPaddingRight?t.lastMenuPaddingRight:e.lastMenuPaddingRight?e.lastMenuPaddingRight:10;0!==o.length&&0!==o[0].querySelectorAll(".ui-grid-menu-mid").length&&(c=parseInt(g.getStyles(angular.element(o)[0]).paddingRight,10),e.lastMenuPaddingRight=c,t.lastMenuPaddingRight=c);var u=r.left+l-s+r.parentLeft+r.width+c;u(c.grid.rowHeaderColumns?c.grid.rowHeaderColumns.length:0);!r&&!n.uiGridColumns&&0===c.grid.options.columnDefs.length&&0
    ',scope:{side:"=uiGridPinnedContainer"},require:"^uiGrid",compile:function(){return{post:function(n,t,e,r){var o=r.grid,i=0;function a(){if("left"===n.side||"right"===n.side){for(var e=o.renderContainers[n.side].visibleColumnCache,t=0,r=0;r=t&&(t=e.sort.priority+1)}),t},e.prototype.resetColumnSorting=function(t){this.columns.forEach(function(e){e===t||e.suppressRemoveSort||(e.sort={})})},e.prototype.getColumnSorting=function(){var t=[];return this.columns.slice(0).sort(p.prioritySort).forEach(function(e){e.sort&&void 0!==e.sort.direction&&e.sort.direction&&(e.sort.direction===s.ASC||e.sort.direction===s.DESC)&&t.push(e)}),t},e.prototype.sortColumn=function(e,t,r){var i=this,n=null;if(void 0===e||!e)throw new Error("No column parameter provided");if("boolean"==typeof t?r=t:n=t,!r||i.options&&i.options.suppressMultiSort?(i.resetColumnSorting(e),e.sort.priority=void 0,e.sort.priority=i.getNextColumnSortPriority()):void 0===e.sort.priority&&(e.sort.priority=i.getNextColumnSortPriority()),n)e.sort.direction=n;else{var o=e.sortDirectionCycle.indexOf(e.sort&&e.sort.direction?e.sort.direction:null);o=(o+1)%e.sortDirectionCycle.length,e.colDef&&e.suppressRemoveSort&&!e.sortDirectionCycle[o]&&(o=(o+1)%e.sortDirectionCycle.length),e.sortDirectionCycle[o]?e.sort.direction=e.sortDirectionCycle[o]:a(e,i)}return i.api.core.raise.sortChanged(i,i.getColumnSorting()),S.when(e)};var a=function(t,e){e.columns.forEach(function(e){e.sort&&void 0!==e.sort.priority&&e.sort.priority>t.sort.priority&&(e.sort.priority-=1)}),t.sort={}};function l(e,t){return e||0Math.ceil(s)&&(c=p-s+r.renderContainers.body.prevScrollTop,i.y=E(c+r.options.rowHeight,g,r.renderContainers.body.prevScrolltopPercentage))}if(null!==t){for(var f=o.indexOf(t),m=r.renderContainers.body.getCanvasWidth()-r.renderContainers.body.getViewportWidth(),h=0,v=0;vt&&(e.sort.priority-=1)}),this.sort={},this.grid.api.core.raise.sortChanged(this.grid,this.grid.getColumnSorting())},t.prototype.getColClass=function(e){var t=c.COL_CLASS_PREFIX+this.uid;return e?"."+t:t},t.prototype.isPinnedLeft=function(){return"left"===this.renderContainer},t.prototype.isPinnedRight=function(){return"right"===this.renderContainer},t.prototype.getColClassDefinition=function(){return" .grid"+this.grid.id+" "+this.getColClass(!0)+" { min-width: "+this.drawnWidth+"px; max-width: "+this.drawnWidth+"px; }"},t.prototype.getRenderContainer=function(){var e=this.renderContainer;return null!==e&&""!==e&&void 0!==e||(e="body"),this.grid.renderContainers[e]},t.prototype.showColumn=function(){this.colDef.visible=!0},t.prototype.getAggregationText=function(){if(this.colDef.aggregationHideLabel)return"";if(this.colDef.aggregationLabel)return this.colDef.aggregationLabel;switch(this.colDef.aggregationType){case c.aggregationTypes.count:return e.getSafeText("aggregation.count");case c.aggregationTypes.sum:return e.getSafeText("aggregation.sum");case c.aggregationTypes.avg:return e.getSafeText("aggregation.avg");case c.aggregationTypes.min:return e.getSafeText("aggregation.min");case c.aggregationTypes.max:return e.getSafeText("aggregation.max");default:return""}},t.prototype.getCellTemplate=function(){return this.cellTemplatePromise},t.prototype.getCompiledElementFn=function(){return this.compiledElementFnDefer.promise},t}]),angular.module("ui.grid").factory("GridOptions",["gridUtil","uiGridConstants",function(t,r){return{initialize:function(e){return e.onRegisterApi=e.onRegisterApi||angular.noop(),e.data=e.data||[],e.columnDefs=e.columnDefs||[],e.excludeProperties=e.excludeProperties||["$$hashKey"],e.enableRowHashing=!1!==e.enableRowHashing,e.rowIdentity=e.rowIdentity||function(e){return t.hashKey(e)},e.getRowIdentity=e.getRowIdentity||function(e){return e.$$hashKey},e.flatEntityAccess=!0===e.flatEntityAccess,e.showHeader=void 0===e.showHeader||e.showHeader,e.showHeader?e.headerRowHeight=void 0!==e.headerRowHeight?e.headerRowHeight:30:e.headerRowHeight=0,"string"==typeof e.rowHeight?e.rowHeight=parseInt(e.rowHeight)||30:e.rowHeight=e.rowHeight||30,e.minRowsToShow=void 0!==e.minRowsToShow?e.minRowsToShow:10,e.showGridFooter=!0===e.showGridFooter,e.showColumnFooter=!0===e.showColumnFooter,e.columnFooterHeight=void 0!==e.columnFooterHeight?e.columnFooterHeight:30,e.gridFooterHeight=void 0!==e.gridFooterHeight?e.gridFooterHeight:30,e.columnWidth=void 0!==e.columnWidth?e.columnWidth:50,e.maxVisibleColumnCount=void 0!==e.maxVisibleColumnCount?e.maxVisibleColumnCount:200,e.virtualizationThreshold=void 0!==e.virtualizationThreshold?e.virtualizationThreshold:20,e.columnVirtualizationThreshold=void 0!==e.columnVirtualizationThreshold?e.columnVirtualizationThreshold:10,e.excessRows=void 0!==e.excessRows?e.excessRows:4,e.scrollThreshold=void 0!==e.scrollThreshold?e.scrollThreshold:4,e.excessColumns=void 0!==e.excessColumns?e.excessColumns:4,e.aggregationCalcThrottle=void 0!==e.aggregationCalcThrottle?e.aggregationCalcThrottle:500,e.wheelScrollThrottle=void 0!==e.wheelScrollThrottle?e.wheelScrollThrottle:70,e.scrollDebounce=void 0!==e.scrollDebounce?e.scrollDebounce:300,e.enableHiding=!1!==e.enableHiding,e.enableSorting=!1!==e.enableSorting,e.suppressMultiSort=!0===e.suppressMultiSort,e.enableFiltering=!0===e.enableFiltering,e.filterContainer=void 0!==e.filterContainer?e.filterContainer:"headerCell",e.enableColumnMenus=!1!==e.enableColumnMenus,e.enableVerticalScrollbar=void 0!==e.enableVerticalScrollbar?e.enableVerticalScrollbar:r.scrollbars.ALWAYS,e.enableHorizontalScrollbar=void 0!==e.enableHorizontalScrollbar?e.enableHorizontalScrollbar:r.scrollbars.ALWAYS,e.enableMinHeightCheck=!1!==e.enableMinHeightCheck,e.minimumColumnSize=void 0!==e.minimumColumnSize?e.minimumColumnSize:30,e.rowEquality=e.rowEquality||function(e,t){return e===t},e.headerTemplate=e.headerTemplate||null,e.footerTemplate=e.footerTemplate||"ui-grid/ui-grid-footer",e.gridFooterTemplate=e.gridFooterTemplate||"ui-grid/ui-grid-grid-footer",e.rowTemplate=e.rowTemplate||"ui-grid/ui-grid-row",e.gridMenuTemplate=e.gridMenuTemplate||"ui-grid/uiGridMenu",e.menuButtonTemplate=e.menuButtonTemplate||"ui-grid/ui-grid-menu-button",e.menuItemTemplate=e.menuItemTemplate||"ui-grid/uiGridMenuItem",e.appScopeProvider=e.appScopeProvider||null,e}}}]),angular.module("ui.grid").factory("GridRenderContainer",["gridUtil","uiGridConstants",function(b,n){function e(e,t,r){var i=this;i.name=e,i.grid=t,i.visibleRowCache=[],i.visibleColumnCache=[],i.renderedRows=[],i.renderedColumns=[],i.prevScrollTop=0,i.prevScrolltopPercentage=0,i.prevRowScrollIndex=0,i.prevScrollLeft=0,i.prevScrollleftPercentage=0,i.prevColumnScrollIndex=0,i.columnStyles="",i.viewportAdjusters=[],i.hasHScrollbar=!1,i.hasVScrollbar=!1,i.canvasHeightShouldUpdate=!0,i.$$canvasHeight=0,r&&angular.isObject(r)&&angular.extend(i,r),t.registerStyleComputation({priority:5,func:function(){return i.updateColumnWidths(),i.columnStyles}})}return e.prototype.reset=function(){this.visibleColumnCache.length=0,this.visibleRowCache.length=0,this.renderedRows.length=0,this.renderedColumns.length=0},e.prototype.containsColumn=function(e){return-1!==this.visibleColumnCache.indexOf(e)},e.prototype.minRowsToRender=function(){for(var e=0,t=0,r=this.getViewportHeight(),i=this.visibleRowCache.length-1;ti.grid.options.virtualizationThreshold){if(null!=e){if(!i.grid.suppressParentScrollDown&&i.prevScrollTope&&l>i.prevRowScrollIndex-i.grid.options.scrollThreshold&&lt.grid.options.columnVirtualizationThreshold&&t.getCanvasWidth()>t.getViewportWidth())a=[Math.max(0,o-t.grid.options.excessColumns),Math.min(i.length,o+r+t.grid.options.excessColumns)];else{var l=t.visibleColumnCache.length;a=[0,Math.max(l,r+t.grid.options.excessColumns)]}t.updateViewableColumnRange(a),t.prevColumnScrollIndex=o},e.prototype.getLeftIndex=function(e){for(var t=0,r=0;re.maxWidth&&(t=e.maxWidth),te.maxWidth&&(t=e.maxWidth),te.minWidth&&0e.offsetWidth)},e.prototype.getViewportStyle=function(){var e=this,t={},r={};return r[n.scrollbars.ALWAYS]="scroll",r[n.scrollbars.WHEN_NEEDED]="auto",e.hasHScrollbar=!1,e.hasVScrollbar=!1,e.grid.disableScrolling?(t["overflow-x"]="hidden",t["overflow-y"]="hidden"):("body"===e.name?(e.hasHScrollbar=e.grid.options.enableHorizontalScrollbar!==n.scrollbars.NEVER,e.grid.isRTL()?e.grid.hasLeftContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER):e.grid.hasRightContainerColumns()||(e.hasVScrollbar=e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER)):"left"===e.name?e.hasVScrollbar=!!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER:e.hasVScrollbar=!e.grid.isRTL()&&e.grid.options.enableVerticalScrollbar!==n.scrollbars.NEVER,t["overflow-x"]=e.hasHScrollbar?r[e.grid.options.enableHorizontalScrollbar]:"hidden",t["overflow-y"]=e.hasVScrollbar?r[e.grid.options.enableVerticalScrollbar]:"hidden"),t},e}]),angular.module("ui.grid").factory("GridRow",["gridUtil","uiGridConstants",function(i,t){function e(e,t,r){this.grid=r,this.entity=e,this.index=t,this.uid=i.nextUid(),this.visible=!0,this.isSelected=!1,this.$$height=r.options.rowHeight}return Object.defineProperty(e.prototype,"height",{get:function(){return this.$$height},set:function(e){e!==this.$$height&&(this.grid.updateCanvasHeight(),this.$$height=e)}}),e.prototype.getQualifiedColField=function(e){return"row."+this.getEntityQualifiedColField(e)},e.prototype.getEntityQualifiedColField=function(e){return e.field===t.ENTITY_BINDING?"entity":i.preEval("entity."+e.field)},e.prototype.setRowInvisible=function(e){e&&e.setThisRowInvisible&&e.setThisRowInvisible("user")},e.prototype.clearRowInvisible=function(e){e&&e.clearThisRowInvisible&&e.clearThisRowInvisible("user")},e.prototype.setThisRowInvisible=function(e,t){this.invisibleReason||(this.invisibleReason={}),this.invisibleReason[e]=!0,this.evaluateRowVisibility(t)},e.prototype.clearThisRowInvisible=function(e,t){void 0!==this.invisibleReason&&delete this.invisibleReason[e],this.evaluateRowVisibility(t)},e.prototype.evaluateRowVisibility=function(e){var r=!0;void 0!==this.invisibleReason&&angular.forEach(this.invisibleReason,function(e,t){e&&(r=!1)}),void 0!==this.visible&&this.visible===r||(this.visible=r,e||(this.grid.queueGridRefresh(),this.grid.api.core.raise.rowsVisibleChanged(this)))},e}]),function(){"use strict";angular.module("ui.grid").factory("GridRowColumn",["$parse","$filter",function(e,t){var r=function e(t,r){if(!(this instanceof e))throw"Using GridRowColumn as a function insead of as a constructor. Must be called with `new` keyword";this.row=t,this.col=r};return r.prototype.getIntersectionValueRaw=function(){return e(this.row.getEntityQualifiedColField(this.col))(this.row)},r}])}(),angular.module("ui.grid").factory("ScrollEvent",["gridUtil",function(a){function e(e,t,r,i){var n=this;if(!e)throw new Error("grid argument is required");n.grid=e,n.source=i,n.withDelay=!0,n.sourceRowContainer=t,n.sourceColContainer=r,n.newScrollLeft=null,n.newScrollTop=null,n.x=null,n.y=null,n.verticalScrollLength=-9999999,n.horizontalScrollLength=-999999,n.fireThrottledScrollingEvent=a.throttle(function(e){n.grid.scrollContainers(e,n)},n.grid.options.wheelScrollThrottle,{trailing:!0})}return e.prototype.getNewScrollLeft=function(e,t){var r=this;if(r.newScrollLeft)return r.newScrollLeft;var i,n=e.getCanvasWidth()-e.getViewportWidth(),o=a.normalizeScrollLeft(t,r.grid);if(void 0!==r.x.percentage&&void 0!==r.x.percentage)i=r.x.percentage;else{if(void 0===r.x.pixels||void 0===r.x.pixels)throw new Error("No percentage or pixel value provided for scroll event X axis");i=r.x.percentage=(o+r.x.pixels)/n}return Math.max(0,i*n)},e.prototype.getNewScrollTop=function(e,t){var r=this;if(r.newScrollTop)return r.newScrollTop;var i,n=e.getVerticalScrollLength(),o=t[0].scrollTop;if(void 0!==r.y.percentage&&void 0!==r.y.percentage)i=r.y.percentage;else{if(void 0===r.y.pixels||void 0===r.y.pixels)throw new Error("No percentage or pixel value provided for scroll event Y axis");i=r.y.percentage=(o+r.y.pixels)/n}return Math.max(0,i*n)},e.prototype.atTop=function(e){return this.y&&(0===this.y.percentage||this.verticalScrollLength<0)&&0===e},e.prototype.atBottom=function(e){return this.y&&(1===this.y.percentage||0===this.verticalScrollLength)&&0
    ')[0],r="reverse";return document.body.appendChild(t),0 1 or < 1 file choosers within the menu item, error, cannot continue"):o[0].addEventListener("change",function(e){var t=e.srcElement||e.target;if(t&&t.files&&1===t.files.length){var r=t.files[0];void 0!==i&&i?(n=i.grid,a.importThisFile(n,r),t.form.reset()):l.logError("Could not import file because UI Grid was not found.")}},!1)}}}])}(),function(){"use strict";var e=angular.module("ui.grid.infiniteScroll",["ui.grid"]);e.service("uiGridInfiniteScrollService",["gridUtil","$compile","$rootScope","uiGridConstants","ScrollEvent","$q",function(e,t,l,s,a,r){var d={initializeGrid:function(r,e){if(d.defaultGridOptions(r.options),r.options.enableInfiniteScroll){r.infiniteScroll={dataLoading:!1},d.setScrollDirections(r,r.options.infiniteScrollUp,r.options.infiniteScrollDown),r.api.core.on.scrollEnd(e,d.handleScroll);var t={events:{infiniteScroll:{needLoadMoreData:function(e,t){},needLoadMoreDataTop:function(e,t){}}},methods:{infiniteScroll:{dataLoaded:function(e,t){return d.setScrollDirections(r,e,t),d.adjustScroll(r).then(function(){r.infiniteScroll.dataLoading=!1})},resetScroll:function(e,t){d.setScrollDirections(r,e,t),d.adjustInfiniteScrollPosition(r,0)},saveScrollPercentage:function(){r.infiniteScroll.prevScrollTop=r.renderContainers.body.prevScrollTop,r.infiniteScroll.previousVisibleRows=r.getVisibleRowCount()},dataRemovedTop:function(e,t){d.dataRemovedTop(r,e,t)},dataRemovedBottom:function(e,t){d.dataRemovedBottom(r,e,t)},setScrollDirections:function(e,t){d.setScrollDirections(r,e,t)}}}};r.api.registerEventsFromObject(t.events),r.api.registerMethodsFromObject(t.methods)}},defaultGridOptions:function(e){e.enableInfiniteScroll=!1!==e.enableInfiniteScroll,e.infiniteScrollRowsFromEnd=e.infiniteScrollRowsFromEnd||20,e.infiniteScrollUp=!0===e.infiniteScrollUp,e.infiniteScrollDown=!1!==e.infiniteScrollDown},setScrollDirections:function(e,t,r){e.infiniteScroll.scrollUp=!0===t,e.suppressParentScrollUp=!0===t,e.infiniteScroll.scrollDown=!1!==r,e.suppressParentScrollDown=!1!==r},handleScroll:function(e){if(!(e.grid.infiniteScroll&&e.grid.infiniteScroll.dataLoading||"ui.grid.adjustInfiniteScrollPosition"===e.source)&&e.y)if(0===e.y.percentage)e.grid.scrollDirection=s.scrollDirection.UP,d.loadData(e.grid);else if(1===e.y.percentage)e.grid.scrollDirection=s.scrollDirection.DOWN,d.loadData(e.grid);else{var t=e.grid.options.infiniteScrollRowsFromEnd/e.grid.renderContainers.body.visibleRowCache.length;e.grid.scrollDirection===s.scrollDirection.UP?e.y.percentage<=t&&d.loadData(e.grid):e.grid.scrollDirection===s.scrollDirection.DOWN&&1-e.y.percentage<=t&&d.loadData(e.grid)}},loadData:function(e){e.infiniteScroll.previousVisibleRows=e.renderContainers.body.visibleRowCache.length,e.infiniteScroll.direction=e.scrollDirection,delete e.infiniteScroll.prevScrollTop,e.scrollDirection===s.scrollDirection.UP&&e.infiniteScroll.scrollUp?(e.infiniteScroll.dataLoading=!0,e.api.infiniteScroll.raise.needLoadMoreDataTop()):e.scrollDirection===s.scrollDirection.DOWN&&e.infiniteScroll.scrollDown&&(e.infiniteScroll.dataLoading=!0,e.api.infiniteScroll.raise.needLoadMoreData())},adjustScroll:function(o){var a=r.defer();return l.$applyAsync(function(){var e,t,r,i;e=o.getViewportHeight()+o.headerHeight-o.renderContainers.body.headerHeight-o.scrollbarHeight,t=o.options.rowHeight,void 0===o.infiniteScroll.direction&&d.adjustInfiniteScrollPosition(o,0);var n=t*(r=o.getVisibleRowCount());o.infiniteScroll.scrollDown&&n=i.length-r||t>=i.length-r)s.logError("MoveColumn: Invalid values for originalPosition, finalPosition");else{var o=function(e){for(var t=e,r=0;r<=t;r++)angular.isDefined(i[r])&&(angular.isDefined(i[r].colDef.visible)&&!1===i[r].colDef.visible||!0===i[r].isRowHeader)&&t++;return t};l.redrawColumnAtPosition(a,o(e),o(t))}}else s.logError("MoveColumn: Please provide valid values for originalPosition and finalPosition")}}}};a.api.registerEventsFromObject(e.events),a.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enableColumnMoving=!1!==e.enableColumnMoving},movableColumnBuilder:function(e,t,r){return e.enableColumnMoving=void 0===e.enableColumnMoving?r.enableColumnMoving:e.enableColumnMoving,i.all([])},updateColumnCache:function(e){e.moveColumns.orderCache=e.getOnlyDataColumns()},verifyColumnOrder:function(i){var n,o=i.rowHeaderColumns.length;angular.forEach(i.moveColumns.orderCache,function(e,t){if(-1!==(n=i.columns.indexOf(e))&&n-o!==t){var r=i.columns.splice(n,1)[0];i.columns.splice(t+o,0,r)}})},redrawColumnAtPosition:function(e,t,r){var i=e.columns;if(t!==r){for(var n=tMath.max(n,r))){var a=i[t];if(a.colDef.enableColumnMoving){if(rMath.abs(p)){b.redrawColumnAtPosition(c.grid,i,o-1);break}}else for(o=i-1;0<=o;o--)if((angular.isUndefined(r[o].colDef.visible)||!0===r[o].colDef.visible)&&(a+=r[o].drawnWidth||r[o].width||r[o].colDef.width)>Math.abs(p)){b.redrawColumnAtPosition(c.grid,i,o+1);break}aMath.ceil(u.grid.gridWidth)){e*=8;var l=new S(c.col.grid,null,null,"uiGridHeaderCell.moveElement");l.x={pixels:e},l.grid.scrollContainers("",l)}for(var s=0,d=0;dr.length&&(i=((o.options.paginationCurrentPage=1)-1)*t),r.slice(i,n+1)},900)},defaultGridOptions:function(e){e.enablePagination=!1!==e.enablePagination,e.enablePaginationControls=!1!==e.enablePaginationControls,e.useExternalPagination=!0===e.useExternalPagination,e.useCustomPagination=!0===e.useCustomPagination,t.isNullOrUndefined(e.totalItems)&&(e.totalItems=0),t.isNullOrUndefined(e.paginationPageSizes)&&(e.paginationPageSizes=[250,500,1e3]),t.isNullOrUndefined(e.paginationPageSize)&&(0r.paginationApi.getTotalPages()?o.paginationCurrentPage=r.paginationApi.getTotalPages():d.onPaginationChanged(r.grid,o.paginationCurrentPage,o.paginationPageSize))});r.$on("$destroy",function(){l()}),r.cantPageForward=function(){return r.paginationApi.getTotalPages()?r.cantPageToLast():o.data.length<1},r.cantPageToLast=function(){var e=r.paginationApi.getTotalPages();return!e||o.paginationCurrentPage>=e},r.cantPageBackward=function(){return o.paginationCurrentPage<=1};var s=function(e){e&&u.focus.bySelector(t,".ui-grid-pager-control-input")};r.pageFirstPageClick=function(){r.paginationApi.seek(1),s(r.cantPageBackward())},r.pagePreviousPageClick=function(){r.paginationApi.previousPage(),s(r.cantPageBackward())},r.pageNextPageClick=function(){r.paginationApi.nextPage(),s(r.cantPageForward())},r.pageLastPageClick=function(){r.paginationApi.seek(r.paginationApi.getTotalPages()),s(r.cantPageToLast())}}}}])}(),function(){"use strict";var e=angular.module("ui.grid.pinning",["ui.grid"]);e.constant("uiGridPinningConstants",{container:{LEFT:"left",RIGHT:"right",NONE:""}}),e.service("uiGridPinningService",["gridUtil","GridRenderContainer","i18nService","uiGridPinningConstants",function(a,e,l,s){var d={initializeGrid:function(r){d.defaultGridOptions(r.options),r.registerColumnBuilder(d.pinningColumnBuilder);var e={events:{pinning:{columnPinned:function(e,t){}}},methods:{pinning:{pinColumn:function(e,t){d.pinColumn(r,e,t)}}}};r.api.registerEventsFromObject(e.events),r.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enablePinning=!1!==e.enablePinning,e.hidePinLeft=e.enablePinning&&e.hidePinLeft,e.hidePinRight=e.enablePinning&&e.hidePinRight},pinningColumnBuilder:function(e,t,r){if(e.enablePinning=void 0===e.enablePinning?r.enablePinning:e.enablePinning,e.hidePinLeft=void 0===e.hidePinLeft?r.hidePinLeft:e.hidePinLeft,e.hidePinRight=void 0===e.hidePinRight?r.hidePinRight:e.hidePinRight,e.pinnedLeft?(t.renderContainer="left",t.grid.createLeftContainer()):e.pinnedRight&&(t.renderContainer="right",t.grid.createRightContainer()),e.enablePinning){var i={name:"ui.grid.pinning.pinLeft",title:l.get().pinning.pinLeft,icon:"ui-grid-icon-left-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"left"!==this.context.col.renderContainer},action:function(){d.pinColumn(this.context.col.grid,this.context.col,s.container.LEFT)}},n={name:"ui.grid.pinning.pinRight",title:l.get().pinning.pinRight,icon:"ui-grid-icon-right-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"right"!==this.context.col.renderContainer},action:function(){d.pinColumn(this.context.col.grid,this.context.col,s.container.RIGHT)}},o={name:"ui.grid.pinning.unpin",title:l.get().pinning.unpin,icon:"ui-grid-icon-cancel",shown:function(){return void 0!==this.context.col.renderContainer&&null!==this.context.col.renderContainer&&"body"!==this.context.col.renderContainer},action:function(){d.pinColumn(this.context.col.grid,this.context.col,s.container.NONE)}};e.hidePinLeft||a.arrayContainsObjectWithProperty(t.menuItems,"name","ui.grid.pinning.pinLeft")||t.menuItems.push(i),e.hidePinRight||a.arrayContainsObjectWithProperty(t.menuItems,"name","ui.grid.pinning.pinRight")||t.menuItems.push(n),a.arrayContainsObjectWithProperty(t.menuItems,"name","ui.grid.pinning.unpin")||t.menuItems.push(o)}},pinColumn:function(e,t,r){r===s.container.NONE?(t.renderContainer=null,t.colDef.pinnedLeft=t.colDef.pinnedRight=!1):(t.renderContainer=r)===s.container.LEFT?e.createLeftContainer():r===s.container.RIGHT&&e.createRightContainer(),e.refresh().then(function(){e.api.pinning.raise.columnPinned(t.colDef,r)})}};return d}]),e.directive("uiGridPinning",["gridUtil","uiGridPinningService",function(e,n){return{require:"uiGrid",scope:!1,compile:function(){return{pre:function(e,t,r,i){n.initializeGrid(i.grid)},post:function(e,t,r,i){}}}}}])}(),function(){"use strict";var e=angular.module("ui.grid.resizeColumns",["ui.grid"]);e.service("uiGridResizeColumnsService",["gridUtil","$q","$rootScope",function(i,n,o){return{defaultGridOptions:function(e){e.enableColumnResizing=!1!==e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1)},colResizerColumnBuilder:function(e,t,r){return e.enableColumnResizing=void 0===e.enableColumnResizing?r.enableColumnResizing:e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1),n.all([])},registerPublicApi:function(e){e.api.registerEventsFromObject({colResizable:{columnSizeChanged:function(e,t){}}})},fireColumnSizeChanged:function(e,t,r){o.$applyAsync(function(){e.api.colResizable?e.api.colResizable.raise.columnSizeChanged(t,r):i.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events.")})},findTargetCol:function(e,t,r){var i=e.getRenderContainer();if("left"!==t)return e;var n=i.visibleColumnCache.indexOf(e);return 0===n?i.visibleColumnCache[0]:i.visibleColumnCache[n-1*r]}}}]),e.directive("uiGridResizeColumns",["gridUtil","uiGridResizeColumnsService",function(e,n){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,t,r,i){n.defaultGridOptions(i.grid.options),i.grid.registerColumnBuilder(n.colResizerColumnBuilder),n.registerPublicApi(i.grid)},post:function(e,t,r,i){}}}}}]),e.directive("uiGridHeaderCell",["gridUtil","$templateCache","$compile","$q","uiGridResizeColumnsService","uiGridConstants",function(e,o,c,t,u,g){return{priority:-10,require:"^uiGrid",compile:function(){return{post:function(a,l,e,t){var r=t.grid;if(r.options.enableColumnResizing){var s=o.get("ui-grid/columnResizer"),d=1;r.isRTL()&&(a.position="left",d=-1);var i=function(){for(var e=l[0].getElementsByClassName("ui-grid-column-resizer"),t=0;t');return{priority:0,scope:{col:"=",position:"@",renderIndex:"="},require:"?^uiGrid",link:function(l,s,e,d){var o=0,a=0,c=0,u=1;function g(e){d.grid.refreshCanvas(!0).then(function(){d.grid.queueGridRefresh()})}function p(e,t){var r=t;return e.minWidth&&re.maxWidth&&(r=e.maxWidth),r}function r(e,t){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),(a=(e.targetTouches?e.targetTouches[0]:e).clientX-c)<0?a=0:a>d.grid.gridWidth&&(a=d.grid.gridWidth);var r=w.findTargetCol(l.col,l.position,u);if(!1!==r.colDef.enableColumnResizing){d.grid.element.hasClass("column-resizing")||d.grid.element.addClass("column-resizing");var i=a-o,n=parseInt(r.drawnWidth+i*u,10);a+=(p(r,n)-n)*u,b.css({left:a+"px"}),d.fireEvent(C.events.ITEM_DRAGGING)}}function i(e){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),d.grid.element.removeClass("column-resizing"),b.remove();var t=(a=(e.changedTouches?e.changedTouches[0]:e).clientX-c)-o;if(0===t)return m(),void f();var r=w.findTargetCol(l.col,l.position,u);if(!1!==r.colDef.enableColumnResizing){var i=parseInt(r.drawnWidth+t*u,10);r.width=p(r,i),r.hasCustomWidth=!0,g(),w.fireColumnSizeChanged(d.grid,r.colDef,t),m(),f()}}d.grid.isRTL()&&(l.position="left",u=-1),"left"===l.position?s.addClass("left"):"right"===l.position&&s.addClass("right");var n=function(e,t){e.originalEvent&&(e=e.originalEvent),e.stopPropagation(),c=d.grid.element[0].getBoundingClientRect().left,o=(e.targetTouches?e.targetTouches[0]:e).clientX-c,d.grid.element.append(b),b.css({left:o}),"touchstart"===e.type?(h.on("touchend",i),h.on("touchmove",r),s.off("mousedown",n)):(h.on("mouseup",i),h.on("mousemove",r),s.off("touchstart",n))},f=function(){s.on("mousedown",n),s.on("touchstart",n)},m=function(){h.off("mouseup",i),h.off("touchend",i),h.off("mousemove",r),h.off("touchmove",r),s.off("mousedown",n),s.off("touchstart",n)};f();var t=function(e,t){e.stopPropagation();var r=w.findTargetCol(l.col,l.position,u);if(!1!==r.colDef.enableColumnResizing){var n=0,i=v.closestElm(s,".ui-grid-render-container").querySelectorAll("."+C.COL_CLASS_PREFIX+r.uid+" .ui-grid-cell-contents");Array.prototype.forEach.call(i,function(e){var i;angular.element(e).parent().hasClass("ui-grid-header-cell")&&(i=angular.element(e).parent()[0].querySelectorAll(".ui-grid-column-menu-button")),v.fakeElement(e,{},function(e){var t=angular.element(e);t.attr("style","float: left");var r=v.elementWidth(t);i&&(r+=v.elementWidth(i));ne.value||null===e.value)&&(e.value=t)}},avg:{label:n.get().aggregation.avg,menuTitle:n.get().grouping.aggregate_avg,aggregationFn:function(e,t,r){void 0===e.count?e.count=1:e.count++,isNaN(r)||(void 0===e.value||void 0===e.sum?(e.value=r,e.sum=r):(e.sum+=r,e.value=e.sum/e.count))}}}},finaliseAggregation:function(e,t){t.col.treeAggregationUpdateEntity&&void 0!==e&&void 0!==e.entity["$$"+t.col.uid]&&angular.extend(t,e.entity["$$"+t.col.uid]),"function"==typeof t.col.treeAggregationFinalizerFn&&t.col.treeAggregationFinalizerFn(t),"function"==typeof t.col.customTreeAggregationFinalizerFn&&t.col.customTreeAggregationFinalizerFn(t),void 0===t.rendered&&(t.rendered=t.label?t.label+t.value:t.value)},finaliseAggregations:function(e){null!=e&&void 0!==e.treeNode.aggregations&&e.treeNode.aggregations.forEach(function(r){if(s.finaliseAggregation(e,r),r.col.treeAggregationUpdateEntity){var i={};angular.forEach(r,function(e,t){r.hasOwnProperty(t)&&"col"!==t&&(i[t]=e)}),e.entity["$$"+r.col.uid]=i}})},treeFooterAggregationType:function(e,t){return s.finaliseAggregation(void 0,t.treeFooterAggregation),void 0===t.treeFooterAggregation.value||null===t.treeFooterAggregation.rendered?"":t.treeFooterAggregation.rendered}};return s}]),e.directive("uiGridTreeBaseRowHeaderButtons",["$templateCache","uiGridTreeBaseService",function(e,o){return{replace:!0,restrict:"E",template:e.get("ui-grid/treeBaseRowHeaderButtons"),scope:!0,require:"^uiGrid",link:function(r,e,t,i){var n=i.grid;r.treeButtonClass=function(e){if(n.options.showTreeExpandNoChildren&&-1 -1}":"{'ui-grid-tree-header-row': row.treeLevel > -1}",t.attr("ng-class",i),{pre:function(e,t,r,i){},post:function(e,t,r,i){}}}}})}(),function(){"use strict";var e=angular.module("ui.grid.treeView",["ui.grid","ui.grid.treeBase"]);e.constant("uiGridTreeViewConstants",{featureName:"treeView",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),e.service("uiGridTreeViewService",["$q","uiGridTreeViewConstants","uiGridTreeBaseConstants","uiGridTreeBaseService","gridUtil","GridRow","gridClassFactory","i18nService","uiGridConstants",function(e,t,r,n,i,o,a,l,s){var d={initializeGrid:function(e,t){n.initializeGrid(e,t),e.treeView={},e.registerRowsProcessor(d.adjustSorting,60);var r={treeView:{}},i={treeView:{}};e.api.registerEventsFromObject(r),e.api.registerMethodsFromObject(i)},defaultGridOptions:function(e){e.enableTreeView=!1!==e.enableTreeView},adjustSorting:function(e){return this.columns.forEach(function(e){e.sort&&(e.sort.ignoreSort=!0)}),e}};return d}]),e.directive("uiGridTreeView",["uiGridTreeViewConstants","uiGridTreeViewService","$templateCache",function(e,n,t){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,t,r,i){!1!==i.grid.options.enableTreeView&&n.initializeGrid(i.grid,e)},post:function(e,t,r,i){}}}}}])}(),function(){"use strict";var e=angular.module("ui.grid.validate",["ui.grid"]);e.service("uiGridValidateService",["$sce","$q","$http","i18nService","uiGridConstants",function(n,c,e,o,t){var u={validatorFactories:{},setExternalFactoryFunction:function(e){u.externalFactoryFunction=e},clearExternalFactory:function(){delete u.externalFactoryFunction},getValidatorFromExternalFactory:function(e,t){return u.externalFactoryFunction(e,t).validatorFactory(t)},getMessageFromExternalFactory:function(e,t){return u.externalFactoryFunction(e,t).messageFunction(t)},setValidator:function(e,t,r){u.validatorFactories[e]={validatorFactory:t,messageFunction:r}},getValidator:function(e,t){if(u.externalFactoryFunction){var r=u.getValidatorFromExternalFactory(e,t);if(r)return r}if(!u.validatorFactories[e])throw"Invalid validator name: "+e;return u.validatorFactories[e].validatorFactory(t)},getMessage:function(e,t){if(u.externalFactoryFunction){var r=u.getMessageFromExternalFactory(e,t);if(r)return r}return u.validatorFactories[e].messageFunction(t)},isInvalid:function(e,t){return e["$$invalid"+t.name]},setInvalid:function(e,t){e["$$invalid"+t.name]=!0},setValid:function(e,t){delete e["$$invalid"+t.name]},setError:function(e,t,r){e["$$errors"+t.name]||(e["$$errors"+t.name]={}),e["$$errors"+t.name][r]=!0},clearError:function(e,t,r){e["$$errors"+t.name]&&r in e["$$errors"+t.name]&&delete e["$$errors"+t.name][r]},getErrorMessages:function(e,t){var r=[];return e["$$errors"+t.name]&&0!==Object.keys(e["$$errors"+t.name]).length&&Object.keys(e["$$errors"+t.name]).sort().forEach(function(e){r.push(u.getMessage(e,t.validators[e]))}),r},getFormattedErrors:function(e,t){var r="",i=u.getErrorMessages(e,t);if(i.length)return i.forEach(function(e){r+=e+"
    "}),n.trustAsHtml("

    "+o.getSafeText("validate.error")+"

    "+r)},getTitleFormattedErrors:function(e,t){var r="",i=u.getErrorMessages(e,t);if(i.length)return i.forEach(function(e){r+=e+"\n"}),n.trustAsHtml(o.getSafeText("validate.error")+"\n"+r)},runValidators:function(e,t,n,o,a){if(n!==o){if(void 0===t.name||!t.name)throw new Error("colDef.name is required to perform validation");u.setValid(e,t);var r=function(t,r,i){return function(e){e||(u.setInvalid(t,r),u.setError(t,r,i),a&&a.api.validate.raise.validationFailed(t,r,n,o))}},i=[];for(var l in t.validators){u.clearError(e,t,l);var s=u.getValidator(l,t.validators[l]),d=c.when(s(o,n,e,t)).then(r(e,t,l));i.push(d)}return c.all(i)}},createDefaultValidators:function(){u.setValidator("minLength",function(r){return function(e,t){return null==t||""===t||t.length>=r}},function(e){return o.getSafeText("validate.minLength").replace("THRESHOLD",e)}),u.setValidator("maxLength",function(r){return function(e,t){return null==t||""===t||t.length<=r}},function(e){return o.getSafeText("validate.maxLength").replace("THRESHOLD",e)}),u.setValidator("required",function(r){return function(e,t){return!r||!(null==t||""===t)}},function(){return o.getSafeText("validate.required")})},initializeGrid:function(e,n){n.validate={isInvalid:u.isInvalid,getErrorMessages:u.getErrorMessages,getFormattedErrors:u.getFormattedErrors,getTitleFormattedErrors:u.getTitleFormattedErrors,runValidators:u.runValidators};var t={events:{validate:{validationFailed:function(e,t,r,i){}}},methods:{validate:{isInvalid:function(e,t){return n.validate.isInvalid(e,t)},getErrorMessages:function(e,t){return n.validate.getErrorMessages(e,t)},getFormattedErrors:function(e,t){return n.validate.getFormattedErrors(e,t)},getTitleFormattedErrors:function(e,t){return n.validate.getTitleFormattedErrors(e,t)}}}};n.api.registerEventsFromObject(t.events),n.api.registerMethodsFromObject(t.methods),n.edit&&n.api.edit.on.afterCellEdit(e,function(e,t,r,i){n.validate.runValidators(e,t,r,i,n)}),u.createDefaultValidators()}};return u}]),e.directive("uiGridValidate",["gridUtil","uiGridValidateService",function(e,n){return{priority:0,replace:!0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,t,r,i){n.initializeGrid(e,i.grid)},post:function(e,t,r,i){}}}}}])}(),angular.module("ui.grid").run(["$templateCache",function(e){"use strict";e.put("ui-grid/ui-grid-filter",'
     
     
    '),e.put("ui-grid/ui-grid-footer",''),e.put("ui-grid/ui-grid-grid-footer",''),e.put("ui-grid/ui-grid-header",'
    \x3c!-- theader --\x3e
    '),e.put("ui-grid/ui-grid-menu-button",'
     
    '),e.put("ui-grid/ui-grid-menu-header-item",'
  • '),e.put("ui-grid/ui-grid-no-header",'
    '),e.put("ui-grid/ui-grid-row","
    "),e.put("ui-grid/ui-grid",'
    \x3c!-- TODO (c0bra): add "scoped" attr here, eventually? --\x3e
    '),e.put("ui-grid/uiGridCell",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),e.put("ui-grid/uiGridColumnMenu",'
    \x3c!--
    \n
    \n
      \n
      \n
    • Sort Ascending
    • \n
    • Sort Descending
    • \n
    • Remove Sort
    • \n
      \n
    \n
    \n
    --\x3e
    '),e.put("ui-grid/uiGridFooterCell",'
    {{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}
    '),e.put("ui-grid/uiGridHeaderCell",'
    {{ col.displayName CUSTOM_FILTERS }} {{col.sort.priority + 1}}
    '),e.put("ui-grid/uiGridMenu",'
    '),e.put("ui-grid/uiGridMenuItem",''),e.put("ui-grid/uiGridRenderContainer","
    \x3c!-- All of these dom elements are replaced in place --\x3e
    "),e.put("ui-grid/uiGridViewport",'
    \x3c!-- tbody --\x3e
    '),e.put("ui-grid/cellEditor",'
    '),e.put("ui-grid/dropdownEditor",'
    '),e.put("ui-grid/fileChooserEditor",'
    '),e.put("ui-grid/emptyBaseLayerContainer",'
    '),e.put("ui-grid/expandableRow",'
    '),e.put("ui-grid/expandableRowHeader",'
    '),e.put("ui-grid/expandableScrollFiller","
     
    "),e.put("ui-grid/expandableTopRowHeader",'
    '),e.put("ui-grid/csvLink",'LINK_LABEL'),e.put("ui-grid/importerMenuItem",'
  • '),e.put("ui-grid/importerMenuItemContainer","
    "),e.put("ui-grid/pagination",'
    {{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    '),e.put("ui-grid/columnResizer",'
    '),e.put("ui-grid/gridFooterSelectedItems",'({{"search.selectedItems" | t}} {{grid.selection.selectedCount}})'),e.put("ui-grid/selectionHeaderCell",'
    \x3c!--
     
    --\x3e
    '),e.put("ui-grid/selectionRowHeader",'
    '),e.put("ui-grid/selectionRowHeaderButtons",''),e.put("ui-grid/selectionSelectAllButtons",''),e.put("ui-grid/treeBaseExpandAllButtons",'
    '),e.put("ui-grid/treeBaseHeaderCell",'
    '),e.put("ui-grid/treeBaseRowHeader",'
    '),e.put("ui-grid/treeBaseRowHeaderButtons",'
     
    '),e.put("ui-grid/cellTitleValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),e.put("ui-grid/cellTooltipValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.move-columns.js b/src/ui-grid.move-columns.js new file mode 100644 index 0000000000..cb8f7816de --- /dev/null +++ b/src/ui-grid.move-columns.js @@ -0,0 +1,581 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.moveColumns + * @description + * + * # ui.grid.moveColumns + * + * + * + * This module provides column moving capability to ui.grid. It enables to change the position of columns. + *
    + */ + var module = angular.module('ui.grid.moveColumns', ['ui.grid']); + + /** + * @ngdoc service + * @name ui.grid.moveColumns.service:uiGridMoveColumnService + * @description Service for column moving feature. + */ + module.service('uiGridMoveColumnService', ['$q', '$rootScope', '$log', 'ScrollEvent', 'uiGridConstants', 'gridUtil', function ($q, $rootScope, $log, ScrollEvent, uiGridConstants, gridUtil) { + var service = { + initializeGrid: function (grid) { + var self = this; + this.registerPublicApi(grid); + this.defaultGridOptions(grid.options); + grid.moveColumns = {orderCache: []}; // Used to cache the order before columns are rebuilt + grid.registerColumnBuilder(self.movableColumnBuilder); + grid.registerDataChangeCallback(self.verifyColumnOrder, [uiGridConstants.dataChange.COLUMN]); + }, + registerPublicApi: function (grid) { + var self = this; + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:PublicApi + * @description Public Api for column moving feature. + */ + var publicApi = { + events: { + /** + * @ngdoc event + * @name columnPositionChanged + * @eventOf ui.grid.moveColumns.api:PublicApi + * @description raised when column is moved + *
    +             *      gridApi.colMovable.on.columnPositionChanged(scope,function(colDef, originalPosition, newPosition) {})
    +             * 
    + * @param {object} colDef the column that was moved + * @param {integer} originalPosition of the column + * @param {integer} finalPosition of the column + */ + colMovable: { + columnPositionChanged: function (colDef, originalPosition, newPosition) { + } + } + }, + methods: { + /** + * @ngdoc method + * @name moveColumn + * @methodOf ui.grid.moveColumns.api:PublicApi + * @description Method can be used to change column position. + *
    +             *      gridApi.colMovable.moveColumn(oldPosition, newPosition)
    +             * 
    + * @param {integer} originalPosition of the column + * @param {integer} finalPosition of the column + */ + colMovable: { + moveColumn: function (originalPosition, finalPosition) { + var columns = grid.columns; + if (!angular.isNumber(originalPosition) || !angular.isNumber(finalPosition)) { + gridUtil.logError('MoveColumn: Please provide valid values for originalPosition and finalPosition'); + return; + } + var nonMovableColumns = 0; + for (var i = 0; i < columns.length; i++) { + if ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true) { + nonMovableColumns++; + } + } + if (originalPosition >= (columns.length - nonMovableColumns) || finalPosition >= (columns.length - nonMovableColumns)) { + gridUtil.logError('MoveColumn: Invalid values for originalPosition, finalPosition'); + return; + } + var findPositionForRenderIndex = function (index) { + var position = index; + for (var i = 0; i <= position; i++) { + if (angular.isDefined(columns[i]) && ((angular.isDefined(columns[i].colDef.visible) && columns[i].colDef.visible === false) || columns[i].isRowHeader === true)) { + position++; + } + } + return position; + }; + self.redrawColumnAtPosition(grid, findPositionForRenderIndex(originalPosition), findPositionForRenderIndex(finalPosition)); + } + } + } + }; + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + }, + defaultGridOptions: function (gridOptions) { + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:GridOptions + * + * @description Options for configuring the move column feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + /** + * @ngdoc object + * @name enableColumnMoving + * @propertyOf ui.grid.moveColumns.api:GridOptions + * @description If defined, sets the default value for the colMovable flag on each individual colDefs + * if their individual enableColumnMoving configuration is not defined. Defaults to true. + */ + gridOptions.enableColumnMoving = gridOptions.enableColumnMoving !== false; + }, + movableColumnBuilder: function (colDef, col, gridOptions) { + var promises = []; + /** + * @ngdoc object + * @name ui.grid.moveColumns.api:ColumnDef + * + * @description Column Definition for move column feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + /** + * @ngdoc object + * @name enableColumnMoving + * @propertyOf ui.grid.moveColumns.api:ColumnDef + * @description Enable column moving for the column. + */ + colDef.enableColumnMoving = colDef.enableColumnMoving === undefined ? gridOptions.enableColumnMoving + : colDef.enableColumnMoving; + return $q.all(promises); + }, + /** + * @ngdoc method + * @name updateColumnCache + * @methodOf ui.grid.moveColumns + * @description Cache the current order of columns, so we can restore them after new columnDefs are defined + */ + updateColumnCache: function(grid) { + grid.moveColumns.orderCache = grid.getOnlyDataColumns(); + }, + /** + * @ngdoc method + * @name verifyColumnOrder + * @methodOf ui.grid.moveColumns + * @description dataChangeCallback which uses the cached column order to restore the column order + * when it is reset by altering the columnDefs array. + */ + verifyColumnOrder: function(grid) { + var headerRowOffset = grid.rowHeaderColumns.length; + var newIndex; + + angular.forEach(grid.moveColumns.orderCache, function(cacheCol, cacheIndex) { + newIndex = grid.columns.indexOf(cacheCol); + if ( newIndex !== -1 && newIndex - headerRowOffset !== cacheIndex ) { + var column = grid.columns.splice(newIndex, 1)[0]; + grid.columns.splice(cacheIndex + headerRowOffset, 0, column); + } + }); + }, + redrawColumnAtPosition: function (grid, originalPosition, newPosition) { + var columns = grid.columns; + + if (originalPosition === newPosition) { + return; + } + + // check columns in between move-range to make sure they are visible columns + var pos = (originalPosition < newPosition) ? originalPosition + 1 : originalPosition - 1; + var i0 = Math.min(pos, newPosition); + for (i0; i0 <= Math.max(pos, newPosition); i0++) { + if (columns[i0].visible) { + break; + } + } + if (i0 > Math.max(pos, newPosition)) { + // no visible column found, column did not visibly move + return; + } + + var originalColumn = columns[originalPosition]; + if (originalColumn.colDef.enableColumnMoving) { + if (originalPosition > newPosition) { + for (var i1 = originalPosition; i1 > newPosition; i1--) { + columns[i1] = columns[i1 - 1]; + } + } + else if (newPosition > originalPosition) { + for (var i2 = originalPosition; i2 < newPosition; i2++) { + columns[i2] = columns[i2 + 1]; + } + } + columns[newPosition] = originalColumn; + service.updateColumnCache(grid); + grid.queueGridRefresh(); + $rootScope.$applyAsync(function () { + grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); + grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition); + }); + } + } + }; + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.moveColumns.directive:uiGridMoveColumns + * @element div + * @restrict A + * @description Adds column moving features to the ui-grid directive. + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.moveColumns']); + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO', age: 45 }, + { name: 'Frank', title: 'Lowly Developer', age: 25 }, + { name: 'Jenny', title: 'Highly Developer', age: 35 } + ]; + $scope.columnDefs = [ + {name: 'name'}, + {name: 'title'}, + {name: 'age'} + ]; + }]); + + + .grid { + width: 100%; + height: 150px; + } + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridMoveColumns', ['uiGridMoveColumnService', function (uiGridMoveColumnService) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridMoveColumnService.initializeGrid(uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.moveColumns.directive:uiGridHeaderCell + * @element div + * @restrict A + * + * @description Stacks on top of ui.grid.uiGridHeaderCell to provide capability to be able to move it to reposition column. + * + * On receiving mouseDown event headerCell is cloned, now as the mouse moves the cloned header cell also moved in the grid. + * In case the moving cloned header cell reaches the left or right extreme of grid, grid scrolling is triggered (if horizontal scroll exists). + * On mouseUp event column is repositioned at position where mouse is released and cloned header cell is removed. + * + * Events that invoke cloning of header cell: + * - mousedown + * + * Events that invoke movement of cloned header cell: + * - mousemove + * + * Events that invoke repositioning of column: + * - mouseup + */ + module.directive('uiGridHeaderCell', ['$q', 'gridUtil', 'uiGridMoveColumnService', '$document', '$log', 'uiGridConstants', 'ScrollEvent', + function ($q, gridUtil, uiGridMoveColumnService, $document, $log, uiGridConstants, ScrollEvent) { + return { + priority: -10, + require: '^uiGrid', + compile: function () { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + + if ($scope.col.colDef.enableColumnMoving) { + + /* + * Our general approach to column move is that we listen to a touchstart or mousedown + * event over the column header. When we hear one, then we wait for a move of the same type + * - if we are a touchstart then we listen for a touchmove, if we are a mousedown we listen for + * a mousemove (i.e. a drag) before we decide that there's a move underway. If there's never a move, + * and we instead get a mouseup or a touchend, then we just drop out again and do nothing. + * + */ + var $contentsElm = angular.element( $elm[0].querySelectorAll('.ui-grid-cell-contents') ); + + var gridLeft; + var previousMouseX; + var totalMouseMovement; + var rightMoveLimit; + var elmCloned = false; + var movingElm; + var reducedWidth; + var moveOccurred = false; + + var downFn = function( event ) { + // Setting some variables required for calculations. + gridLeft = $scope.grid.element[0].getBoundingClientRect().left; + if ( $scope.grid.hasLeftContainer() ) { + gridLeft += $scope.grid.renderContainers.left.header[0].getBoundingClientRect().width; + } + + previousMouseX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); + totalMouseMovement = 0; + rightMoveLimit = gridLeft + $scope.grid.getViewportWidth(); + + if ( event.type === 'mousedown' ) { + $document.on('mousemove', moveFn); + $document.on('mouseup', upFn); + } + else if ( event.type === 'touchstart' ) { + $document.on('touchmove', moveFn); + $document.on('touchend', upFn); + } + }; + + var moveFn = function( event ) { + var pageX = event.pageX || (event.originalEvent ? event.originalEvent.pageX : 0); + var changeValue = pageX - previousMouseX; + if ( changeValue === 0 ) { return; } + // Disable text selection in Chrome during column move + document.onselectstart = function() { return false; }; + + moveOccurred = true; + + if (!elmCloned) { + cloneElement(); + } + else if (elmCloned) { + moveElement(changeValue); + previousMouseX = pageX; + } + }; + + var upFn = function( event ) { + // Re-enable text selection after column move + document.onselectstart = null; + + // Remove the cloned element on mouse up. + if (movingElm) { + movingElm.remove(); + elmCloned = false; + } + + offAllEvents(); + onDownEvents(); + + if (!moveOccurred) { + return; + } + + var columns = $scope.grid.columns; + var columnIndex = 0; + for (var i = 0; i < columns.length; i++) { + if (columns[i].colDef.name !== $scope.col.colDef.name) { + columnIndex++; + } + else { + break; + } + } + + var targetIndex; + + // Case where column should be moved to a position on its left + if (totalMouseMovement < 0) { + var totalColumnsLeftWidth = 0; + var il; + if ( $scope.grid.isRTL() ) { + for (il = columnIndex + 1; il < columns.length; il++) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, il - 1); + break; + } + } + } + } + else { + for (il = columnIndex - 1; il >= 0; il--) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, il + 1); + break; + } + } + } + } + + // Case where column should be moved to beginning (or end in RTL) of the grid. + if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) { + targetIndex = 0; + if ( $scope.grid.isRTL() ) { + targetIndex = columns.length - 1; + } + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, targetIndex); + } + } + + // Case where column should be moved to a position on its right + else if (totalMouseMovement > 0) { + var totalColumnsRightWidth = 0; + var ir; + if ( $scope.grid.isRTL() ) { + for (ir = columnIndex - 1; ir > 0; ir--) { + if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) { + totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width; + if (totalColumnsRightWidth > totalMouseMovement) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, ir); + break; + } + } + } + } + else { + for (ir = columnIndex + 1; ir < columns.length; ir++) { + if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) { + totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width; + if (totalColumnsRightWidth > totalMouseMovement) { + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, ir - 1); + break; + } + } + } + } + + + // Case where column should be moved to end (or beginning in RTL) of the grid. + if (totalColumnsRightWidth < totalMouseMovement) { + targetIndex = columns.length - 1; + if ( $scope.grid.isRTL() ) { + targetIndex = 0; + } + uiGridMoveColumnService.redrawColumnAtPosition + ($scope.grid, columnIndex, targetIndex); + } + } + + + + }; + + var onDownEvents = function() { + $contentsElm.on('touchstart', downFn); + $contentsElm.on('mousedown', downFn); + }; + + var offAllEvents = function() { + $contentsElm.off('touchstart', downFn); + $contentsElm.off('mousedown', downFn); + + $document.off('mousemove', moveFn); + $document.off('touchmove', moveFn); + + $document.off('mouseup', upFn); + $document.off('touchend', upFn); + }; + + onDownEvents(); + + + var cloneElement = function () { + elmCloned = true; + + // Cloning header cell and appending to current header cell. + movingElm = $elm.clone(); + $elm.parent().append(movingElm); + + // Left of cloned element should be aligned to original header cell. + movingElm.addClass('movingColumn'); + var movingElementStyles = {}; + movingElementStyles.left = $elm[0].offsetLeft + 'px'; + var gridRight = $scope.grid.element[0].getBoundingClientRect().right; + var elmRight = $elm[0].getBoundingClientRect().right; + if (elmRight > gridRight) { + reducedWidth = $scope.col.drawnWidth + (gridRight - elmRight); + movingElementStyles.width = reducedWidth + 'px'; + } + movingElm.css(movingElementStyles); + }; + + var moveElement = function (changeValue) { + // Calculate total column width + var columns = $scope.grid.columns; + var totalColumnWidth = 0; + for (var i = 0; i < columns.length; i++) { + if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) { + totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width; + } + } + + // Calculate new position of left of column + var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1; + var currentElmRight = movingElm[0].getBoundingClientRect().right; + var newElementLeft; + + newElementLeft = currentElmLeft - gridLeft + changeValue; + newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit; + + // Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid + if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) { + movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft + + (newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'}); + } + else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) { + changeValue *= 8; + var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement'); + scrollEvent.x = {pixels: changeValue}; + scrollEvent.grid.scrollContainers('',scrollEvent); + } + + // Calculate total width of columns on the left of the moving column and the mouse movement + var totalColumnsLeftWidth = 0; + for (var il = 0; il < columns.length; il++) { + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { + if (columns[il].colDef.name !== $scope.col.colDef.name) { + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; + } + else { + break; + } + } + } + if ($scope.newScrollLeft === undefined) { + totalMouseMovement += changeValue; + } + else { + totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth; + } + + // Increase width of moving column, in case the rightmost column was moved and its width was + // decreased because of overflow + if (reducedWidth < $scope.col.drawnWidth) { + reducedWidth += Math.abs(changeValue); + movingElm.css({'width': reducedWidth + 'px'}); + } + }; + + $scope.$on('$destroy', offAllEvents); + } + } + }; + } + }; + }]); +})(); diff --git a/src/ui-grid.move-columns.min.js b/src/ui-grid.move-columns.min.js new file mode 100644 index 0000000000..8a6a57d241 --- /dev/null +++ b/src/ui-grid.move-columns.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.moveColumns",["ui.grid"]);e.service("uiGridMoveColumnService",["$q","$rootScope","$log","ScrollEvent","uiGridConstants","gridUtil",function(o,d,e,i,s,u){var f={initializeGrid:function(e){this.registerPublicApi(e),this.defaultGridOptions(e.options),e.moveColumns={orderCache:[]},e.registerColumnBuilder(this.movableColumnBuilder),e.registerDataChangeCallback(this.verifyColumnOrder,[s.dataChange.COLUMN])},registerPublicApi:function(t){var a=this,e={events:{colMovable:{columnPositionChanged:function(e,i,n){}}},methods:{colMovable:{moveColumn:function(e,i){var o=t.columns;if(angular.isNumber(e)&&angular.isNumber(i)){for(var n=0,r=0;r=o.length-n||i>=o.length-n)u.logError("MoveColumn: Invalid values for originalPosition, finalPosition");else{var l=function(e){for(var i=e,n=0;n<=i;n++)angular.isDefined(o[n])&&(angular.isDefined(o[n].colDef.visible)&&!1===o[n].colDef.visible||!0===o[n].isRowHeader)&&i++;return i};a.redrawColumnAtPosition(t,l(e),l(i))}}else u.logError("MoveColumn: Please provide valid values for originalPosition and finalPosition")}}}};t.api.registerEventsFromObject(e.events),t.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enableColumnMoving=!1!==e.enableColumnMoving},movableColumnBuilder:function(e,i,n){return e.enableColumnMoving=void 0===e.enableColumnMoving?n.enableColumnMoving:e.enableColumnMoving,o.all([])},updateColumnCache:function(e){e.moveColumns.orderCache=e.getOnlyDataColumns()},verifyColumnOrder:function(o){var r,l=o.rowHeaderColumns.length;angular.forEach(o.moveColumns.orderCache,function(e,i){if(-1!==(r=o.columns.indexOf(e))&&r-l!==i){var n=o.columns.splice(r,1)[0];o.columns.splice(i+l,0,n)}})},redrawColumnAtPosition:function(e,i,n){var o=e.columns;if(i!==n){for(var r=iMath.max(r,n))){var t=o[i];if(t.colDef.enableColumnMoving){if(nMath.abs(g)){w.redrawColumnAtPosition(s.grid,o,l-1);break}}else for(l=o-1;0<=l;l--)if((angular.isUndefined(n[l].colDef.visible)||!0===n[l].colDef.visible)&&(t+=n[l].drawnWidth||n[l].width||n[l].colDef.width)>Math.abs(g)){w.redrawColumnAtPosition(s.grid,o,l+1);break}tMath.ceil(f.grid.gridWidth)){e*=8;var a=new M(s.col.grid,null,null,"uiGridHeaderCell.moveElement");a.x={pixels:e},a.grid.scrollContainers("",a)}for(var u=0,d=0;dAlpha This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs. + * + * This module provides pagination support to ui-grid + */ + var module = angular.module('ui.grid.pagination', ['ng', 'ui.grid']); + + /** + * @ngdoc service + * @name ui.grid.pagination.service:uiGridPaginationService + * + * @description Service for the pagination feature + */ + module.service('uiGridPaginationService', ['gridUtil', + function (gridUtil) { + var service = { + /** + * @ngdoc method + * @name initializeGrid + * @methodOf ui.grid.pagination.service:uiGridPaginationService + * @description Attaches the service to a certain grid + * @param {Grid} grid The grid we want to work with + */ + initializeGrid: function (grid) { + service.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.pagination.api:PublicAPI + * + * @description Public API for the pagination feature + */ + var publicApi = { + events: { + pagination: { + /** + * @ngdoc event + * @name paginationChanged + * @eventOf ui.grid.pagination.api:PublicAPI + * @description This event fires when the pageSize or currentPage changes + * @param {int} currentPage requested page number + * @param {int} pageSize requested page size + */ + paginationChanged: function (currentPage, pageSize) { } + } + }, + methods: { + pagination: { + /** + * @ngdoc method + * @name getPage + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Returns the number of the current page + */ + getPage: function () { + return grid.options.enablePagination ? grid.options.paginationCurrentPage : null; + }, + /** + * @ngdoc method + * @name getFirstRowIndex + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Returns the index of the first row of the current page. + */ + getFirstRowIndex: function () { + if (grid.options.useCustomPagination) { + return grid.options.paginationPageSizes.reduce(function(result, size, index) { + return index < grid.options.paginationCurrentPage - 1 ? result + size : result; + }, 0); + } + return ((grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize); + }, + /** + * @ngdoc method + * @name getLastRowIndex + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Returns the index of the last row of the current page. + */ + getLastRowIndex: function () { + if (grid.options.useCustomPagination) { + return publicApi.methods.pagination.getFirstRowIndex() + grid.options.paginationPageSizes[grid.options.paginationCurrentPage - 1] - 1; + } + return Math.min(grid.options.paginationCurrentPage * grid.options.paginationPageSize, grid.options.totalItems) - 1; + }, + /** + * @ngdoc method + * @name getTotalPages + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Returns the total number of pages + */ + getTotalPages: function () { + if (!grid.options.enablePagination) { + return null; + } + + if (grid.options.useCustomPagination) { + return grid.options.paginationPageSizes.length; + } + + return (grid.options.totalItems === 0) ? 1 : Math.ceil(grid.options.totalItems / grid.options.paginationPageSize); + }, + /** + * @ngdoc method + * @name nextPage + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Moves to the next page, if possible + */ + nextPage: function () { + if (!grid.options.enablePagination) { + return; + } + + if (grid.options.totalItems > 0) { + grid.options.paginationCurrentPage = Math.min( + grid.options.paginationCurrentPage + 1, + publicApi.methods.pagination.getTotalPages() + ); + } + else { + grid.options.paginationCurrentPage++; + } + }, + /** + * @ngdoc method + * @name previousPage + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Moves to the previous page, if we're not on the first page + */ + previousPage: function () { + if (!grid.options.enablePagination) { + return; + } + + grid.options.paginationCurrentPage = Math.max(grid.options.paginationCurrentPage - 1, 1); + }, + /** + * @ngdoc method + * @name seek + * @methodOf ui.grid.pagination.api:PublicAPI + * @description Moves to the requested page + * @param {int} page The number of the page that should be displayed + */ + seek: function (page) { + if (!grid.options.enablePagination) { + return; + } + if (!angular.isNumber(page) || page < 1) { + throw 'Invalid page number: ' + page; + } + + grid.options.paginationCurrentPage = Math.min(page, publicApi.methods.pagination.getTotalPages()); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + + var processPagination = function( renderableRows ) { + if (grid.options.useExternalPagination || !grid.options.enablePagination) { + return renderableRows; + } + // client side pagination + var pageSize = parseInt(grid.options.paginationPageSize, 10); + var currentPage = parseInt(grid.options.paginationCurrentPage, 10); + + var visibleRows = renderableRows.filter(function (row) { return row.visible; }); + grid.options.totalItems = visibleRows.length; + + var firstRow = publicApi.methods.pagination.getFirstRowIndex(); + var lastRow = publicApi.methods.pagination.getLastRowIndex(); + + if (firstRow > visibleRows.length) { + currentPage = grid.options.paginationCurrentPage = 1; + firstRow = (currentPage - 1) * pageSize; + } + return visibleRows.slice(firstRow, lastRow + 1); + }; + + grid.registerRowsProcessor(processPagination, 900 ); + + }, + defaultGridOptions: function (gridOptions) { + /** + * @ngdoc object + * @name ui.grid.pagination.api:GridOptions + * + * @description GridOptions for the pagination feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc property + * @name enablePagination + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Enables pagination. Defaults to true. + */ + gridOptions.enablePagination = gridOptions.enablePagination !== false; + /** + * @ngdoc property + * @name enablePaginationControls + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Enables the paginator at the bottom of the grid. Turn this off if you want to implement your + * own controls outside the grid. + */ + gridOptions.enablePaginationControls = gridOptions.enablePaginationControls !== false; + /** + * @ngdoc property + * @name useExternalPagination + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Disables client side pagination. When true, handle the paginationChanged event and set data + * and totalItems. Defaults to `false` + */ + gridOptions.useExternalPagination = gridOptions.useExternalPagination === true; + + /** + * @ngdoc property + * @name useCustomPagination + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Disables client-side pagination. When true, handle the `paginationChanged` event and set `data`, + * `firstRowIndex`, `lastRowIndex`, and `totalItems`. Defaults to `false`. + */ + gridOptions.useCustomPagination = gridOptions.useCustomPagination === true; + + /** + * @ngdoc property + * @name totalItems + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Total number of items, set automatically when using client side pagination, but needs set by user + * for server side pagination + */ + if (gridUtil.isNullOrUndefined(gridOptions.totalItems)) { + gridOptions.totalItems = 0; + } + /** + * @ngdoc property + * @name paginationPageSizes + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Array of page sizes, defaults to `[250, 500, 1000]` + */ + if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSizes)) { + gridOptions.paginationPageSizes = [250, 500, 1000]; + } + /** + * @ngdoc property + * @name paginationPageSize + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Page size, defaults to the first item in paginationPageSizes, or 0 if paginationPageSizes is empty + */ + if (gridUtil.isNullOrUndefined(gridOptions.paginationPageSize)) { + if (gridOptions.paginationPageSizes.length > 0) { + gridOptions.paginationPageSize = gridOptions.paginationPageSizes[0]; + } + else { + gridOptions.paginationPageSize = 0; + } + } + /** + * @ngdoc property + * @name paginationCurrentPage + * @propertyOf ui.grid.pagination.api:GridOptions + * @description Current page number, defaults to 1 + */ + if (gridUtil.isNullOrUndefined(gridOptions.paginationCurrentPage)) { + gridOptions.paginationCurrentPage = 1; + } + + /** + * @ngdoc property + * @name paginationTemplate + * @propertyOf ui.grid.pagination.api:GridOptions + * @description A custom template for the pager, defaults to `ui-grid/pagination` + */ + if (gridUtil.isNullOrUndefined(gridOptions.paginationTemplate)) { + gridOptions.paginationTemplate = 'ui-grid/pagination'; + } + }, + /** + * @ngdoc method + * @methodOf ui.grid.pagination.service:uiGridPaginationService + * @name uiGridPaginationService + * @description Raises paginationChanged and calls refresh for client side pagination + * @param {Grid} grid the grid for which the pagination changed + * @param {int} currentPage requested page number + * @param {int} pageSize requested page size + */ + onPaginationChanged: function (grid, currentPage, pageSize) { + grid.api.pagination.raise.paginationChanged(currentPage, pageSize); + if (!grid.options.useExternalPagination) { + grid.queueGridRefresh(); // client side pagination + } + } + }; + + return service; + } + ]); + /** + * @ngdoc directive + * @name ui.grid.pagination.directive:uiGridPagination + * @element div + * @restrict A + * + * @description Adds pagination features to grid + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.pagination']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Alex', car: 'Toyota' }, + { name: 'Sam', car: 'Lexus' }, + { name: 'Joe', car: 'Dodge' }, + { name: 'Bob', car: 'Buick' }, + { name: 'Cindy', car: 'Ford' }, + { name: 'Brian', car: 'Audi' }, + { name: 'Malcom', car: 'Mercedes Benz' }, + { name: 'Dave', car: 'Ford' }, + { name: 'Stacey', car: 'Audi' }, + { name: 'Amy', car: 'Acura' }, + { name: 'Scott', car: 'Toyota' }, + { name: 'Ryan', car: 'BMW' }, + ]; + + $scope.gridOptions = { + data: 'data', + paginationPageSizes: [5, 10, 25], + paginationPageSize: 5, + columnDefs: [ + {name: 'name'}, + {name: 'car'} + ] + } + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridPagination', ['gridUtil', 'uiGridPaginationService', + function (gridUtil, uiGridPaginationService) { + return { + priority: -200, + scope: false, + require: 'uiGrid', + link: { + pre: function ($scope, $elm, $attr, uiGridCtrl) { + uiGridPaginationService.initializeGrid(uiGridCtrl.grid); + + gridUtil.getTemplate(uiGridCtrl.grid.options.paginationTemplate) + .then(function (contents) { + var template = angular.element(contents); + + $elm.append(template); + uiGridCtrl.innerCompile(template); + }); + } + } + }; + } + ]); + + /** + * @ngdoc directive + * @name ui.grid.pagination.directive:uiGridPager + * @element div + * + * @description Panel for handling pagination + */ + module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService', 'i18nConstants', + function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService, i18nConstants) { + return { + priority: -200, + scope: true, + require: '^uiGrid', + link: function ($scope, $elm, $attr, uiGridCtrl) { + var defaultFocusElementSelector = '.ui-grid-pager-control-input'; + + $scope.aria = i18nService.getSafeText('pagination.aria'); // Returns an object with all of the aria labels + + var updateLabels = function() { + $scope.paginationApi = uiGridCtrl.grid.api.pagination; + $scope.sizesLabel = i18nService.getSafeText('pagination.sizes'); + $scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems'); + $scope.paginationOf = i18nService.getSafeText('pagination.of'); + $scope.paginationThrough = i18nService.getSafeText('pagination.through'); + }; + + updateLabels(); + + $scope.$on(i18nConstants.UPDATE_EVENT, updateLabels); + + var options = uiGridCtrl.grid.options; + + uiGridCtrl.grid.renderContainers.body.registerViewportAdjuster(function (adjustment) { + if (options.enablePaginationControls) { + adjustment.height = adjustment.height - gridUtil.elementHeight($elm, "padding"); + } + return adjustment; + }); + + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) { + if (!grid.options.useExternalPagination) { + grid.options.totalItems = grid.rows.length; + } + }, [uiGridConstants.dataChange.ROW]); + + $scope.$on('$destroy', dataChangeDereg); + + var deregP = $scope.$watch('grid.options.paginationCurrentPage + grid.options.paginationPageSize', function (newValues, oldValues) { + if (newValues === oldValues || oldValues === undefined) { + return; + } + + if (!angular.isNumber(options.paginationCurrentPage) || options.paginationCurrentPage < 1) { + options.paginationCurrentPage = 1; + return; + } + + if (options.totalItems > 0 && options.paginationCurrentPage > $scope.paginationApi.getTotalPages()) { + options.paginationCurrentPage = $scope.paginationApi.getTotalPages(); + return; + } + + uiGridPaginationService.onPaginationChanged($scope.grid, options.paginationCurrentPage, options.paginationPageSize); + }); + + $scope.$on('$destroy', function() { + deregP(); + }); + + $scope.cantPageForward = function () { + if ($scope.paginationApi.getTotalPages()) { + return $scope.cantPageToLast(); + } + else { + return options.data.length < 1; + } + }; + + $scope.cantPageToLast = function () { + var totalPages = $scope.paginationApi.getTotalPages(); + + return !totalPages || options.paginationCurrentPage >= totalPages; + }; + + $scope.cantPageBackward = function () { + return options.paginationCurrentPage <= 1; + }; + + var focusToInputIf = function(condition) { + if (condition) { + gridUtil.focus.bySelector($elm, defaultFocusElementSelector); + } + }; + + // Takes care of setting focus to the middle element when focus is lost + $scope.pageFirstPageClick = function () { + $scope.paginationApi.seek(1); + focusToInputIf($scope.cantPageBackward()); + }; + + $scope.pagePreviousPageClick = function () { + $scope.paginationApi.previousPage(); + focusToInputIf($scope.cantPageBackward()); + }; + + $scope.pageNextPageClick = function () { + $scope.paginationApi.nextPage(); + focusToInputIf($scope.cantPageForward()); + }; + + $scope.pageLastPageClick = function () { + $scope.paginationApi.seek($scope.paginationApi.getTotalPages()); + focusToInputIf($scope.cantPageToLast()); + }; + } + }; + } + ]); +})(); + +angular.module('ui.grid.pagination').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/pagination', + "
    0\">/ {{ paginationApi.getTotalPages() }}
    1 && !grid.options.useCustomPagination\">  {{sizesLabel}}
    {{grid.options.paginationPageSize}} {{sizesLabel}}
    0\">{{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    " + ); + +}]); diff --git a/src/ui-grid.pagination.min.js b/src/ui-grid.pagination.min.js new file mode 100644 index 0000000000..eeffd63863 --- /dev/null +++ b/src/ui-grid.pagination.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var i=angular.module("ui.grid.pagination",["ng","ui.grid"]);i.service("uiGridPaginationService",["gridUtil",function(a){var i={initializeGrid:function(o){i.defaultGridOptions(o.options);var g={events:{pagination:{paginationChanged:function(i,a){}}},methods:{pagination:{getPage:function(){return o.options.enablePagination?o.options.paginationCurrentPage:null},getFirstRowIndex:function(){return o.options.useCustomPagination?o.options.paginationPageSizes.reduce(function(i,a,n){return nn.length&&(t=((o.options.paginationCurrentPage=1)-1)*a),n.slice(t,e+1)},900)},defaultGridOptions:function(i){i.enablePagination=!1!==i.enablePagination,i.enablePaginationControls=!1!==i.enablePaginationControls,i.useExternalPagination=!0===i.useExternalPagination,i.useCustomPagination=!0===i.useCustomPagination,a.isNullOrUndefined(i.totalItems)&&(i.totalItems=0),a.isNullOrUndefined(i.paginationPageSizes)&&(i.paginationPageSizes=[250,500,1e3]),a.isNullOrUndefined(i.paginationPageSize)&&(0n.paginationApi.getTotalPages()?o.paginationCurrentPage=n.paginationApi.getTotalPages():p.onPaginationChanged(n.grid,o.paginationCurrentPage,o.paginationPageSize))});n.$on("$destroy",function(){r()}),n.cantPageForward=function(){return n.paginationApi.getTotalPages()?n.cantPageToLast():o.data.length<1},n.cantPageToLast=function(){var i=n.paginationApi.getTotalPages();return!i||o.paginationCurrentPage>=i},n.cantPageBackward=function(){return o.paginationCurrentPage<=1};var s=function(i){i&&u.focus.bySelector(a,".ui-grid-pager-control-input")};n.pageFirstPageClick=function(){n.paginationApi.seek(1),s(n.cantPageBackward())},n.pagePreviousPageClick=function(){n.paginationApi.previousPage(),s(n.cantPageBackward())},n.pageNextPageClick=function(){n.paginationApi.nextPage(),s(n.cantPageForward())},n.pageLastPageClick=function(){n.paginationApi.seek(n.paginationApi.getTotalPages()),s(n.cantPageToLast())}}}}])}(),angular.module("ui.grid.pagination").run(["$templateCache",function(i){"use strict";i.put("ui-grid/pagination",'
    {{ 1 + paginationApi.getFirstRowIndex() }} - {{ 1 + paginationApi.getLastRowIndex() }} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.pinning.js b/src/ui-grid.pinning.js new file mode 100644 index 0000000000..c46cb24705 --- /dev/null +++ b/src/ui-grid.pinning.js @@ -0,0 +1,280 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.pinning + * @description + * + * # ui.grid.pinning + * + * + * + * This module provides column pinning to the end user via menu options in the column header + * + *
    + */ + + var module = angular.module('ui.grid.pinning', ['ui.grid']); + + module.constant('uiGridPinningConstants', { + container: { + LEFT: 'left', + RIGHT: 'right', + NONE: '' + } + }); + + module.service('uiGridPinningService', ['gridUtil', 'GridRenderContainer', 'i18nService', 'uiGridPinningConstants', function (gridUtil, GridRenderContainer, i18nService, uiGridPinningConstants) { + var service = { + + initializeGrid: function (grid) { + service.defaultGridOptions(grid.options); + + // Register a column builder to add new menu items for pinning left and right + grid.registerColumnBuilder(service.pinningColumnBuilder); + + /** + * @ngdoc object + * @name ui.grid.pinning.api:PublicApi + * + * @description Public Api for pinning feature + */ + var publicApi = { + events: { + pinning: { + /** + * @ngdoc event + * @name columnPinned + * @eventOf ui.grid.pinning.api:PublicApi + * @description raised when column pin state has changed + *
    +               *   gridApi.pinning.on.columnPinned(scope, function(colDef){})
    +               * 
    + * @param {object} colDef the column that was changed + * @param {string} container the render container the column is in ('left', 'right', '') + */ + columnPinned: function(colDef, container) { + } + } + }, + methods: { + pinning: { + /** + * @ngdoc function + * @name pinColumn + * @methodOf ui.grid.pinning.api:PublicApi + * @description pin column left, right, or none + *
    +               *   gridApi.pinning.pinColumn(col, uiGridPinningConstants.container.LEFT)
    +               * 
    + * @param {gridColumn} col the column being pinned + * @param {string} container one of the recognised types + * from uiGridPinningConstants + */ + pinColumn: function(col, container) { + service.pinColumn(grid, col, container); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.pinning.api:GridOptions + * + * @description GridOptions for pinning feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enablePinning + * @propertyOf ui.grid.pinning.api:GridOptions + * @description Enable pinning for the entire grid. + *
    Defaults to true + */ + gridOptions.enablePinning = gridOptions.enablePinning !== false; + /** + * @ngdoc object + * @name hidePinLeft + * @propertyOf ui.grid.pinning.api:GridOptions + * @description Hide Pin Left for the entire grid. + *
    Defaults to false + */ + gridOptions.hidePinLeft = gridOptions.enablePinning && gridOptions.hidePinLeft; + /** + * @ngdoc object + * @name hidePinRight + * @propertyOf ui.grid.pinning.api:GridOptions + * @description Hide Pin Right pinning for the entire grid. + *
    Defaults to false + */ + gridOptions.hidePinRight = gridOptions.enablePinning && gridOptions.hidePinRight; + }, + + pinningColumnBuilder: function (colDef, col, gridOptions) { + // default to true unless gridOptions or colDef is explicitly false + + /** + * @ngdoc object + * @name ui.grid.pinning.api:ColumnDef + * + * @description ColumnDef for pinning feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name enablePinning + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Enable pinning for the individual column. + *
    Defaults to true + */ + colDef.enablePinning = colDef.enablePinning === undefined ? gridOptions.enablePinning : colDef.enablePinning; + /** + * @ngdoc object + * @name hidePinLeft + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Hide Pin Left for the individual column. + *
    Defaults to false + */ + colDef.hidePinLeft = colDef.hidePinLeft === undefined ? gridOptions.hidePinLeft : colDef.hidePinLeft; + /** + * @ngdoc object + * @name hidePinRight + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Hide Pin Right for the individual column. + *
    Defaults to false + */ + colDef.hidePinRight = colDef.hidePinRight === undefined ? gridOptions.hidePinRight : colDef.hidePinRight; + + /** + * @ngdoc object + * @name pinnedLeft + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Column is pinned left when grid is rendered + *
    Defaults to false + */ + + /** + * @ngdoc object + * @name pinnedRight + * @propertyOf ui.grid.pinning.api:ColumnDef + * @description Column is pinned right when grid is rendered + *
    Defaults to false + */ + if (colDef.pinnedLeft) { + col.renderContainer = 'left'; + col.grid.createLeftContainer(); + } + else if (colDef.pinnedRight) { + col.renderContainer = 'right'; + col.grid.createRightContainer(); + } + + if (!colDef.enablePinning) { + return; + } + + var pinColumnLeftAction = { + name: 'ui.grid.pinning.pinLeft', + title: i18nService.get().pinning.pinLeft, + icon: 'ui-grid-icon-left-open', + shown: function () { + return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'left'; + }, + action: function () { + service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.LEFT); + } + }; + + var pinColumnRightAction = { + name: 'ui.grid.pinning.pinRight', + title: i18nService.get().pinning.pinRight, + icon: 'ui-grid-icon-right-open', + shown: function () { + return typeof(this.context.col.renderContainer) === 'undefined' || !this.context.col.renderContainer || this.context.col.renderContainer !== 'right'; + }, + action: function () { + service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.RIGHT); + } + }; + + var removePinAction = { + name: 'ui.grid.pinning.unpin', + title: i18nService.get().pinning.unpin, + icon: 'ui-grid-icon-cancel', + shown: function () { + return typeof(this.context.col.renderContainer) !== 'undefined' && this.context.col.renderContainer !== null && this.context.col.renderContainer !== 'body'; + }, + action: function () { + service.pinColumn(this.context.col.grid, this.context.col, uiGridPinningConstants.container.NONE); + } + }; + + // Skip from menu if hidePinLeft or hidePinRight is true + if (!colDef.hidePinLeft && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinLeft')) { + col.menuItems.push(pinColumnLeftAction); + } + if (!colDef.hidePinRight && !gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.pinRight')) { + col.menuItems.push(pinColumnRightAction); + } + if (!gridUtil.arrayContainsObjectWithProperty(col.menuItems, 'name', 'ui.grid.pinning.unpin')) { + col.menuItems.push(removePinAction); + } + }, + + pinColumn: function(grid, col, container) { + if (container === uiGridPinningConstants.container.NONE) { + col.renderContainer = null; + col.colDef.pinnedLeft = col.colDef.pinnedRight = false; + } + else { + col.renderContainer = container; + if (container === uiGridPinningConstants.container.LEFT) { + grid.createLeftContainer(); + } + else if (container === uiGridPinningConstants.container.RIGHT) { + grid.createRightContainer(); + } + } + + grid.refresh() + .then(function() { + grid.api.pinning.raise.columnPinned( col.colDef, container ); + }); + } + }; + + return service; + }]); + + module.directive('uiGridPinning', ['gridUtil', 'uiGridPinningService', + function (gridUtil, uiGridPinningService) { + return { + require: 'uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridPinningService.initializeGrid(uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); +})(); diff --git a/src/ui-grid.pinning.min.js b/src/ui-grid.pinning.min.js new file mode 100644 index 0000000000..210185ca0d --- /dev/null +++ b/src/ui-grid.pinning.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var n=angular.module("ui.grid.pinning",["ui.grid"]);n.constant("uiGridPinningConstants",{container:{LEFT:"left",RIGHT:"right",NONE:""}}),n.service("uiGridPinningService",["gridUtil","GridRenderContainer","i18nService","uiGridPinningConstants",function(c,n,d,u){var a={initializeGrid:function(e){a.defaultGridOptions(e.options),e.registerColumnBuilder(a.pinningColumnBuilder);var n={events:{pinning:{columnPinned:function(n,i){}}},methods:{pinning:{pinColumn:function(n,i){a.pinColumn(e,n,i)}}}};e.api.registerEventsFromObject(n.events),e.api.registerMethodsFromObject(n.methods)},defaultGridOptions:function(n){n.enablePinning=!1!==n.enablePinning,n.hidePinLeft=n.enablePinning&&n.hidePinLeft,n.hidePinRight=n.enablePinning&&n.hidePinRight},pinningColumnBuilder:function(n,i,e){if(n.enablePinning=void 0===n.enablePinning?e.enablePinning:n.enablePinning,n.hidePinLeft=void 0===n.hidePinLeft?e.hidePinLeft:n.hidePinLeft,n.hidePinRight=void 0===n.hidePinRight?e.hidePinRight:n.hidePinRight,n.pinnedLeft?(i.renderContainer="left",i.grid.createLeftContainer()):n.pinnedRight&&(i.renderContainer="right",i.grid.createRightContainer()),n.enablePinning){var t={name:"ui.grid.pinning.pinLeft",title:d.get().pinning.pinLeft,icon:"ui-grid-icon-left-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"left"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.LEFT)}},r={name:"ui.grid.pinning.pinRight",title:d.get().pinning.pinRight,icon:"ui-grid-icon-right-open",shown:function(){return void 0===this.context.col.renderContainer||!this.context.col.renderContainer||"right"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.RIGHT)}},o={name:"ui.grid.pinning.unpin",title:d.get().pinning.unpin,icon:"ui-grid-icon-cancel",shown:function(){return void 0!==this.context.col.renderContainer&&null!==this.context.col.renderContainer&&"body"!==this.context.col.renderContainer},action:function(){a.pinColumn(this.context.col.grid,this.context.col,u.container.NONE)}};n.hidePinLeft||c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.pinLeft")||i.menuItems.push(t),n.hidePinRight||c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.pinRight")||i.menuItems.push(r),c.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.pinning.unpin")||i.menuItems.push(o)}},pinColumn:function(n,i,e){e===u.container.NONE?(i.renderContainer=null,i.colDef.pinnedLeft=i.colDef.pinnedRight=!1):(i.renderContainer=e)===u.container.LEFT?n.createLeftContainer():e===u.container.RIGHT&&n.createRightContainer(),n.refresh().then(function(){n.api.pinning.raise.columnPinned(i.colDef,e)})}};return a}]),n.directive("uiGridPinning",["gridUtil","uiGridPinningService",function(n,r){return{require:"uiGrid",scope:!1,compile:function(){return{pre:function(n,i,e,t){r.initializeGrid(t.grid)},post:function(n,i,e,t){}}}}}])}(); \ No newline at end of file diff --git a/src/ui-grid.resize-columns.js b/src/ui-grid.resize-columns.js new file mode 100644 index 0000000000..e1e705384e --- /dev/null +++ b/src/ui-grid.resize-columns.js @@ -0,0 +1,573 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function() { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.resizeColumns + * @description + * + * # ui.grid.resizeColumns + * + * + * + * This module allows columns to be resized. + */ + var module = angular.module('ui.grid.resizeColumns', ['ui.grid']); + + module.service('uiGridResizeColumnsService', ['gridUtil', '$q', '$rootScope', + function (gridUtil, $q, $rootScope) { + return { + defaultGridOptions: function(gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.resizeColumns.api:GridOptions + * + * @description GridOptions for resizeColumns feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enableColumnResizing + * @propertyOf ui.grid.resizeColumns.api:GridOptions + * @description Enable column resizing on the entire grid + *
    Defaults to true + */ + gridOptions.enableColumnResizing = gridOptions.enableColumnResizing !== false; + + // legacy support + // use old name if it is explicitly false + if (gridOptions.enableColumnResize === false) { + gridOptions.enableColumnResizing = false; + } + }, + + colResizerColumnBuilder: function (colDef, col, gridOptions) { + var promises = []; + + /** + * @ngdoc object + * @name ui.grid.resizeColumns.api:ColumnDef + * + * @description ColumnDef for resizeColumns feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + /** + * @ngdoc object + * @name enableColumnResizing + * @propertyOf ui.grid.resizeColumns.api:ColumnDef + * @description Enable column resizing on an individual column + *
    Defaults to GridOptions.enableColumnResizing + */ + // default to true unless gridOptions or colDef is explicitly false + colDef.enableColumnResizing = colDef.enableColumnResizing === undefined ? gridOptions.enableColumnResizing : colDef.enableColumnResizing; + + + // legacy support of old option name + if (colDef.enableColumnResize === false) { + colDef.enableColumnResizing = false; + } + + return $q.all(promises); + }, + + registerPublicApi: function (grid) { + /** + * @ngdoc object + * @name ui.grid.resizeColumns.api:PublicApi + * @description Public Api for column resize feature. + */ + var publicApi = { + events: { + /** + * @ngdoc event + * @name columnSizeChanged + * @eventOf ui.grid.resizeColumns.api:PublicApi + * @description raised when column is resized + *
    +                 *      gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange) {})
    +                 * 
    + * @param {object} colDef the column that was resized + * @param {integer} delta of the column size change + */ + colResizable: { + columnSizeChanged: function (colDef, deltaChange) { + } + } + } + }; + grid.api.registerEventsFromObject(publicApi.events); + }, + + fireColumnSizeChanged: function (grid, colDef, deltaChange) { + $rootScope.$applyAsync(function () { + if ( grid.api.colResizable ) { + grid.api.colResizable.raise.columnSizeChanged(colDef, deltaChange); + } else { + gridUtil.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events."); + } + }); + }, + + // get either this column, or the column next to this column, to resize, + // returns the column we're going to resize + findTargetCol: function(col, position, rtlMultiplier) { + var renderContainer = col.getRenderContainer(); + + if (position === 'left') { + // Get the column to the left of this one + var colIndex = renderContainer.visibleColumnCache.indexOf(col); + if (colIndex === 0) { + return renderContainer.visibleColumnCache[0]; + } + return renderContainer.visibleColumnCache[colIndex - 1 * rtlMultiplier]; + } else { + return col; + } + } + }; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.resizeColumns.directive:uiGridResizeColumns + * @element div + * @restrict A + * @description + * Enables resizing for all columns on the grid. If, for some reason, you want to use the ui-grid-resize-columns directive, but not allow column resizing, you can explicitly set the + * option to false. This prevents resizing for the entire grid, regardless of individual columnDef options. + * + * @example + + + + +
    +
    +
    +
    + + + +
    + */ + module.directive('uiGridResizeColumns', ['gridUtil', 'uiGridResizeColumnsService', function (gridUtil, uiGridResizeColumnsService) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridResizeColumnsService.defaultGridOptions(uiGridCtrl.grid.options); + uiGridCtrl.grid.registerColumnBuilder( uiGridResizeColumnsService.colResizerColumnBuilder); + uiGridResizeColumnsService.registerPublicApi(uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + + // Extend the uiGridHeaderCell directive + module.directive('uiGridHeaderCell', ['gridUtil', '$templateCache', '$compile', '$q', 'uiGridResizeColumnsService', 'uiGridConstants', function (gridUtil, $templateCache, $compile, $q, uiGridResizeColumnsService, uiGridConstants) { + return { + // Run after the original uiGridHeaderCell + priority: -10, + require: '^uiGrid', + // scope: false, + compile: function() { + return { + post: function ($scope, $elm, $attrs, uiGridCtrl) { + var grid = uiGridCtrl.grid; + + if (grid.options.enableColumnResizing) { + var columnResizerElm = $templateCache.get('ui-grid/columnResizer'); + + var rtlMultiplier = 1; + // when in RTL mode reverse the direction using the rtlMultiplier and change the position to left + if (grid.isRTL()) { + $scope.position = 'left'; + rtlMultiplier = -1; + } + + var displayResizers = function() { + + // remove any existing resizers. + var resizers = $elm[0].getElementsByClassName('ui-grid-column-resizer'); + for ( var i = 0; i < resizers.length; i++ ) { + angular.element(resizers[i]).remove(); + } + + // get the target column for the left resizer + var otherCol = uiGridResizeColumnsService.findTargetCol($scope.col, 'left', rtlMultiplier); + var renderContainer = $scope.col.getRenderContainer(); + + // Don't append the left resizer if this is the first column or the column to the left of this one has resizing disabled + if (otherCol && renderContainer.visibleColumnCache.indexOf($scope.col) !== 0 && otherCol.colDef.enableColumnResizing !== false) { + var resizerLeft = angular.element(columnResizerElm).clone(); + resizerLeft.attr('position', 'left'); + + $elm.prepend(resizerLeft); + $compile(resizerLeft)($scope); + } + + // Don't append the right resizer if this column has resizing disabled + if ($scope.col.colDef.enableColumnResizing !== false) { + var resizerRight = angular.element(columnResizerElm).clone(); + resizerRight.attr('position', 'right'); + + $elm.append(resizerRight); + $compile(resizerRight)($scope); + } + }; + + displayResizers(); + + var waitDisplay = function() { + $scope.$applyAsync(displayResizers); + }; + + var dataChangeDereg = grid.registerDataChangeCallback( waitDisplay, [uiGridConstants.dataChange.COLUMN] ); + + $scope.$on( '$destroy', dataChangeDereg ); + } + } + }; + } + }; + }]); + + + + /** + * @ngdoc directive + * @name ui.grid.resizeColumns.directive:uiGridColumnResizer + * @element div + * @restrict A + * + * @description + * Draggable handle that controls column resizing. + * + * @example + + + + +
    +
    +
    +
    + + // TODO: e2e specs? + + // TODO: post-resize a horizontal scroll event should be fired + +
    + */ + module.directive('uiGridColumnResizer', ['$document', 'gridUtil', 'uiGridConstants', 'uiGridResizeColumnsService', function ($document, gridUtil, uiGridConstants, uiGridResizeColumnsService) { + var resizeOverlay = angular.element('
    '); + + return { + priority: 0, + scope: { + col: '=', + position: '@', + renderIndex: '=' + }, + require: '?^uiGrid', + link: function ($scope, $elm, $attrs, uiGridCtrl) { + var startX = 0, + x = 0, + gridLeft = 0, + rtlMultiplier = 1; + + // when in RTL mode reverse the direction using the rtlMultiplier and change the position to left + if (uiGridCtrl.grid.isRTL()) { + $scope.position = 'left'; + rtlMultiplier = -1; + } + + if ($scope.position === 'left') { + $elm.addClass('left'); + } + else if ($scope.position === 'right') { + $elm.addClass('right'); + } + + // Refresh the grid canvas + // takes an argument representing the diff along the X-axis that the resize had + function refreshCanvas(xDiff) { + // Then refresh the grid canvas, rebuilding the styles so that the scrollbar updates its size + uiGridCtrl.grid.refreshCanvas(true).then( function() { + uiGridCtrl.grid.queueGridRefresh(); + }); + } + + // Check that the requested width isn't wider than the maxWidth, or narrower than the minWidth + // Returns the new recommended with, after constraints applied + function constrainWidth(col, width) { + var newWidth = width; + + // If the new width would be less than the column's allowably minimum width, don't allow it + if (col.minWidth && newWidth < col.minWidth) { + newWidth = col.minWidth; + } + else if (col.maxWidth && newWidth > col.maxWidth) { + newWidth = col.maxWidth; + } + + return newWidth; + } + + + /* + * Our approach to event handling aims to deal with both touch devices and mouse devices + * We register down handlers on both touch and mouse. When a touchstart or mousedown event + * occurs, we register the corresponding touchmove/touchend, or mousemove/mouseend events. + * + * This way we can listen for both without worrying about the fact many touch devices also emulate + * mouse events - basically whichever one we hear first is what we'll go with. + */ + function moveFunction(event, args) { + if (event.originalEvent) { event = event.originalEvent; } + event.preventDefault(); + + x = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft; + + if (x < 0) { x = 0; } + else if (x > uiGridCtrl.grid.gridWidth) { x = uiGridCtrl.grid.gridWidth; } + + var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); + + // Don't resize if it's disabled on this column + if (col.colDef.enableColumnResizing === false) { + return; + } + + if (!uiGridCtrl.grid.element.hasClass('column-resizing')) { + uiGridCtrl.grid.element.addClass('column-resizing'); + } + + // Get the diff along the X axis + var xDiff = x - startX; + + // Get the width that this mouse would give the column + var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10); + + // check we're not outside the allowable bounds for this column + x = x + ( constrainWidth(col, newWidth) - newWidth ) * rtlMultiplier; + + resizeOverlay.css({ left: x + 'px' }); + + uiGridCtrl.fireEvent(uiGridConstants.events.ITEM_DRAGGING); + } + + + function upFunction(event) { + if (event.originalEvent) { event = event.originalEvent; } + event.preventDefault(); + + uiGridCtrl.grid.element.removeClass('column-resizing'); + + resizeOverlay.remove(); + + // Resize the column + x = (event.changedTouches ? event.changedTouches[0] : event).clientX - gridLeft; + var xDiff = x - startX; + + if (xDiff === 0) { + // no movement, so just reset event handlers, including turning back on both + // down events - we turned one off when this event started + offAllEvents(); + onDownEvents(); + return; + } + + var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); + + // Don't resize if it's disabled on this column + if (col.colDef.enableColumnResizing === false) { + return; + } + + // Get the new width + var newWidth = parseInt(col.drawnWidth + xDiff * rtlMultiplier, 10); + + // check we're not outside the allowable bounds for this column + col.width = constrainWidth(col, newWidth); + col.hasCustomWidth = true; + + refreshCanvas(xDiff); + + uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff); + + // stop listening of up and move events - wait for next down + // reset the down events - we will have turned one off when this event started + offAllEvents(); + onDownEvents(); + } + + + var downFunction = function(event, args) { + if (event.originalEvent) { event = event.originalEvent; } + event.stopPropagation(); + + // Get the left offset of the grid + // gridLeft = uiGridCtrl.grid.element[0].offsetLeft; + gridLeft = uiGridCtrl.grid.element[0].getBoundingClientRect().left; + + // Get the starting X position, which is the X coordinate of the click minus the grid's offset + startX = (event.targetTouches ? event.targetTouches[0] : event).clientX - gridLeft; + + // Append the resizer overlay + uiGridCtrl.grid.element.append(resizeOverlay); + + // Place the resizer overlay at the start position + resizeOverlay.css({ left: startX }); + + // Add handlers for move and up events - if we were mousedown then we listen for mousemove and mouseup, if + // we were touchdown then we listen for touchmove and touchup. Also remove the handler for the equivalent + // down event - so if we're touchdown, then remove the mousedown handler until this event is over, if we're + // mousedown then remove the touchdown handler until this event is over, this avoids processing duplicate events + if ( event.type === 'touchstart' ) { + $document.on('touchend', upFunction); + $document.on('touchmove', moveFunction); + $elm.off('mousedown', downFunction); + } + else { + $document.on('mouseup', upFunction); + $document.on('mousemove', moveFunction); + $elm.off('touchstart', downFunction); + } + }; + + var onDownEvents = function() { + $elm.on('mousedown', downFunction); + $elm.on('touchstart', downFunction); + }; + + var offAllEvents = function() { + $document.off('mouseup', upFunction); + $document.off('touchend', upFunction); + $document.off('mousemove', moveFunction); + $document.off('touchmove', moveFunction); + $elm.off('mousedown', downFunction); + $elm.off('touchstart', downFunction); + }; + + onDownEvents(); + + + // On doubleclick, resize to fit all rendered cells + var dblClickFn = function(event, args) { + event.stopPropagation(); + + var col = uiGridResizeColumnsService.findTargetCol($scope.col, $scope.position, rtlMultiplier); + + // Don't resize if it's disabled on this column + if (col.colDef.enableColumnResizing === false) { + return; + } + + // Go through the rendered rows and find out the max size for the data in this column + var maxWidth = 0; + + // Get the parent render container element + var renderContainerElm = gridUtil.closestElm($elm, '.ui-grid-render-container'); + + // Get the cell contents so we measure correctly. For the header cell we have to account for the sort icon and the menu buttons, if present + var cells = renderContainerElm.querySelectorAll('.' + uiGridConstants.COL_CLASS_PREFIX + col.uid + ' .ui-grid-cell-contents'); + Array.prototype.forEach.call(cells, function (cell) { + // Get the cell width + // gridUtil.logDebug('width', gridUtil.elementWidth(cell)); + + // Account for the menu button if it exists + var menuButton; + if (angular.element(cell).parent().hasClass('ui-grid-header-cell')) { + menuButton = angular.element(cell).parent()[0].querySelectorAll('.ui-grid-column-menu-button'); + } + + gridUtil.fakeElement(cell, {}, function(newElm) { + // Make the element float since it's a div and can expand to fill its container + var e = angular.element(newElm); + e.attr('style', 'float: left'); + + var width = gridUtil.elementWidth(e); + + if (menuButton) { + var menuButtonWidth = gridUtil.elementWidth(menuButton); + width = width + menuButtonWidth; + } + + if (width > maxWidth) { + maxWidth = width; + } + }); + }); + + // check we're not outside the allowable bounds for this column + var newWidth = constrainWidth(col, maxWidth); + var xDiff = newWidth - col.drawnWidth; + col.width = newWidth; + col.hasCustomWidth = true; + + refreshCanvas(xDiff); + + uiGridResizeColumnsService.fireColumnSizeChanged(uiGridCtrl.grid, col.colDef, xDiff); }; + $elm.on('dblclick', dblClickFn); + + $elm.on('$destroy', function() { + $elm.off('dblclick', dblClickFn); + offAllEvents(); + }); + } + }; + }]); +})(); + +angular.module('ui.grid.resizeColumns').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/columnResizer', + "
    " + ); + +}]); diff --git a/src/ui-grid.resize-columns.min.js b/src/ui-grid.resize-columns.min.js new file mode 100644 index 0000000000..9871bfcad5 --- /dev/null +++ b/src/ui-grid.resize-columns.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.resizeColumns",["ui.grid"]);e.service("uiGridResizeColumnsService",["gridUtil","$q","$rootScope",function(r,o,t){return{defaultGridOptions:function(e){e.enableColumnResizing=!1!==e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1)},colResizerColumnBuilder:function(e,i,n){return e.enableColumnResizing=void 0===e.enableColumnResizing?n.enableColumnResizing:e.enableColumnResizing,!1===e.enableColumnResize&&(e.enableColumnResizing=!1),o.all([])},registerPublicApi:function(e){e.api.registerEventsFromObject({colResizable:{columnSizeChanged:function(e,i){}}})},fireColumnSizeChanged:function(e,i,n){t.$applyAsync(function(){e.api.colResizable?e.api.colResizable.raise.columnSizeChanged(i,n):r.logError("The resizeable api is not registered, this may indicate that you've included the module but not added the 'ui-grid-resize-columns' directive to your grid definition. Cannot raise any events.")})},findTargetCol:function(e,i,n){var r=e.getRenderContainer();if("left"!==i)return e;var o=r.visibleColumnCache.indexOf(e);return 0===o?r.visibleColumnCache[0]:r.visibleColumnCache[o-1*n]}}}]),e.directive("uiGridResizeColumns",["gridUtil","uiGridResizeColumnsService",function(e,o){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,n,r){o.defaultGridOptions(r.grid.options),r.grid.registerColumnBuilder(o.colResizerColumnBuilder),o.registerPublicApi(r.grid)},post:function(e,i,n,r){}}}}}]),e.directive("uiGridHeaderCell",["gridUtil","$templateCache","$compile","$q","uiGridResizeColumnsService","uiGridConstants",function(e,t,d,i,c,g){return{priority:-10,require:"^uiGrid",compile:function(){return{post:function(l,u,e,i){var n=i.grid;if(n.options.enableColumnResizing){var a=t.get("ui-grid/columnResizer"),s=1;n.isRTL()&&(l.position="left",s=-1);var r=function(){for(var e=u[0].getElementsByClassName("ui-grid-column-resizer"),i=0;i');return{priority:0,scope:{col:"=",position:"@",renderIndex:"="},require:"?^uiGrid",link:function(u,a,e,s){var t=0,l=0,d=0,c=1;function g(e){s.grid.refreshCanvas(!0).then(function(){s.grid.queueGridRefresh()})}function f(e,i){var n=i;return e.minWidth&&ne.maxWidth&&(n=e.maxWidth),n}function n(e,i){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),(l=(e.targetTouches?e.targetTouches[0]:e).clientX-d)<0?l=0:l>s.grid.gridWidth&&(l=s.grid.gridWidth);var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){s.grid.element.hasClass("column-resizing")||s.grid.element.addClass("column-resizing");var r=l-t,o=parseInt(n.drawnWidth+r*c,10);l+=(f(n,o)-o)*c,R.css({left:l+"px"}),s.fireEvent(p.events.ITEM_DRAGGING)}}function r(e){e.originalEvent&&(e=e.originalEvent),e.preventDefault(),s.grid.element.removeClass("column-resizing"),R.remove();var i=(l=(e.changedTouches?e.changedTouches[0]:e).clientX-d)-t;if(0===i)return C(),void m();var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){var r=parseInt(n.drawnWidth+i*c,10);n.width=f(n,r),n.hasCustomWidth=!0,g(),z.fireColumnSizeChanged(s.grid,n.colDef,i),C(),m()}}s.grid.isRTL()&&(u.position="left",c=-1),"left"===u.position?a.addClass("left"):"right"===u.position&&a.addClass("right");var o=function(e,i){e.originalEvent&&(e=e.originalEvent),e.stopPropagation(),d=s.grid.element[0].getBoundingClientRect().left,t=(e.targetTouches?e.targetTouches[0]:e).clientX-d,s.grid.element.append(R),R.css({left:t}),"touchstart"===e.type?(v.on("touchend",r),v.on("touchmove",n),a.off("mousedown",o)):(v.on("mouseup",r),v.on("mousemove",n),a.off("touchstart",o))},m=function(){a.on("mousedown",o),a.on("touchstart",o)},C=function(){v.off("mouseup",r),v.off("touchend",r),v.off("mousemove",n),v.off("touchmove",n),a.off("mousedown",o),a.off("touchstart",o)};m();var i=function(e,i){e.stopPropagation();var n=z.findTargetCol(u.col,u.position,c);if(!1!==n.colDef.enableColumnResizing){var o=0,r=h.closestElm(a,".ui-grid-render-container").querySelectorAll("."+p.COL_CLASS_PREFIX+n.uid+" .ui-grid-cell-contents");Array.prototype.forEach.call(r,function(e){var r;angular.element(e).parent().hasClass("ui-grid-header-cell")&&(r=angular.element(e).parent()[0].querySelectorAll(".ui-grid-column-menu-button")),h.fakeElement(e,{},function(e){var i=angular.element(e);i.attr("style","float: left");var n=h.elementWidth(i);r&&(n+=h.elementWidth(r));o')}]); \ No newline at end of file diff --git a/src/ui-grid.row-edit.js b/src/ui-grid.row-edit.js new file mode 100644 index 0000000000..fae86ff4c5 --- /dev/null +++ b/src/ui-grid.row-edit.js @@ -0,0 +1,716 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.rowEdit + * @description + * + * # ui.grid.rowEdit + * + * + * + * This module extends the edit feature to provide tracking and saving of rows + * of data. The tutorial provides more information on how this feature is best + * used {@link tutorial/205_row_editable here}. + *
    + * This feature depends on usage of the ui-grid-edit feature, and also benefits + * from use of ui-grid-cellNav to provide the full spreadsheet-like editing + * experience + * + */ + + var module = angular.module('ui.grid.rowEdit', ['ui.grid', 'ui.grid.edit', 'ui.grid.cellNav']); + + /** + * @ngdoc object + * @name ui.grid.rowEdit.constant:uiGridRowEditConstants + * + * @description constants available in row edit module + */ + module.constant('uiGridRowEditConstants', { + }); + + /** + * @ngdoc service + * @name ui.grid.rowEdit.service:uiGridRowEditService + * + * @description Services for row editing features + */ + module.service('uiGridRowEditService', ['$interval', '$q', 'uiGridConstants', 'uiGridRowEditConstants', 'gridUtil', + function ($interval, $q, uiGridConstants, uiGridRowEditConstants, gridUtil) { + + var service = { + + initializeGrid: function (scope, grid) { + /** + * @ngdoc object + * @name ui.grid.rowEdit.api:PublicApi + * + * @description Public Api for rowEdit feature + */ + + grid.rowEdit = {}; + + var publicApi = { + events: { + rowEdit: { + /** + * @ngdoc event + * @eventOf ui.grid.rowEdit.api:PublicApi + * @name saveRow + * @description raised when a row is ready for saving. Once your + * row has saved you may need to use angular.extend to update the + * data entity with any changed data from your save (for example, + * lock version information if you're using optimistic locking, + * or last update time/user information). + * + * Your method should call setSavePromise somewhere in the body before + * returning control. The feature will then wait, with the gridRow greyed out + * whilst this promise is being resolved. + * + *
    +                 *      gridApi.rowEdit.on.saveRow(scope,function(rowEntity) {})
    +                 * 
    + * and somewhere within the event handler: + *
    +                 *      gridApi.rowEdit.setSavePromise( rowEntity, savePromise)
    +                 * 
    + * @param {object} rowEntity the options.data element that was edited + * @returns {promise} Your saveRow method should return a promise, the + * promise should either be resolved (implying successful save), or + * rejected (implying an error). + */ + saveRow: function (rowEntity) { + } + } + }, + methods: { + rowEdit: { + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name setSavePromise + * @description Sets the promise associated with the row save, mandatory that + * the saveRow event handler calls this method somewhere before returning. + *
    +                 *      gridApi.rowEdit.setSavePromise(rowEntity, savePromise)
    +                 * 
    + * @param {object} rowEntity a data row from the grid for which a save has + * been initiated + * @param {promise} savePromise the promise that will be resolved when the + * save is successful, or rejected if the save fails + * + */ + setSavePromise: function ( rowEntity, savePromise) { + service.setSavePromise(grid, rowEntity, savePromise); + }, + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name getDirtyRows + * @description Returns all currently dirty rows + *
    +                 *      gridApi.rowEdit.getDirtyRows(grid)
    +                 * 
    + * @returns {array} An array of gridRows that are currently dirty + * + */ + getDirtyRows: function () { + return grid.rowEdit.dirtyRows ? grid.rowEdit.dirtyRows : []; + }, + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name getErrorRows + * @description Returns all currently errored rows + *
    +                 *      gridApi.rowEdit.getErrorRows(grid)
    +                 * 
    + * @returns {array} An array of gridRows that are currently in error + * + */ + getErrorRows: function () { + return grid.rowEdit.errorRows ? grid.rowEdit.errorRows : []; + }, + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name flushDirtyRows + * @description Triggers a save event for all currently dirty rows, could + * be used where user presses a save button or navigates away from the page + *
    +                 *      gridApi.rowEdit.flushDirtyRows(grid)
    +                 * 
    + * @returns {promise} a promise that represents the aggregate of all + * of the individual save promises - i.e. it will be resolved when all + * the individual save promises have been resolved. + * + */ + flushDirtyRows: function () { + return service.flushDirtyRows(grid); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name setRowsDirty + * @description Sets each of the rows passed in dataRows + * to be dirty. Note that if you have only just inserted the + * rows into your data you will need to wait for a $digest cycle + * before the gridRows are present - so often you would wrap this + * call in a $interval or $timeout. Also, you must pass row.entity + * into this function rather than row objects themselves. + *
    +                 *      $interval( function() {
    +                 *        gridApi.rowEdit.setRowsDirty(myDataRows);
    +                 *      }, 0, 1);
    +                 * 
    + * @param {array} dataRows the data entities for which the gridRows + * should be set dirty. + * + */ + setRowsDirty: function ( dataRows) { + service.setRowsDirty(grid, dataRows); + }, + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.api:PublicApi + * @name setRowsClean + * @description Sets each of the rows passed in dataRows + * to be clean, removing them from the dirty cache and the error cache, + * and clearing the error flag and the dirty flag + *
    +                 *      var gridRows = $scope.gridApi.rowEdit.getDirtyRows();
    +                 *      var dataRows = gridRows.map( function( gridRow ) { return gridRow.entity; });
    +                 *      $scope.gridApi.rowEdit.setRowsClean( dataRows );
    +                 * 
    + * @param {array} dataRows the data entities for which the gridRows + * should be set clean. + * + */ + setRowsClean: function ( dataRows) { + service.setRowsClean(grid, dataRows); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + + grid.api.core.on.renderingComplete( scope, function ( gridApi ) { + grid.api.edit.on.afterCellEdit( scope, service.endEditCell ); + grid.api.edit.on.beginCellEdit( scope, service.beginEditCell ); + grid.api.edit.on.cancelCellEdit( scope, service.cancelEditCell ); + + if ( grid.api.cellNav ) { + grid.api.cellNav.on.navigate( scope, service.navigate ); + } + }); + + }, + + defaultGridOptions: function (gridOptions) { + + /** + * @ngdoc object + * @name ui.grid.rowEdit.api:GridOptions + * + * @description Options for configuring the rowEdit feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name saveRow + * @description Returns a function that saves the specified row from the grid, + * and returns a promise + * @param {object} grid the grid for which dirty rows should be flushed + * @param {GridRow} gridRow the row that should be saved + * @returns {function} the saveRow function returns a function. That function + * in turn, when called, returns a promise relating to the save callback + */ + saveRow: function ( grid, gridRow ) { + var self = this; + + return function() { + gridRow.isSaving = true; + + if ( gridRow.rowEditSavePromise ) { + // don't save the row again if it's already saving - that causes stale object exceptions + return gridRow.rowEditSavePromise; + } + + var promise = grid.api.rowEdit.raise.saveRow( gridRow.entity ); + + if ( gridRow.rowEditSavePromise ) { + gridRow.rowEditSavePromise.then( self.processSuccessPromise( grid, gridRow ), self.processErrorPromise( grid, gridRow )); + } else { + gridUtil.logError( 'A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise' ); + } + return promise; + }; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name setSavePromise + * @description Sets the promise associated with the row save, mandatory that + * the saveRow event handler calls this method somewhere before returning. + *
    +         *      gridApi.rowEdit.setSavePromise(grid, rowEntity)
    +         * 
    + * @param {object} grid the grid for which dirty rows should be returned + * @param {object} rowEntity a data row from the grid for which a save has + * been initiated + * @param {promise} savePromise the promise that will be resolved when the + * save is successful, or rejected if the save fails + * + */ + setSavePromise: function (grid, rowEntity, savePromise) { + var gridRow = grid.getRow( rowEntity ); + gridRow.rowEditSavePromise = savePromise; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name processSuccessPromise + * @description Returns a function that processes the successful + * resolution of a save promise + * @param {object} grid the grid for which the promise should be processed + * @param {GridRow} gridRow the row that has been saved + * @returns {function} the success handling function + */ + processSuccessPromise: function ( grid, gridRow ) { + var self = this; + + return function() { + delete gridRow.isSaving; + delete gridRow.isDirty; + delete gridRow.isError; + delete gridRow.rowEditSaveTimer; + delete gridRow.rowEditSavePromise; + self.removeRow( grid.rowEdit.errorRows, gridRow ); + self.removeRow( grid.rowEdit.dirtyRows, gridRow ); + }; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name processErrorPromise + * @description Returns a function that processes the failed + * resolution of a save promise + * @param {object} grid the grid for which the promise should be processed + * @param {GridRow} gridRow the row that is now in error + * @returns {function} the error handling function + */ + processErrorPromise: function ( grid, gridRow ) { + return function() { + delete gridRow.isSaving; + delete gridRow.rowEditSaveTimer; + delete gridRow.rowEditSavePromise; + + gridRow.isError = true; + + if (!grid.rowEdit.errorRows) { + grid.rowEdit.errorRows = []; + } + if (!service.isRowPresent( grid.rowEdit.errorRows, gridRow ) ) { + grid.rowEdit.errorRows.push( gridRow ); + } + }; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name removeRow + * @description Removes a row from a cache of rows - either + * grid.rowEdit.errorRows or grid.rowEdit.dirtyRows. If the row + * is not present silently does nothing. + * @param {array} rowArray the array from which to remove the row + * @param {GridRow} gridRow the row that should be removed + */ + removeRow: function( rowArray, removeGridRow ) { + if (typeof(rowArray) === 'undefined' || rowArray === null) { + return; + } + + rowArray.forEach( function( gridRow, index ) { + if ( gridRow.uid === removeGridRow.uid ) { + rowArray.splice( index, 1); + } + }); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name isRowPresent + * @description Checks whether a row is already present + * in the given array + * @param {array} rowArray the array in which to look for the row + * @param {GridRow} gridRow the row that should be looked for + */ + isRowPresent: function( rowArray, removeGridRow ) { + var present = false; + rowArray.forEach( function( gridRow, index ) { + if ( gridRow.uid === removeGridRow.uid ) { + present = true; + } + }); + return present; + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name flushDirtyRows + * @description Triggers a save event for all currently dirty rows, could + * be used where user presses a save button or navigates away from the page + *
    +         *      gridApi.rowEdit.flushDirtyRows(grid)
    +         * 
    + * @param {object} grid the grid for which dirty rows should be flushed + * @returns {promise} a promise that represents the aggregate of all + * of the individual save promises - i.e. it will be resolved when all + * the individual save promises have been resolved. + * + */ + flushDirtyRows: function(grid) { + var promises = []; + grid.api.rowEdit.getDirtyRows().forEach( function( gridRow ) { + service.cancelTimer( grid, gridRow ); + service.saveRow( grid, gridRow )(); + promises.push( gridRow.rowEditSavePromise ); + }); + + return $q.all( promises ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name endEditCell + * @description Receives an afterCellEdit event from the edit function, + * and sets flags as appropriate. Only the rowEntity parameter + * is processed, although other params are available. Grid + * is automatically provided by the gridApi. + * @param {object} rowEntity the data entity for which the cell + * was edited + */ + endEditCell: function( rowEntity, colDef, newValue, previousValue ) { + var grid = this.grid; + var gridRow = grid.getRow( rowEntity ); + if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, dirty flag cannot be set' ); return; } + + if ( newValue !== previousValue || gridRow.isDirty ) { + if ( !grid.rowEdit.dirtyRows ) { + grid.rowEdit.dirtyRows = []; + } + + if ( !gridRow.isDirty ) { + gridRow.isDirty = true; + grid.rowEdit.dirtyRows.push( gridRow ); + } + + delete gridRow.isError; + + service.considerSetTimer( grid, gridRow ); + } + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name beginEditCell + * @description Receives a beginCellEdit event from the edit function, + * and cancels any rowEditSaveTimers if present, as the user is still editing + * this row. Only the rowEntity parameter + * is processed, although other params are available. Grid + * is automatically provided by the gridApi. + * @param {object} rowEntity the data entity for which the cell + * editing has commenced + */ + beginEditCell: function( rowEntity, colDef ) { + var grid = this.grid; + var gridRow = grid.getRow( rowEntity ); + if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be cancelled' ); return; } + + service.cancelTimer( grid, gridRow ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name cancelEditCell + * @description Receives a cancelCellEdit event from the edit function, + * and if the row was already dirty, restarts the save timer. If the row + * was not already dirty, then it's not dirty now either and does nothing. + * + * Only the rowEntity parameter + * is processed, although other params are available. Grid + * is automatically provided by the gridApi. + * + * @param {object} rowEntity the data entity for which the cell + * editing was cancelled + */ + cancelEditCell: function( rowEntity, colDef ) { + var grid = this.grid; + var gridRow = grid.getRow( rowEntity ); + if ( !gridRow ) { gridUtil.logError( 'Unable to find rowEntity in grid data, timer cannot be set' ); return; } + + service.considerSetTimer( grid, gridRow ); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name navigate + * @description cellNav tells us that the selected cell has changed. If + * the new row had a timer running, then stop it similar to in a beginCellEdit + * call. If the old row is dirty and not the same as the new row, then + * start a timer on it. + * @param {object} newRowCol the row and column that were selected + * @param {object} oldRowCol the row and column that was left + * + */ + navigate: function( newRowCol, oldRowCol ) { + var grid = this.grid; + if ( newRowCol.row.rowEditSaveTimer ) { + service.cancelTimer( grid, newRowCol.row ); + } + + if ( oldRowCol && oldRowCol.row && oldRowCol.row !== newRowCol.row ) { + service.considerSetTimer( grid, oldRowCol.row ); + } + }, + + + /** + * @ngdoc property + * @propertyOf ui.grid.rowEdit.api:GridOptions + * @name rowEditWaitInterval + * @description How long the grid should wait for another change on this row + * before triggering a save (in milliseconds). If set to -1, then saves are + * never triggered by timer (implying that the user will call flushDirtyRows() + * manually) + * + * @example + * Setting the wait interval to 4 seconds + *
    +         *   $scope.gridOptions = { rowEditWaitInterval: 4000 }
    +         * 
    + * + */ + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name considerSetTimer + * @description Consider setting a timer on this row (if it is dirty). if there is a timer running + * on the row and the row isn't currently saving, cancel it, using cancelTimer, then if the row is + * dirty and not currently saving then set a new timer + * @param {object} grid the grid for which we are processing + * @param {GridRow} gridRow the row for which the timer should be adjusted + * + */ + considerSetTimer: function( grid, gridRow ) { + service.cancelTimer( grid, gridRow ); + + if ( gridRow.isDirty && !gridRow.isSaving ) { + if ( grid.options.rowEditWaitInterval !== -1 ) { + var waitTime = grid.options.rowEditWaitInterval ? grid.options.rowEditWaitInterval : 2000; + gridRow.rowEditSaveTimer = $interval( service.saveRow( grid, gridRow ), waitTime, 1); + } + } + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name cancelTimer + * @description cancel the $interval for any timer running on this row + * then delete the timer itself + * @param {object} grid the grid for which we are processing + * @param {GridRow} gridRow the row for which the timer should be adjusted + * + */ + cancelTimer: function( grid, gridRow ) { + if ( gridRow.rowEditSaveTimer && !gridRow.isSaving ) { + $interval.cancel(gridRow.rowEditSaveTimer); + delete gridRow.rowEditSaveTimer; + } + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name setRowsDirty + * @description Sets each of the rows passed in dataRows + * to be dirty. note that if you have only just inserted the + * rows into your data you will need to wait for a $digest cycle + * before the gridRows are present - so often you would wrap this + * call in a $interval or $timeout + *
    +         *      $interval( function() {
    +         *        gridApi.rowEdit.setRowsDirty( myDataRows);
    +         *      }, 0, 1);
    +         * 
    + * @param {object} grid the grid for which rows should be set dirty + * @param {array} dataRows the data entities for which the gridRows + * should be set dirty. + * + */ + setRowsDirty: function( grid, myDataRows ) { + var gridRow; + myDataRows.forEach( function( value, index ) { + gridRow = grid.getRow( value ); + if ( gridRow ) { + if ( !grid.rowEdit.dirtyRows ) { + grid.rowEdit.dirtyRows = []; + } + + if ( !gridRow.isDirty ) { + gridRow.isDirty = true; + grid.rowEdit.dirtyRows.push( gridRow ); + } + + delete gridRow.isError; + + service.considerSetTimer( grid, gridRow ); + } else { + gridUtil.logError( "requested row not found in rowEdit.setRowsDirty, row was: " + value ); + } + }); + }, + + + /** + * @ngdoc method + * @methodOf ui.grid.rowEdit.service:uiGridRowEditService + * @name setRowsClean + * @description Sets each of the rows passed in dataRows + * to be clean, clearing the dirty flag and the error flag, and removing + * the rows from the dirty and error caches. + * @param {object} grid the grid for which rows should be set clean + * @param {array} dataRows the data entities for which the gridRows + * should be set clean. + * + */ + setRowsClean: function( grid, myDataRows ) { + var gridRow; + + myDataRows.forEach( function( value, index ) { + gridRow = grid.getRow( value ); + if ( gridRow ) { + delete gridRow.isDirty; + service.removeRow( grid.rowEdit.dirtyRows, gridRow ); + service.cancelTimer( grid, gridRow ); + + delete gridRow.isError; + service.removeRow( grid.rowEdit.errorRows, gridRow ); + } else { + gridUtil.logError( "requested row not found in rowEdit.setRowsClean, row was: " + value ); + } + }); + } + + }; + + return service; + + }]); + + /** + * @ngdoc directive + * @name ui.grid.rowEdit.directive:uiGridEdit + * @element div + * @restrict A + * + * @description Adds row editing features to the ui-grid-edit directive. + * + */ + module.directive('uiGridRowEdit', ['gridUtil', 'uiGridRowEditService', 'uiGridEditConstants', + function (gridUtil, uiGridRowEditService, uiGridEditConstants) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridRowEditService.initializeGrid($scope, uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.rowEdit.directive:uiGridViewport + * @element div + * + * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used + * for the grid row to allow coloring of saving and error rows + */ + module.directive('uiGridViewport', + ['$compile', 'uiGridConstants', 'gridUtil', '$parse', + function ($compile, uiGridConstants, gridUtil, $parse) { + return { + priority: -200, // run after default directive + scope: false, + compile: function ($elm, $attrs) { + var rowRepeatDiv = angular.element($elm.children().children()[0]); + + var existingNgClass = rowRepeatDiv.attr("ng-class"); + var newNgClass = ''; + if ( existingNgClass ) { + newNgClass = existingNgClass.slice(0, -1) + ", 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}"; + } else { + newNgClass = "{'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}"; + } + rowRepeatDiv.attr("ng-class", newNgClass); + + return { + pre: function ($scope, $elm, $attrs, controllers) { + + }, + post: function ($scope, $elm, $attrs, controllers) { + } + }; + } + }; + }]); + +})(); diff --git a/src/ui-grid.row-edit.min.js b/src/ui-grid.row-edit.min.js new file mode 100644 index 0000000000..3554bb43b8 --- /dev/null +++ b/src/ui-grid.row-edit.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var r=angular.module("ui.grid.rowEdit",["ui.grid","ui.grid.edit","ui.grid.cellNav"]);r.constant("uiGridRowEditConstants",{}),r.service("uiGridRowEditService",["$interval","$q","uiGridConstants","uiGridRowEditConstants","gridUtil",function(t,r,i,e,s){var d={initializeGrid:function(i,e){e.rowEdit={};var r={events:{rowEdit:{saveRow:function(r){}}},methods:{rowEdit:{setSavePromise:function(r,i){d.setSavePromise(e,r,i)},getDirtyRows:function(){return e.rowEdit.dirtyRows?e.rowEdit.dirtyRows:[]},getErrorRows:function(){return e.rowEdit.errorRows?e.rowEdit.errorRows:[]},flushDirtyRows:function(){return d.flushDirtyRows(e)},setRowsDirty:function(r){d.setRowsDirty(e,r)},setRowsClean:function(r){d.setRowsClean(e,r)}}}};e.api.registerEventsFromObject(r.events),e.api.registerMethodsFromObject(r.methods),e.api.core.on.renderingComplete(i,function(r){e.api.edit.on.afterCellEdit(i,d.endEditCell),e.api.edit.on.beginCellEdit(i,d.beginEditCell),e.api.edit.on.cancelCellEdit(i,d.cancelEditCell),e.api.cellNav&&e.api.cellNav.on.navigate(i,d.navigate)})},defaultGridOptions:function(r){},saveRow:function(i,e){var t=this;return function(){if(e.isSaving=!0,e.rowEditSavePromise)return e.rowEditSavePromise;var r=i.api.rowEdit.raise.saveRow(e.entity);return e.rowEditSavePromise?e.rowEditSavePromise.then(t.processSuccessPromise(i,e),t.processErrorPromise(i,e)):s.logError("A promise was not returned when saveRow event was raised, either nobody is listening to event, or event handler did not return a promise"),r}},setSavePromise:function(r,i,e){r.getRow(i).rowEditSavePromise=e},processSuccessPromise:function(r,i){var e=this;return function(){delete i.isSaving,delete i.isDirty,delete i.isError,delete i.rowEditSaveTimer,delete i.rowEditSavePromise,e.removeRow(r.rowEdit.errorRows,i),e.removeRow(r.rowEdit.dirtyRows,i)}},processErrorPromise:function(r,i){return function(){delete i.isSaving,delete i.rowEditSaveTimer,delete i.rowEditSavePromise,i.isError=!0,r.rowEdit.errorRows||(r.rowEdit.errorRows=[]),d.isRowPresent(r.rowEdit.errorRows,i)||r.rowEdit.errorRows.push(i)}},removeRow:function(e,t){null!=e&&e.forEach(function(r,i){r.uid===t.uid&&e.splice(i,1)})},isRowPresent:function(r,e){var t=!1;return r.forEach(function(r,i){r.uid===e.uid&&(t=!0)}),t},flushDirtyRows:function(i){var e=[];return i.api.rowEdit.getDirtyRows().forEach(function(r){d.cancelTimer(i,r),d.saveRow(i,r)(),e.push(r.rowEditSavePromise)}),r.all(e)},endEditCell:function(r,i,e,t){var o=this.grid,n=o.getRow(r);n?(e!==t||n.isDirty)&&(o.rowEdit.dirtyRows||(o.rowEdit.dirtyRows=[]),n.isDirty||(n.isDirty=!0,o.rowEdit.dirtyRows.push(n)),delete n.isError,d.considerSetTimer(o,n)):s.logError("Unable to find rowEntity in grid data, dirty flag cannot be set")},beginEditCell:function(r,i){var e=this.grid,t=e.getRow(r);t?d.cancelTimer(e,t):s.logError("Unable to find rowEntity in grid data, timer cannot be cancelled")},cancelEditCell:function(r,i){var e=this.grid,t=e.getRow(r);t?d.considerSetTimer(e,t):s.logError("Unable to find rowEntity in grid data, timer cannot be set")},navigate:function(r,i){var e=this.grid;r.row.rowEditSaveTimer&&d.cancelTimer(e,r.row),i&&i.row&&i.row!==r.row&&d.considerSetTimer(e,i.row)},considerSetTimer:function(r,i){if(d.cancelTimer(r,i),i.isDirty&&!i.isSaving&&-1!==r.options.rowEditWaitInterval){var e=r.options.rowEditWaitInterval?r.options.rowEditWaitInterval:2e3;i.rowEditSaveTimer=t(d.saveRow(r,i),e,1)}},cancelTimer:function(r,i){i.rowEditSaveTimer&&!i.isSaving&&(t.cancel(i.rowEditSaveTimer),delete i.rowEditSaveTimer)},setRowsDirty:function(e,r){var t;r.forEach(function(r,i){(t=e.getRow(r))?(e.rowEdit.dirtyRows||(e.rowEdit.dirtyRows=[]),t.isDirty||(t.isDirty=!0,e.rowEdit.dirtyRows.push(t)),delete t.isError,d.considerSetTimer(e,t)):s.logError("requested row not found in rowEdit.setRowsDirty, row was: "+r)})},setRowsClean:function(e,r){var t;r.forEach(function(r,i){(t=e.getRow(r))?(delete t.isDirty,d.removeRow(e.rowEdit.dirtyRows,t),d.cancelTimer(e,t),delete t.isError,d.removeRow(e.rowEdit.errorRows,t)):s.logError("requested row not found in rowEdit.setRowsClean, row was: "+r)})}};return d}]),r.directive("uiGridRowEdit",["gridUtil","uiGridRowEditService","uiGridEditConstants",function(r,o,i){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(r,i,e,t){o.initializeGrid(r,t.grid)},post:function(r,i,e,t){}}}}}]),r.directive("uiGridViewport",["$compile","uiGridConstants","gridUtil","$parse",function(r,i,e,t){return{priority:-200,scope:!1,compile:function(r,i){var e=angular.element(r.children().children()[0]),t=e.attr("ng-class"),o="";return o=t?t.slice(0,-1)+", 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}":"{'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError}",e.attr("ng-class",o),{pre:function(r,i,e,t){},post:function(r,i,e,t){}}}}}])}(); \ No newline at end of file diff --git a/src/ui-grid.saveState.js b/src/ui-grid.saveState.js new file mode 100644 index 0000000000..59b27d8382 --- /dev/null +++ b/src/ui-grid.saveState.js @@ -0,0 +1,830 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.saveState + * @description + * + * # ui.grid.saveState + * + * + * + * This module provides the ability to save the grid state, and restore + * it when the user returns to the page. + * + * No UI is provided, the caller should provide their own UI/buttons + * as appropriate. Usually the navigate events would be used to save + * the grid state and restore it. + * + *
    + *
    + * + *
    + */ + + var module = angular.module('ui.grid.saveState', ['ui.grid', 'ui.grid.selection', 'ui.grid.cellNav', 'ui.grid.grouping', 'ui.grid.pinning', 'ui.grid.treeView']); + + /** + * @ngdoc object + * @name ui.grid.saveState.constant:uiGridSaveStateConstants + * + * @description constants available in save state module + */ + + module.constant('uiGridSaveStateConstants', { + featureName: 'saveState' + }); + + /** + * @ngdoc service + * @name ui.grid.saveState.service:uiGridSaveStateService + * + * @description Services for saveState feature + */ + module.service('uiGridSaveStateService', + function () { + var service = { + + initializeGrid: function (grid) { + + // add feature namespace and any properties to grid for needed state + grid.saveState = {}; + this.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.saveState.api:PublicApi + * + * @description Public Api for saveState feature + */ + var publicApi = { + events: { + saveState: { + } + }, + methods: { + saveState: { + /** + * @ngdoc function + * @name save + * @methodOf ui.grid.saveState.api:PublicApi + * @description Packages the current state of the grid into + * an object, and provides it to the user for saving + * @returns {object} the state as a javascript object that can be saved + */ + save: function () { + return service.save(grid); + }, + /** + * @ngdoc function + * @name restore + * @methodOf ui.grid.saveState.api:PublicApi + * @description Restores the provided state into the grid + * @param {scope} $scope a scope that we can broadcast on + * @param {object} state the state that should be restored into the grid + * @returns {object} the promise created by refresh + */ + restore: function ( $scope, state) { + return service.restore(grid, $scope, state); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.saveState.api:GridOptions + * + * @description GridOptions for saveState feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + /** + * @ngdoc object + * @name saveWidths + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the current column widths. Note that unless + * you've provided the user with some way to resize their columns (say + * the resize columns feature), then this makes little sense. + *
    Defaults to true + */ + gridOptions.saveWidths = gridOptions.saveWidths !== false; + /** + * @ngdoc object + * @name saveOrder + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Restore the current column order. Note that unless + * you've provided the user with some way to reorder their columns (for + * example the move columns feature), this makes little sense. + *
    Defaults to true + */ + gridOptions.saveOrder = gridOptions.saveOrder !== false; + /** + * @ngdoc object + * @name saveScroll + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the current scroll position. Note that this + * is saved as the percentage of the grid scrolled - so if your + * user returns to a grid with a significantly different number of + * rows (perhaps some data has been deleted) then the scroll won't + * actually show the same rows as before. If you want to scroll to + * a specific row then you should instead use the saveFocus option, which + * is the default. + * + * Note that this element will only be saved if the cellNav feature is + * enabled + *
    Defaults to false + */ + gridOptions.saveScroll = gridOptions.saveScroll === true; + /** + * @ngdoc object + * @name saveFocus + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the current focused cell. On returning + * to this focused cell we'll also scroll. This option is + * preferred to the saveScroll option, so is set to true by + * default. If saveScroll is set to true then this option will + * be disabled. + * + * By default this option saves the current row number and column + * number, and returns to that row and column. However, if you define + * a saveRowIdentity function, then it will return you to the currently + * selected column within that row (in a business sense - so if some + * rows have been deleted, it will still find the same data, presuming it + * still exists in the list. If it isn't in the list then it will instead + * return to the same row number - i.e. scroll percentage) + * + * Note that this option will do nothing if the cellNav + * feature is not enabled. + * + *
    Defaults to true (unless saveScroll is true) + */ + gridOptions.saveFocus = gridOptions.saveScroll !== true && gridOptions.saveFocus !== false; + /** + * @ngdoc object + * @name saveRowIdentity + * @propertyOf ui.grid.saveState.api:GridOptions + * @description A function that can be called, passing in a rowEntity, + * and that will return a unique id for that row. This might simply + * return the `id` field from that row (if you have one), or it might + * concatenate some fields within the row to make a unique value. + * + * This value will be used to find the same row again and set the focus + * to it, if it exists when we return. + * + *
    Defaults to undefined + */ + /** + * @ngdoc object + * @name saveVisible + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save whether or not columns are visible. + * + *
    Defaults to true + */ + gridOptions.saveVisible = gridOptions.saveVisible !== false; + /** + * @ngdoc object + * @name saveSort + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the current sort state for each column + * + *
    Defaults to true + */ + gridOptions.saveSort = gridOptions.saveSort !== false; + /** + * @ngdoc object + * @name saveFilter + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the current filter state for each column + * + *
    Defaults to true + */ + gridOptions.saveFilter = gridOptions.saveFilter !== false; + /** + * @ngdoc object + * @name saveSelection + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the currently selected rows. If the `saveRowIdentity` callback + * is defined, then it will save the id of the row and select that. If not, then + * it will attempt to select the rows by row number, which will give the wrong results + * if the data set has changed in the mean-time. + * + * Note that this option only does anything + * if the selection feature is enabled. + * + *
    Defaults to true + */ + gridOptions.saveSelection = gridOptions.saveSelection !== false; + /** + * @ngdoc object + * @name saveGrouping + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the grouping configuration. If set to true and the + * grouping feature is not enabled then does nothing. + * + *
    Defaults to true + */ + gridOptions.saveGrouping = gridOptions.saveGrouping !== false; + /** + * @ngdoc object + * @name saveGroupingExpandedStates + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the grouping row expanded states. If set to true and the + * grouping feature is not enabled then does nothing. + * + * This can be quite a bit of data, in many cases you wouldn't want to save this + * information. + * + *
    Defaults to false + */ + gridOptions.saveGroupingExpandedStates = gridOptions.saveGroupingExpandedStates === true; + /** + * @ngdoc object + * @name savePinning + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save pinning state for columns. + * + *
    Defaults to true + */ + gridOptions.savePinning = gridOptions.savePinning !== false; + /** + * @ngdoc object + * @name saveTreeView + * @propertyOf ui.grid.saveState.api:GridOptions + * @description Save the treeView configuration. If set to true and the + * treeView feature is not enabled then does nothing. + * + *
    Defaults to true + */ + gridOptions.saveTreeView = gridOptions.saveTreeView !== false; + }, + + /** + * @ngdoc function + * @name save + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the current grid state into an object, and + * passes that object back to the caller + * @param {Grid} grid the grid whose state we'd like to save + * @returns {object} the state ready to be saved + */ + save: function (grid) { + var savedState = {}; + + savedState.columns = service.saveColumns( grid ); + savedState.scrollFocus = service.saveScrollFocus( grid ); + savedState.selection = service.saveSelection( grid ); + savedState.grouping = service.saveGrouping( grid ); + savedState.treeView = service.saveTreeView( grid ); + savedState.pagination = service.savePagination( grid ); + + return savedState; + }, + + + /** + * @ngdoc function + * @name restore + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Applies the provided state to the grid + * + * @param {Grid} grid the grid whose state we'd like to restore + * @param {scope} $scope a scope that we can broadcast on + * @param {object} state the state we'd like to restore + * @returns {object} the promise created by refresh + */ + restore: function( grid, $scope, state ) { + if ( state.columns ) { + service.restoreColumns( grid, state.columns ); + } + + if ( state.scrollFocus ) { + service.restoreScrollFocus( grid, $scope, state.scrollFocus ); + } + + if ( state.selection ) { + service.restoreSelection( grid, state.selection ); + } + + if ( state.grouping ) { + service.restoreGrouping( grid, state.grouping ); + } + + if ( state.treeView ) { + service.restoreTreeView( grid, state.treeView ); + } + + if ( state.pagination ) { + service.restorePagination( grid, state.pagination ); + } + + return grid.refresh(); + }, + + + /** + * @ngdoc function + * @name saveColumns + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the column setup, including sort, filters, ordering, + * pinning and column widths. + * + * Works through the current columns, storing them in order. Stores the + * column name, then the visible flag, width, sort and filters for each column. + * + * @param {Grid} grid the grid whose state we'd like to save + * @returns {array} the columns state ready to be saved + */ + saveColumns: function( grid ) { + var columns = []; + + grid.getOnlyDataColumns().forEach( function( column ) { + var savedColumn = {}; + savedColumn.name = column.name; + + if ( grid.options.saveVisible ) { + savedColumn.visible = column.visible; + } + + if ( grid.options.saveWidths ) { + savedColumn.width = column.width; + } + + // these two must be copied, not just pointed too - otherwise our saved state is pointing to the same object as current state + if ( grid.options.saveSort ) { + savedColumn.sort = angular.copy( column.sort ); + } + + if ( grid.options.saveFilter ) { + savedColumn.filters = []; + column.filters.forEach( function( filter ) { + var copiedFilter = {}; + angular.forEach( filter, function( value, key) { + if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder') { + copiedFilter[key] = value; + } + }); + savedColumn.filters.push(copiedFilter); + }); + } + + if ( !!grid.api.pinning && grid.options.savePinning ) { + savedColumn.pinned = column.renderContainer ? column.renderContainer : ''; + } + + columns.push( savedColumn ); + }); + + return columns; + }, + + + /** + * @ngdoc function + * @name saveScrollFocus + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the currently scroll or focus. + * + * If cellNav isn't present then does nothing - we can't return + * to the scroll position without cellNav anyway. + * + * If the cellNav module is present, and saveFocus is true, then + * it saves the currently focused cell. If rowIdentity is present + * then saves using rowIdentity, otherwise saves visibleRowNum. + * + * If the cellNav module is not present, and saveScroll is true, then + * it approximates the current scroll row and column, and saves that. + * + * @param {Grid} grid the grid whose state we'd like to save + * @returns {object} the selection state ready to be saved + */ + saveScrollFocus: function( grid ) { + if ( !grid.api.cellNav ) { + return {}; + } + + var scrollFocus = {}; + if ( grid.options.saveFocus ) { + scrollFocus.focus = true; + var rowCol = grid.api.cellNav.getFocusedCell(); + if ( rowCol !== null ) { + if ( rowCol.col !== null ) { + scrollFocus.colName = rowCol.col.colDef.name; + } + if ( rowCol.row !== null ) { + scrollFocus.rowVal = service.getRowVal( grid, rowCol.row ); + } + } + } + + if ( grid.options.saveScroll || grid.options.saveFocus && !scrollFocus.colName && !scrollFocus.rowVal ) { + scrollFocus.focus = false; + if ( grid.renderContainers.body.prevRowScrollIndex ) { + scrollFocus.rowVal = service.getRowVal( grid, grid.renderContainers.body.visibleRowCache[ grid.renderContainers.body.prevRowScrollIndex ]); + } + + if ( grid.renderContainers.body.prevColScrollIndex ) { + scrollFocus.colName = grid.renderContainers.body.visibleColumnCache[ grid.renderContainers.body.prevColScrollIndex ].name; + } + } + + return scrollFocus; + }, + + + /** + * @ngdoc function + * @name saveSelection + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the currently selected rows, if the selection feature is enabled + * @param {Grid} grid the grid whose state we'd like to save + * @returns {array} the selection state ready to be saved + */ + saveSelection: function( grid ) { + if ( !grid.api.selection || !grid.options.saveSelection ) { + return []; + } + + return grid.api.selection.getSelectedGridRows().map( function( gridRow ) { + return service.getRowVal( grid, gridRow ); + }); + }, + + + /** + * @ngdoc function + * @name saveGrouping + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the grouping state, if the grouping feature is enabled + * @param {Grid} grid the grid whose state we'd like to save + * @returns {object} the grouping state ready to be saved + */ + saveGrouping: function( grid ) { + if ( !grid.api.grouping || !grid.options.saveGrouping ) { + return {}; + } + + return grid.api.grouping.getGrouping( grid.options.saveGroupingExpandedStates ); + }, + + + /** + * @ngdoc function + * @name savePagination + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the pagination state, if the pagination feature is enabled + * @param {Grid} grid the grid whose state we'd like to save + * @returns {object} the pagination state ready to be saved + */ + savePagination: function( grid ) { + if ( !grid.api.pagination || !grid.options.paginationPageSize ) { + return {}; + } + + return { + paginationCurrentPage: grid.options.paginationCurrentPage, + paginationPageSize: grid.options.paginationPageSize + }; + }, + + + /** + * @ngdoc function + * @name saveTreeView + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Saves the tree view state, if the tree feature is enabled + * @param {Grid} grid the grid whose state we'd like to save + * @returns {object} the tree view state ready to be saved + */ + saveTreeView: function( grid ) { + if ( !grid.api.treeView || !grid.options.saveTreeView ) { + return {}; + } + + return grid.api.treeView.getTreeView(); + }, + + + /** + * @ngdoc function + * @name getRowVal + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Helper function that gets either the rowNum or + * the saveRowIdentity, given a gridRow + * @param {Grid} grid the grid the row is in + * @param {GridRow} gridRow the row we want the rowNum for + * @returns {object} an object containing { identity: true/false, row: rowNumber/rowIdentity } + * + */ + getRowVal: function( grid, gridRow ) { + if ( !gridRow ) { + return null; + } + + var rowVal = {}; + if ( grid.options.saveRowIdentity ) { + rowVal.identity = true; + rowVal.row = grid.options.saveRowIdentity( gridRow.entity ); + } + else { + rowVal.identity = false; + rowVal.row = grid.renderContainers.body.visibleRowCache.indexOf( gridRow ); + } + return rowVal; + }, + + + /** + * @ngdoc function + * @name restoreColumns + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Restores the columns, including order, visible, width, + * pinning, sort and filters. + * + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} columnsState the list of columns we had before, with their state + */ + restoreColumns: function( grid, columnsState ) { + var isSortChanged = false; + + columnsState.forEach( function( columnState, index ) { + var currentCol = grid.getColumn( columnState.name ); + + if ( currentCol && !grid.isRowHeaderColumn(currentCol) ) { + if ( grid.options.saveVisible && + ( currentCol.visible !== columnState.visible || + currentCol.colDef.visible !== columnState.visible ) ) { + currentCol.visible = columnState.visible; + currentCol.colDef.visible = columnState.visible; + grid.api.core.raise.columnVisibilityChanged(currentCol); + } + + if ( grid.options.saveWidths && currentCol.width !== columnState.width) { + currentCol.width = columnState.width; + currentCol.hasCustomWidth = true; + } + + if ( grid.options.saveSort && + !angular.equals(currentCol.sort, columnState.sort) && + !( currentCol.sort === undefined && angular.isEmpty(columnState.sort) ) ) { + currentCol.sort = angular.copy( columnState.sort ); + isSortChanged = true; + } + + if ( grid.options.saveFilter && + !angular.equals(currentCol.filters, columnState.filters ) ) { + columnState.filters.forEach( function( filter, index ) { + angular.extend( currentCol.filters[index], filter ); + if ( typeof(filter.term) === 'undefined' || filter.term === null ) { + delete currentCol.filters[index].term; + } + }); + grid.api.core.raise.filterChanged( currentCol ); + } + + if ( !!grid.api.pinning && grid.options.savePinning && currentCol.renderContainer !== columnState.pinned ) { + grid.api.pinning.pinColumn(currentCol, columnState.pinned); + } + + var currentIndex = grid.getOnlyDataColumns().indexOf( currentCol ); + if (currentIndex !== -1) { + if (grid.options.saveOrder && currentIndex !== index) { + var column = grid.columns.splice(currentIndex + grid.rowHeaderColumns.length, 1)[0]; + grid.columns.splice(index + grid.rowHeaderColumns.length, 0, column); + } + } + } + }); + + if ( isSortChanged ) { + grid.api.core.raise.sortChanged( grid, grid.getColumnSorting() ); + } + }, + + + /** + * @ngdoc function + * @name restoreScrollFocus + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Scrolls to the position that was saved. If focus is true, then + * sets focus to the specified row/col. If focus is false, then scrolls to the + * specified row/col. + * + * @param {Grid} grid the grid whose state we'd like to restore + * @param {scope} $scope a scope that we can broadcast on + * @param {object} scrollFocusState the scroll/focus state ready to be restored + */ + restoreScrollFocus: function( grid, $scope, scrollFocusState ) { + if ( !grid.api.cellNav ) { + return; + } + + var colDef, row; + if ( scrollFocusState.colName ) { + var colDefs = grid.options.columnDefs.filter( function( colDef ) { return colDef.name === scrollFocusState.colName; }); + if ( colDefs.length > 0 ) { + colDef = colDefs[0]; + } + } + + if ( scrollFocusState.rowVal && scrollFocusState.rowVal.row ) { + if ( scrollFocusState.rowVal.identity ) { + row = service.findRowByIdentity( grid, scrollFocusState.rowVal ); + } + else { + row = grid.renderContainers.body.visibleRowCache[ scrollFocusState.rowVal.row ]; + } + } + + var entity = row && row.entity ? row.entity : null ; + + if ( colDef || entity ) { + if (scrollFocusState.focus ) { + grid.api.cellNav.scrollToFocus( entity, colDef ); + } + else { + grid.scrollTo( entity, colDef ); + } + } + }, + + + /** + * @ngdoc function + * @name restoreSelection + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Selects the rows that are provided in the selection + * state. If you are using `saveRowIdentity` and more than one row matches the identity + * function then only the first is selected. + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} selectionState the selection state ready to be restored + */ + restoreSelection: function( grid, selectionState ) { + if ( !grid.api.selection ) { + return; + } + + grid.api.selection.clearSelectedRows(); + + selectionState.forEach(function( rowVal ) { + if ( rowVal.identity ) { + var foundRow = service.findRowByIdentity( grid, rowVal ); + + if ( foundRow ) { + grid.api.selection.selectRow( foundRow.entity ); + } + + } + else { + grid.api.selection.selectRowByVisibleIndex( rowVal.row ); + } + }); + }, + + + /** + * @ngdoc function + * @name restoreGrouping + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Restores the grouping configuration, if the grouping feature + * is enabled. + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} groupingState the grouping state ready to be restored + */ + restoreGrouping: function( grid, groupingState ) { + if ( !grid.api.grouping || typeof(groupingState) === 'undefined' || groupingState === null || angular.equals(groupingState, {}) ) { + return; + } + + grid.api.grouping.setGrouping( groupingState ); + }, + + /** + * @ngdoc function + * @name restoreTreeView + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Restores the tree view configuration, if the tree view feature + * is enabled. + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} treeViewState the tree view state ready to be restored + */ + restoreTreeView: function( grid, treeViewState ) { + if ( !grid.api.treeView || typeof(treeViewState) === 'undefined' || treeViewState === null || angular.equals(treeViewState, {}) ) { + return; + } + + grid.api.treeView.setTreeView( treeViewState ); + }, + + /** + * @ngdoc function + * @name restorePagination + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Restores the pagination information, if pagination is enabled. + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} pagination the pagination object to be restored + * @param {number} pagination.paginationCurrentPage the page number to restore + * @param {number} pagination.paginationPageSize the number of items displayed per page + */ + restorePagination: function( grid, pagination ) { + if ( !grid.api.pagination || !grid.options.paginationPageSize ) { + return; + } + + grid.options.paginationCurrentPage = pagination.paginationCurrentPage; + grid.options.paginationPageSize = pagination.paginationPageSize; + }, + + /** + * @ngdoc function + * @name findRowByIdentity + * @methodOf ui.grid.saveState.service:uiGridSaveStateService + * @description Finds a row given it's identity value, returns the first found row + * if any are found, otherwise returns null if no rows are found. + * @param {Grid} grid the grid whose state we'd like to restore + * @param {object} rowVal the row we'd like to find + * @returns {gridRow} the found row, or null if none found + */ + findRowByIdentity: function( grid, rowVal ) { + if ( !grid.options.saveRowIdentity ) { + return null; + } + + var filteredRows = grid.rows.filter( function( gridRow ) { + return ( grid.options.saveRowIdentity( gridRow.entity ) === rowVal.row ); + }); + + if ( filteredRows.length > 0 ) { + return filteredRows[0]; + } else { + return null; + } + } + }; + + return service; + } + ); + + /** + * @ngdoc directive + * @name ui.grid.saveState.directive:uiGridSaveState + * @element div + * @restrict A + * + * @description Adds saveState features to grid + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.saveState']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.gridOptions = { + columnDefs: [ + {name: 'name'}, + {name: 'title', enableCellEdit: true} + ], + data: $scope.data + }; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridSaveState', ['uiGridSaveStateConstants', 'uiGridSaveStateService', 'gridUtil', '$compile', + function (uiGridSaveStateConstants, uiGridSaveStateService, gridUtil, $compile) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridSaveStateService.initializeGrid(uiGridCtrl.grid); + } + }; + } + ]); +})(); diff --git a/src/ui-grid.saveState.min.js b/src/ui-grid.saveState.min.js new file mode 100644 index 0000000000..bf576b442a --- /dev/null +++ b/src/ui-grid.saveState.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.saveState",["ui.grid","ui.grid.selection","ui.grid.cellNav","ui.grid.grouping","ui.grid.pinning","ui.grid.treeView"]);e.constant("uiGridSaveStateConstants",{featureName:"saveState"}),e.service("uiGridSaveStateService",function(){var s={initializeGrid:function(n){n.saveState={},this.defaultGridOptions(n.options);var e={events:{saveState:{}},methods:{saveState:{save:function(){return s.save(n)},restore:function(e,i){return s.restore(n,e,i)}}}};n.api.registerEventsFromObject(e.events),n.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.saveWidths=!1!==e.saveWidths,e.saveOrder=!1!==e.saveOrder,e.saveScroll=!0===e.saveScroll,e.saveFocus=!0!==e.saveScroll&&!1!==e.saveFocus,e.saveVisible=!1!==e.saveVisible,e.saveSort=!1!==e.saveSort,e.saveFilter=!1!==e.saveFilter,e.saveSelection=!1!==e.saveSelection,e.saveGrouping=!1!==e.saveGrouping,e.saveGroupingExpandedStates=!0===e.saveGroupingExpandedStates,e.savePinning=!1!==e.savePinning,e.saveTreeView=!1!==e.saveTreeView},save:function(e){var i={};return i.columns=s.saveColumns(e),i.scrollFocus=s.saveScrollFocus(e),i.selection=s.saveSelection(e),i.grouping=s.saveGrouping(e),i.treeView=s.saveTreeView(e),i.pagination=s.savePagination(e),i},restore:function(e,i,n){return n.columns&&s.restoreColumns(e,n.columns),n.scrollFocus&&s.restoreScrollFocus(e,i,n.scrollFocus),n.selection&&s.restoreSelection(e,n.selection),n.grouping&&s.restoreGrouping(e,n.grouping),n.treeView&&s.restoreTreeView(e,n.treeView),n.pagination&&s.restorePagination(e,n.pagination),e.refresh()},saveColumns:function(n){var o=[];return n.getOnlyDataColumns().forEach(function(e){var i={};i.name=e.name,n.options.saveVisible&&(i.visible=e.visible),n.options.saveWidths&&(i.width=e.width),n.options.saveSort&&(i.sort=angular.copy(e.sort)),n.options.saveFilter&&(i.filters=[],e.filters.forEach(function(e){var n={};angular.forEach(e,function(e,i){"condition"!==i&&"$$hashKey"!==i&&"placeholder"!==i&&(n[i]=e)}),i.filters.push(n)})),n.api.pinning&&n.options.savePinning&&(i.pinned=e.renderContainer?e.renderContainer:""),o.push(i)}),o},saveScrollFocus:function(e){if(!e.api.cellNav)return{};var i={};if(e.options.saveFocus){i.focus=!0;var n=e.api.cellNav.getFocusedCell();null!==n&&(null!==n.col&&(i.colName=n.col.colDef.name),null!==n.row&&(i.rowVal=s.getRowVal(e,n.row)))}return(e.options.saveScroll||e.options.saveFocus&&!i.colName&&!i.rowVal)&&(i.focus=!1,e.renderContainers.body.prevRowScrollIndex&&(i.rowVal=s.getRowVal(e,e.renderContainers.body.visibleRowCache[e.renderContainers.body.prevRowScrollIndex])),e.renderContainers.body.prevColScrollIndex&&(i.colName=e.renderContainers.body.visibleColumnCache[e.renderContainers.body.prevColScrollIndex].name)),i},saveSelection:function(i){return i.api.selection&&i.options.saveSelection?i.api.selection.getSelectedGridRows().map(function(e){return s.getRowVal(i,e)}):[]},saveGrouping:function(e){return e.api.grouping&&e.options.saveGrouping?e.api.grouping.getGrouping(e.options.saveGroupingExpandedStates):{}},savePagination:function(e){return e.api.pagination&&e.options.paginationPageSize?{paginationCurrentPage:e.options.paginationCurrentPage,paginationPageSize:e.options.paginationPageSize}:{}},saveTreeView:function(e){return e.api.treeView&&e.options.saveTreeView?e.api.treeView.getTreeView():{}},getRowVal:function(e,i){if(!i)return null;var n={};return e.options.saveRowIdentity?(n.identity=!0,n.row=e.options.saveRowIdentity(i.entity)):(n.identity=!1,n.row=e.renderContainers.body.visibleRowCache.indexOf(i)),n},restoreColumns:function(r,e){var a=!1;e.forEach(function(e,i){var n=r.getColumn(e.name);if(n&&!r.isRowHeaderColumn(n)){!r.options.saveVisible||n.visible===e.visible&&n.colDef.visible===e.visible||(n.visible=e.visible,n.colDef.visible=e.visible,r.api.core.raise.columnVisibilityChanged(n)),r.options.saveWidths&&n.width!==e.width&&(n.width=e.width,n.hasCustomWidth=!0),!r.options.saveSort||angular.equals(n.sort,e.sort)||void 0===n.sort&&angular.isEmpty(e.sort)||(n.sort=angular.copy(e.sort),a=!0),r.options.saveFilter&&!angular.equals(n.filters,e.filters)&&(e.filters.forEach(function(e,i){angular.extend(n.filters[i],e),void 0!==e.term&&null!==e.term||delete n.filters[i].term}),r.api.core.raise.filterChanged(n)),r.api.pinning&&r.options.savePinning&&n.renderContainer!==e.pinned&&r.api.pinning.pinColumn(n,e.pinned);var o=r.getOnlyDataColumns().indexOf(n);if(-1!==o&&r.options.saveOrder&&o!==i){var t=r.columns.splice(o+r.rowHeaderColumns.length,1)[0];r.columns.splice(i+r.rowHeaderColumns.length,0,t)}}}),a&&r.api.core.raise.sortChanged(r,r.getColumnSorting())},restoreScrollFocus:function(e,i,n){if(e.api.cellNav){var o,t;if(n.colName){var r=e.options.columnDefs.filter(function(e){return e.name===n.colName});0Stable This feature is stable. There should no longer be breaking api changes without a deprecation warning. + * + *
    + */ + + var module = angular.module('ui.grid.selection', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.selection.constant:uiGridSelectionConstants + * + * @description constants available in selection module + */ + module.constant('uiGridSelectionConstants', { + featureName: 'selection', + selectionRowHeaderColName: 'selectionRowHeaderCol' + }); + + // add methods to GridRow + angular.module('ui.grid').config(['$provide', function ($provide) { + $provide.decorator('GridRow', ['$delegate', function ($delegate) { + + /** + * @ngdoc object + * @name ui.grid.selection.api:GridRow + * + * @description GridRow prototype functions added for selection + */ + + /** + * @ngdoc object + * @name enableSelection + * @propertyOf ui.grid.selection.api:GridRow + * @description Enable row selection for this row, only settable by internal code. + * + * The grouping feature, for example, might set group header rows to not be selectable. + *
    Defaults to true + */ + + /** + * @ngdoc object + * @name isSelected + * @propertyOf ui.grid.selection.api:GridRow + * @description Selected state of row. Should be readonly. Make any changes to selected state using setSelected(). + *
    Defaults to false + */ + + /** + * @ngdoc object + * @name isFocused + * @propertyOf ui.grid.selection.api:GridRow + * @description Focused state of row. Should be readonly. Make any changes to focused state using setFocused(). + *
    Defaults to false + */ + + /** + * @ngdoc function + * @name setSelected + * @methodOf ui.grid.selection.api:GridRow + * @description Sets the isSelected property and updates the selectedCount + * Changes to isSelected state should only be made via this function + * @param {Boolean} selected value to set + */ + $delegate.prototype.setSelected = function (selected) { + if (selected !== this.isSelected) { + this.isSelected = selected; + this.grid.selection.selectedCount += selected ? 1 : -1; + } + }; + + /** + * @ngdoc function + * @name setFocused + * @methodOf ui.grid.selection.api:GridRow + * @description Sets the isFocused property + * Changes to isFocused state should only be made via this function + * @param {Boolean} val value to set + */ + $delegate.prototype.setFocused = function(val) { + if (val !== this.isFocused) { + this.grid.selection.focusedRow && (this.grid.selection.focusedRow.isFocused = false); + this.grid.selection.focusedRow = val ? this : null; + this.isFocused = val; + } + }; + + return $delegate; + }]); + }]); + + /** + * @ngdoc service + * @name ui.grid.selection.service:uiGridSelectionService + * + * @description Services for selection features + */ + module.service('uiGridSelectionService', + function () { + var service = { + + initializeGrid: function (grid) { + + // add feature namespace and any properties to grid for needed + /** + * @ngdoc object + * @name ui.grid.selection.grid:selection + * + * @description Grid properties and functions added for selection + */ + grid.selection = { + lastSelectedRow: null, + /** + * @ngdoc object + * @name focusedRow + * @propertyOf ui.grid.selection.grid:selection + * @description Focused row. + */ + focusedRow: null, + selectAll: false + }; + + + /** + * @ngdoc object + * @name selectedCount + * @propertyOf ui.grid.selection.grid:selection + * @description Current count of selected rows + * @example + * var count = grid.selection.selectedCount + */ + grid.selection.selectedCount = 0; + + service.defaultGridOptions(grid.options); + + /** + * @ngdoc object + * @name ui.grid.selection.api:PublicApi + * + * @description Public Api for selection feature + */ + var publicApi = { + events: { + selection: { + /** + * @ngdoc event + * @name rowFocusChanged + * @eventOf ui.grid.selection.api:PublicApi + * @description is raised after the row.isFocused state is changed + * @param {object} scope the scope associated with the grid + * @param {GridRow} row the row that was focused/unfocused + * @param {Event} evt object if raised from an event + */ + rowFocusChanged: function (scope, row, evt) {}, + /** + * @ngdoc event + * @name rowSelectionChanged + * @eventOf ui.grid.selection.api:PublicApi + * @description is raised after the row.isSelected state is changed + * @param {object} scope the scope associated with the grid + * @param {GridRow} row the row that was selected/deselected + * @param {Event} evt object if raised from an event + */ + rowSelectionChanged: function (scope, row, evt) { + }, + /** + * @ngdoc event + * @name rowSelectionChangedBatch + * @eventOf ui.grid.selection.api:PublicApi + * @description is raised after the row.isSelected state is changed + * in bulk, if the `enableSelectionBatchEvent` option is set to true + * (which it is by default). This allows more efficient processing + * of bulk events. + * @param {object} scope the scope associated with the grid + * @param {array} rows the rows that were selected/deselected + * @param {Event} evt object if raised from an event + */ + rowSelectionChangedBatch: function (scope, rows, evt) { + } + } + }, + methods: { + selection: { + /** + * @ngdoc function + * @name toggleRowSelection + * @methodOf ui.grid.selection.api:PublicApi + * @description Toggles data row as selected or unselected + * @param {object} rowEntity gridOptions.data[] array instance + * @param {Event} evt object if raised from an event + */ + toggleRowSelection: function (rowEntity, evt) { + var row = grid.getRow(rowEntity); + if (row !== null) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, + /** + * @ngdoc function + * @name selectRow + * @methodOf ui.grid.selection.api:PublicApi + * @description Select the data row + * @param {object} rowEntity gridOptions.data[] array instance + * @param {Event} evt object if raised from an event + */ + selectRow: function (rowEntity, evt) { + var row = grid.getRow(rowEntity); + if (row !== null && !row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, + /** + * @ngdoc function + * @name selectRowByVisibleIndex + * @methodOf ui.grid.selection.api:PublicApi + * @description Select the specified row by visible index (i.e. if you + * specify row 0 you'll get the first visible row selected). In this context + * visible means of those rows that are theoretically visible (i.e. not filtered), + * rather than rows currently rendered on the screen. + * @param {number} rowNum index within the rowsVisible array + * @param {Event} evt object if raised from an event + */ + selectRowByVisibleIndex: function (rowNum, evt) { + var row = grid.renderContainers.body.visibleRowCache[rowNum]; + if (row !== null && typeof (row) !== 'undefined' && !row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, + /** + * @ngdoc function + * @name unSelectRow + * @methodOf ui.grid.selection.api:PublicApi + * @description UnSelect the data row + * @param {object} rowEntity gridOptions.data[] array instance + * @param {Event} evt object if raised from an event + */ + unSelectRow: function (rowEntity, evt) { + var row = grid.getRow(rowEntity); + if (row !== null && row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, + /** + * @ngdoc function + * @name unSelectRowByVisibleIndex + * @methodOf ui.grid.selection.api:PublicApi + * @description Unselect the specified row by visible index (i.e. if you + * specify row 0 you'll get the first visible row unselected). In this context + * visible means of those rows that are theoretically visible (i.e. not filtered), + * rather than rows currently rendered on the screen. + * @param {number} rowNum index within the rowsVisible array + * @param {Event} evt object if raised from an event + */ + unSelectRowByVisibleIndex: function (rowNum, evt) { + var row = grid.renderContainers.body.visibleRowCache[rowNum]; + if (row !== null && typeof (row) !== 'undefined' && row.isSelected) { + service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); + } + }, + /** + * @ngdoc function + * @name selectAllRows + * @methodOf ui.grid.selection.api:PublicApi + * @description Selects all rows. Does nothing if multiSelect = false + * @param {Event} evt object if raised from an event + */ + selectAllRows: function (evt) { + if (grid.options.multiSelect !== false) { + var changedRows = []; + grid.rows.forEach(function (row) { + if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { + row.setSelected(true); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + }); + grid.selection.selectAll = true; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); + } + }, + /** + * @ngdoc function + * @name selectAllVisibleRows + * @methodOf ui.grid.selection.api:PublicApi + * @description Selects all visible rows. Does nothing if multiSelect = false + * @param {Event} evt object if raised from an event + */ + selectAllVisibleRows: function (evt) { + if (grid.options.multiSelect !== false) { + var changedRows = []; + grid.rows.forEach(function(row) { + if (row.visible) { + if (!row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { + row.setSelected(true); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + } else if (row.isSelected) { + row.setSelected(false); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + }); + grid.selection.selectAll = true; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); + } + }, + /** + * @ngdoc function + * @name clearSelectedRows + * @methodOf ui.grid.selection.api:PublicApi + * @description Unselects all rows + * @param {Event} evt object if raised from an event + */ + clearSelectedRows: function (evt) { + service.clearSelectedRows(grid, evt); + }, + /** + * @ngdoc function + * @name getSelectedRows + * @methodOf ui.grid.selection.api:PublicApi + * @description returns all selectedRow's entity references + */ + getSelectedRows: function () { + return service.getSelectedRows(grid).map(function (gridRow) { + return gridRow.entity; + }).filter(function (entity) { + return entity.hasOwnProperty('$$hashKey') || !angular.isObject(entity); + }); + }, + /** + * @ngdoc function + * @name getSelectedGridRows + * @methodOf ui.grid.selection.api:PublicApi + * @description returns all selectedRow's as gridRows + */ + getSelectedGridRows: function () { + return service.getSelectedRows(grid); + }, + /** + * @ngdoc function + * @name getSelectedCount + * @methodOf ui.grid.selection.api:PublicApi + * @description returns the number of rows selected + */ + getSelectedCount: function () { + return grid.selection.selectedCount; + }, + /** + * @ngdoc function + * @name setMultiSelect + * @methodOf ui.grid.selection.api:PublicApi + * @description Sets the current gridOption.multiSelect to true or false + * @param {bool} multiSelect true to allow multiple rows + */ + setMultiSelect: function (multiSelect) { + grid.options.multiSelect = multiSelect; + }, + /** + * @ngdoc function + * @name setModifierKeysToMultiSelect + * @methodOf ui.grid.selection.api:PublicApi + * @description Sets the current gridOption.modifierKeysToMultiSelect to true or false + * @param {bool} modifierKeysToMultiSelect true to only allow multiple rows when using ctrlKey or shiftKey is used + */ + setModifierKeysToMultiSelect: function (modifierKeysToMultiSelect) { + grid.options.modifierKeysToMultiSelect = modifierKeysToMultiSelect; + }, + /** + * @ngdoc function + * @name getSelectAllState + * @methodOf ui.grid.selection.api:PublicApi + * @description Returns whether or not the selectAll checkbox is currently ticked. The + * grid doesn't automatically select rows when you add extra data - so when you add data + * you need to explicitly check whether the selectAll is set, and then call setVisible rows + * if it is + */ + getSelectAllState: function () { + return grid.selection.selectAll; + } + + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.selection.api:GridOptions + * + * @description GridOptions for selection feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name enableRowSelection + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable row selection for entire grid. + *
    Defaults to true + */ + gridOptions.enableRowSelection = gridOptions.enableRowSelection !== false; + /** + * @ngdoc object + * @name multiSelect + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable multiple row selection for entire grid + *
    Defaults to true + */ + gridOptions.multiSelect = gridOptions.multiSelect !== false; + /** + * @ngdoc object + * @name noUnselect + * @propertyOf ui.grid.selection.api:GridOptions + * @description Prevent a row from being unselected. Works in conjunction + * with `multiselect = false` and `gridApi.selection.selectRow()` to allow + * you to create a single selection only grid - a row is always selected, you + * can only select different rows, you can't unselect the row. + *
    Defaults to false + */ + gridOptions.noUnselect = gridOptions.noUnselect === true; + /** + * @ngdoc object + * @name modifierKeysToMultiSelect + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable multiple row selection only when using the ctrlKey or shiftKey. Requires multiSelect to be true. + *
    Defaults to false + */ + gridOptions.modifierKeysToMultiSelect = gridOptions.modifierKeysToMultiSelect === true; + /** + * @ngdoc object + * @name enableRowHeaderSelection + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable a row header to be used for selection + *
    Defaults to true + */ + gridOptions.enableRowHeaderSelection = gridOptions.enableRowHeaderSelection !== false; + /** + * @ngdoc object + * @name enableFullRowSelection + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable selection by clicking anywhere on the row. Defaults to + * false if `enableRowHeaderSelection` is true, otherwise defaults to true. + */ + if (typeof (gridOptions.enableFullRowSelection) === 'undefined') { + gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection; + } + /** + * @ngdoc object + * @name enableFocusRowOnRowHeaderClick + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable focuse row by clicking on the row header. Defaults to + * true if `enableRowHeaderSelection` is true, otherwise defaults to false. + */ + gridOptions.enableFocusRowOnRowHeaderClick = (gridOptions.enableFocusRowOnRowHeaderClick !== false) + || !gridOptions.enableRowHeaderSelection; + /** + * @ngdoc object + * @name enableSelectRowOnFocus + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable focuse row by clicking on the row anywhere. Defaults true. + */ + gridOptions.enableSelectRowOnFocus = (gridOptions.enableSelectRowOnFocus !== false); + /** + * @ngdoc object + * @name enableSelectAll + * @propertyOf ui.grid.selection.api:GridOptions + * @description Enable the select all checkbox at the top of the selectionRowHeader + *
    Defaults to true + */ + gridOptions.enableSelectAll = gridOptions.enableSelectAll !== false; + /** + * @ngdoc object + * @name enableSelectionBatchEvent + * @propertyOf ui.grid.selection.api:GridOptions + * @description If selected rows are changed in bulk, either via the API or + * via the selectAll checkbox, then a separate event is fired. Setting this + * option to false will cause the rowSelectionChanged event to be called multiple times + * instead + *
    Defaults to true + */ + gridOptions.enableSelectionBatchEvent = gridOptions.enableSelectionBatchEvent !== false; + /** + * @ngdoc object + * @name selectionRowHeaderWidth + * @propertyOf ui.grid.selection.api:GridOptions + * @description can be used to set a custom width for the row header selection column + *
    Defaults to 30px + */ + gridOptions.selectionRowHeaderWidth = angular.isDefined(gridOptions.selectionRowHeaderWidth) ? gridOptions.selectionRowHeaderWidth : 30; + /** + * @ngdoc object + * @name enableFooterTotalSelected + * @propertyOf ui.grid.selection.api:GridOptions + * @description Shows the total number of selected items in footer if true. + *
    Defaults to true. + *
    GridOptions.showGridFooter must also be set to true. + */ + gridOptions.enableFooterTotalSelected = gridOptions.enableFooterTotalSelected !== false; + + /** + * @ngdoc object + * @name isRowSelectable + * @propertyOf ui.grid.selection.api:GridOptions + * @description Makes it possible to specify a method that evaluates for each row and sets its "enableSelection" property. + */ + gridOptions.isRowSelectable = angular.isDefined(gridOptions.isRowSelectable) ? gridOptions.isRowSelectable : angular.noop; + }, + + /** + * @ngdoc function + * @name toggleRowSelection + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description Toggles row as selected or unselected + * @param {Grid} grid grid object + * @param {GridRow} row row to select or deselect + * @param {Event} evt object if resulting from event + * @param {bool} multiSelect if false, only one row at time can be selected + * @param {bool} noUnselect if true then rows cannot be unselected + */ + toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) { + if ( row.enableSelection === false ) { + return; + } + + var selected = row.isSelected, + selectedRows; + + if (!multiSelect) { + if (!selected) { + service.clearSelectedRows(grid, evt); + } + else { + selectedRows = service.getSelectedRows(grid); + if (selectedRows.length > 1) { + selected = false; // Enable reselect of the row + service.clearSelectedRows(grid, evt); + } + } + } + + // only select row in this case + if (!(selected && noUnselect)) { + row.setSelected(!selected); + if (row.isSelected === true) { + grid.selection.lastSelectedRow = row; + } + + selectedRows = service.getSelectedRows(grid); + grid.selection.selectAll = grid.rows.length === selectedRows.length; + + grid.api.selection.raise.rowSelectionChanged(row, evt); + } + }, + /** + * @ngdoc function + * @name shiftSelect + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description selects a group of rows from the last selected row using the shift key + * @param {Grid} grid grid object + * @param {GridRow} row clicked row + * @param {Event} evt object if raised from an event + * @param {bool} multiSelect if false, does nothing this is for multiSelect only + */ + shiftSelect: function (grid, row, evt, multiSelect) { + if (!multiSelect) { + return; + } + var selectedRows = service.getSelectedRows(grid); + var fromRow = selectedRows.length > 0 ? grid.renderContainers.body.visibleRowCache.indexOf(grid.selection.lastSelectedRow) : 0; + var toRow = grid.renderContainers.body.visibleRowCache.indexOf(row); + // reverse select direction + if (fromRow > toRow) { + var tmp = fromRow; + fromRow = toRow; + toRow = tmp; + } + + var changedRows = []; + for (var i = fromRow; i <= toRow; i++) { + var rowToSelect = grid.renderContainers.body.visibleRowCache[i]; + if (rowToSelect) { + if (!rowToSelect.isSelected && rowToSelect.enableSelection !== false) { + rowToSelect.setSelected(true); + grid.selection.lastSelectedRow = rowToSelect; + service.decideRaiseSelectionEvent(grid, rowToSelect, changedRows, evt); + } + } + } + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); + }, + /** + * @ngdoc function + * @name getSelectedRows + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description Returns all the selected rows + * @param {Grid} grid grid object + */ + getSelectedRows: function (grid) { + return grid.rows.filter(function (row) { + return row.isSelected; + }); + }, + + /** + * @ngdoc function + * @name clearSelectedRows + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description Clears all selected rows + * @param {Grid} grid grid object + * @param {Event} evt object if raised from an event + */ + clearSelectedRows: function (grid, evt) { + var changedRows = []; + service.getSelectedRows(grid).forEach(function (row) { + if (row.isSelected && row.enableSelection !== false && grid.options.isRowSelectable(row) !== false) { + row.setSelected(false); + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); + } + }); + grid.selection.selectAll = false; + grid.selection.selectedCount = 0; + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); + }, + + /** + * @ngdoc function + * @name decideRaiseSelectionEvent + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description Decides whether to raise a single event or a batch event + * @param {Grid} grid grid object + * @param {GridRow} row row that has changed + * @param {array} changedRows an array to which we can append the changed + * @param {Event} evt object if raised from an event + * row if we're doing batch events + */ + decideRaiseSelectionEvent: function (grid, row, changedRows, evt) { + if (!grid.options.enableSelectionBatchEvent) { + grid.api.selection.raise.rowSelectionChanged(row, evt); + } + else { + changedRows.push(row); + } + }, + + /** + * @ngdoc function + * @name raiseSelectionEvent + * @methodOf ui.grid.selection.service:uiGridSelectionService + * @description Decides whether we need to raise a batch event, and + * raises it if we do. + * @param {Grid} grid grid object + * @param {array} changedRows an array of changed rows, only populated + * @param {Event} evt object if raised from an event + * if we're doing batch events + */ + decideRaiseSelectionBatchEvent: function (grid, changedRows, evt) { + if (changedRows.length > 0) { + grid.api.selection.raise.rowSelectionChangedBatch(changedRows, evt); + } + } + }; + + return service; + }); + + /** + * @ngdoc directive + * @name ui.grid.selection.directive:uiGridSelection + * @element div + * @restrict A + * + * @description Adds selection features to grid + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.selection']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name', enableCellEdit: true}, + {name: 'title', enableCellEdit: true} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridSelection', ['i18nService', 'uiGridSelectionConstants', 'uiGridSelectionService', 'uiGridConstants', + function (i18nService, uiGridSelectionConstants, uiGridSelectionService, uiGridConstants) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridSelectionService.initializeGrid(uiGridCtrl.grid); + if (uiGridCtrl.grid.options.enableRowHeaderSelection) { + var selectionRowHeaderDef = { + name: uiGridSelectionConstants.selectionRowHeaderColName, + displayName: i18nService.getSafeText('selection.displayName'), + width: uiGridCtrl.grid.options.selectionRowHeaderWidth, + minWidth: 10, + cellTemplate: 'ui-grid/selectionRowHeader', + headerCellTemplate: 'ui-grid/selectionHeaderCell', + enableColumnResizing: false, + enableColumnMenu: false, + exporterSuppressExport: true, + allowCellFocus: true + }; + + uiGridCtrl.grid.addRowHeaderColumn(selectionRowHeaderDef, 0); + } + + var processorSet = false; + + var processSelectableRows = function (rows) { + rows.forEach(function (row) { + row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row); + }); + return rows; + }; + + var updateOptions = function () { + if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) { + uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500); + processorSet = true; + } + }; + + updateOptions(); + + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(updateOptions, [uiGridConstants.dataChange.OPTIONS]); + + $scope.$on('$destroy', dataChangeDereg); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + + } + }; + } + }; + }]); + + module.directive('uiGridSelectionRowHeaderButtons', ['$templateCache', 'uiGridSelectionService', 'gridUtil', + function ($templateCache, uiGridSelectionService, gridUtil) { + return { + replace: true, + restrict: 'E', + template: $templateCache.get('ui-grid/selectionRowHeaderButtons'), + scope: true, + require: '^uiGrid', + link: function ($scope, $elm, $attrs, uiGridCtrl) { + var self = uiGridCtrl.grid; + $scope.selectButtonClick = selectButtonClick; + $scope.selectButtonKeyDown = selectButtonKeyDown; + + // On IE, prevent mousedowns on the select button from starting a selection. + // If this is not done and you shift+click on another row, the browser will select a big chunk of text + if (gridUtil.detectBrowser() === 'ie') { + $elm.on('mousedown', selectButtonMouseDown); + } + + function selectButtonKeyDown(row, evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + evt.preventDefault(); + selectButtonClick(row, evt); + } + } + + function selectButtonClick(row, evt) { + evt.stopPropagation(); + + if (evt.shiftKey) { + uiGridSelectionService.shiftSelect(self, row, evt, self.options.multiSelect); + } + else if (evt.ctrlKey || evt.metaKey) { + uiGridSelectionService.toggleRowSelection(self, row, evt, + self.options.multiSelect, self.options.noUnselect); + } + else if (row.groupHeader) { + uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect); + for (var i = 0; i < row.treeNode.children.length; i++) { + uiGridSelectionService.toggleRowSelection(self, row.treeNode.children[i].row, evt, self.options.multiSelect, self.options.noUnselect); + } + } + else { + uiGridSelectionService.toggleRowSelection(self, row, evt, + (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect); + } + self.options.enableFocusRowOnRowHeaderClick && row.setFocused(!row.isFocused) && self.api.selection.raise.rowFocusChanged(row, evt); + } + + function selectButtonMouseDown(evt) { + if (evt.ctrlKey || evt.shiftKey) { + evt.target.onselectstart = function () { return false; }; + window.setTimeout(function () { evt.target.onselectstart = null; }, 0); + } + } + + $scope.$on('$destroy', function unbindEvents() { + $elm.off(); + }); + } + }; + }]); + + module.directive('uiGridSelectionSelectAllButtons', ['$templateCache', 'uiGridSelectionService', + function ($templateCache, uiGridSelectionService) { + return { + replace: true, + restrict: 'E', + template: $templateCache.get('ui-grid/selectionSelectAllButtons'), + scope: false, + link: function ($scope) { + var self = $scope.col.grid; + + $scope.headerButtonKeyDown = function (evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + evt.preventDefault(); + $scope.headerButtonClick(evt); + } + }; + + $scope.headerButtonClick = function (evt) { + if (self.selection.selectAll) { + uiGridSelectionService.clearSelectedRows(self, evt); + if (self.options.noUnselect) { + self.api.selection.selectRowByVisibleIndex(0, evt); + } + self.selection.selectAll = false; + } + else if (self.options.multiSelect) { + self.api.selection.selectAllVisibleRows(evt); + self.selection.selectAll = true; + } + }; + } + }; + }]); + + /** + * @ngdoc directive + * @name ui.grid.selection.directive:uiGridViewport + * @element div + * + * @description Stacks on top of ui.grid.uiGridViewport to alter the attributes used + * for the grid row + */ + module.directive('uiGridViewport', + function () { + return { + priority: -200, // run after default directive + scope: false, + compile: function ($elm) { + var rowRepeatDiv = angular.element($elm[0].querySelector('.ui-grid-canvas:not(.ui-grid-empty-base-layer-container)').children[0]), + newNgClass = "'ui-grid-row-selected': row.isSelected, 'ui-grid-row-focused': row.isFocused}", + existingNgClass = rowRepeatDiv.attr('ng-class'); + + if (existingNgClass) { + newNgClass = existingNgClass.slice(0, -1) + ',' + newNgClass; + } else { + newNgClass = '{' + newNgClass; + } + rowRepeatDiv.attr('ng-class', newNgClass); + + return { + pre: function ($scope, $elm, $attrs, controllers) {}, + post: function ($scope, $elm, $attrs, controllers) {} + }; + } + }; + }); + + /** + * @ngdoc directive + * @name ui.grid.selection.directive:uiGridCell + * @element div + * @restrict A + * + * @description Stacks on top of ui.grid.uiGridCell to provide selection feature + */ + module.directive('uiGridCell', + ['uiGridConstants', 'uiGridSelectionService', + function (uiGridConstants, uiGridSelectionService) { + return { + priority: -200, // run after default uiGridCell directive + restrict: 'A', + require: '?^uiGrid', + scope: false, + link: function ($scope, $elm, $attrs, uiGridCtrl) { + var touchStartTime = 0, + touchStartPos = {}, + touchTimeout = 300, + touchPosDiff = 100; + + // Bind to keydown events in the render container + if (uiGridCtrl.grid.api.cellNav) { + uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) { + if (rowCol === null || + rowCol.row !== $scope.row || + rowCol.col !== $scope.col) { + return; + } + + if (evt.keyCode === uiGridConstants.keymap.SPACE && $scope.col.colDef.name === 'selectionRowHeaderCol') { + evt.preventDefault(); + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), + $scope.grid.options.noUnselect); + $scope.$apply(); + } + }); + } + + var selectCells = function (evt) { + // if you click on expandable icon doesn't trigger selection + if (evt.target.className === "ui-grid-icon-minus-squared" || evt.target.className === "ui-grid-icon-plus-squared") { + return; + } + + // if we get a click, then stop listening for touchend + $elm.off('touchend', touchEnd); + + if (evt.shiftKey) { + uiGridSelectionService.shiftSelect($scope.grid, $scope.row, evt, $scope.grid.options.multiSelect); + } + else if (evt.ctrlKey || evt.metaKey) { + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + $scope.grid.options.multiSelect, $scope.grid.options.noUnselect); + } + else if ($scope.grid.options.enableSelectRowOnFocus) { + uiGridSelectionService.toggleRowSelection($scope.grid, $scope.row, evt, + ($scope.grid.options.multiSelect && !$scope.grid.options.modifierKeysToMultiSelect), + $scope.grid.options.noUnselect); + } + $scope.row.setFocused(!$scope.row.isFocused); + $scope.grid.api.selection.raise.rowFocusChanged($scope.row, evt); + $scope.$apply(); + + // don't re-enable the touchend handler for a little while - some devices generate both, and it will + // take a little while to move your hand from the mouse to the screen if you have both modes of input + window.setTimeout(function () { + $elm.on('touchend', touchEnd); + }, touchTimeout); + }; + + var touchStart = function (evt) { + touchStartTime = (new Date()).getTime(); + touchStartPos = evt.changedTouches[0]; + + // if we get a touch event, then stop listening for click + $elm.off('click', selectCells); + }; + + var touchEnd = function (evt) { + var touchEndTime = (new Date()).getTime(); + var touchEndPos = evt.changedTouches[0]; + var touchTime = touchEndTime - touchStartTime; + var touchXDiff = Math.abs(touchStartPos.clientX - touchEndPos.clientX) + var touchYDiff = Math.abs(touchStartPos.clientY - touchEndPos.clientY) + + + if (touchXDiff < touchPosDiff && touchYDiff < touchPosDiff) { + if (touchTime < touchTimeout) { + // short touch + selectCells(evt); + } + } + + // don't re-enable the click handler for a little while - some devices generate both, and it will + // take a little while to move your hand from the screen to the mouse if you have both modes of input + window.setTimeout(function () { + $elm.on('click', selectCells); + }, touchTimeout); + }; + + function registerRowSelectionEvents() { + if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && $scope.col.colDef.name !== 'selectionRowHeaderCol') { + $elm.addClass('ui-grid-disable-selection'); + $elm.on('touchstart', touchStart); + $elm.on('touchend', touchEnd); + $elm.on('click', selectCells); + + $scope.registered = true; + } + } + + function unregisterRowSelectionEvents() { + if ($scope.registered) { + $elm.removeClass('ui-grid-disable-selection'); + $elm.off('touchstart', touchStart); + $elm.off('touchend', touchEnd); + $elm.off('click', selectCells); + + $scope.registered = false; + } + } + + registerRowSelectionEvents(); + + // register a dataChange callback so that we can change the selection configuration dynamically + // if the user changes the options + var dataChangeUnreg = $scope.grid.registerDataChangeCallback(function () { + if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && + !$scope.registered) { + registerRowSelectionEvents(); + } + else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) && + $scope.registered) { + unregisterRowSelectionEvents(); + } + }, [uiGridConstants.dataChange.OPTIONS]); + + $elm.on('$destroy', dataChangeUnreg); + } + }; + }]); + + module.directive('uiGridGridFooter', ['$compile', 'gridUtil', function ($compile, gridUtil) { + return { + restrict: 'EA', + replace: true, + priority: -1000, + require: '^uiGrid', + scope: true, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + if (!uiGridCtrl.grid.options.showGridFooter) { + return; + } + + gridUtil.getTemplate('ui-grid/gridFooterSelectedItems') + .then(function (contents) { + var template = angular.element(contents); + + var newElm = $compile(template)($scope); + + angular.element($elm[0].getElementsByClassName('ui-grid-grid-footer')[0]).append(newElm); + }); + }, + post: function ($scope, $elm, $attrs, controllers) { + + } + }; + } + }; + }]); +})(); + +angular.module('ui.grid.selection').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/gridFooterSelectedItems', + "({{\"search.selectedItems\" | t}} {{grid.selection.selectedCount}})" + ); + + + $templateCache.put('ui-grid/selectionHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/selectionRowHeaderButtons', + "
     
    " + ); + + + $templateCache.put('ui-grid/selectionSelectAllButtons', + "
    " + ); + +}]); diff --git a/src/ui-grid.selection.min.js b/src/ui-grid.selection.min.js new file mode 100644 index 0000000000..e1c971c2d5 --- /dev/null +++ b/src/ui-grid.selection.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.selection",["ui.grid"]);e.constant("uiGridSelectionConstants",{featureName:"selection",selectionRowHeaderColName:"selectionRowHeaderCol"}),angular.module("ui.grid").config(["$provide",function(e){e.decorator("GridRow",["$delegate",function(e){return e.prototype.setSelected=function(e){e!==this.isSelected&&(this.isSelected=e,this.grid.selection.selectedCount+=e?1:-1)},e.prototype.setFocused=function(e){e!==this.isFocused&&(this.grid.selection.focusedRow&&(this.grid.selection.focusedRow.isFocused=!1),this.grid.selection.focusedRow=e?this:null,this.isFocused=e)},e}])}]),e.service("uiGridSelectionService",function(){var a={initializeGrid:function(o){o.selection={lastSelectedRow:null,focusedRow:null,selectAll:!1},o.selection.selectedCount=0,a.defaultGridOptions(o.options);var e={events:{selection:{rowFocusChanged:function(e,t,i){},rowSelectionChanged:function(e,t,i){},rowSelectionChangedBatch:function(e,t,i){}}},methods:{selection:{toggleRowSelection:function(e,t){var i=o.getRow(e);null!==i&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectRow:function(e,t){var i=o.getRow(e);null===i||i.isSelected||a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectRowByVisibleIndex:function(e,t){var i=o.renderContainers.body.visibleRowCache[e];null==i||i.isSelected||a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},unSelectRow:function(e,t){var i=o.getRow(e);null!==i&&i.isSelected&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},unSelectRowByVisibleIndex:function(e,t){var i=o.renderContainers.body.visibleRowCache[e];null!=i&&i.isSelected&&a.toggleRowSelection(o,i,t,o.options.multiSelect,o.options.noUnselect)},selectAllRows:function(t){if(!1!==o.options.multiSelect){var i=[];o.rows.forEach(function(e){e.isSelected||!1===e.enableSelection||!1===o.options.isRowSelectable(e)||(e.setSelected(!0),a.decideRaiseSelectionEvent(o,e,i,t))}),o.selection.selectAll=!0,a.decideRaiseSelectionBatchEvent(o,i,t)}},selectAllVisibleRows:function(t){if(!1!==o.options.multiSelect){var i=[];o.rows.forEach(function(e){e.visible?e.isSelected||!1===e.enableSelection||!1===o.options.isRowSelectable(e)||(e.setSelected(!0),a.decideRaiseSelectionEvent(o,e,i,t)):e.isSelected&&(e.setSelected(!1),a.decideRaiseSelectionEvent(o,e,i,t))}),o.selection.selectAll=!0,a.decideRaiseSelectionBatchEvent(o,i,t)}},clearSelectedRows:function(e){a.clearSelectedRows(o,e)},getSelectedRows:function(){return a.getSelectedRows(o).map(function(e){return e.entity}).filter(function(e){return e.hasOwnProperty("$$hashKey")||!angular.isObject(e)})},getSelectedGridRows:function(){return a.getSelectedRows(o)},getSelectedCount:function(){return o.selection.selectedCount},setMultiSelect:function(e){o.options.multiSelect=e},setModifierKeysToMultiSelect:function(e){o.options.modifierKeysToMultiSelect=e},getSelectAllState:function(){return o.selection.selectAll}}}};o.api.registerEventsFromObject(e.events),o.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.enableRowSelection=!1!==e.enableRowSelection,e.multiSelect=!1!==e.multiSelect,e.noUnselect=!0===e.noUnselect,e.modifierKeysToMultiSelect=!0===e.modifierKeysToMultiSelect,e.enableRowHeaderSelection=!1!==e.enableRowHeaderSelection,void 0===e.enableFullRowSelection&&(e.enableFullRowSelection=!e.enableRowHeaderSelection),e.enableFocusRowOnRowHeaderClick=!1!==e.enableFocusRowOnRowHeaderClick||!e.enableRowHeaderSelection,e.enableSelectRowOnFocus=!1!==e.enableSelectRowOnFocus,e.enableSelectAll=!1!==e.enableSelectAll,e.enableSelectionBatchEvent=!1!==e.enableSelectionBatchEvent,e.selectionRowHeaderWidth=angular.isDefined(e.selectionRowHeaderWidth)?e.selectionRowHeaderWidth:30,e.enableFooterTotalSelected=!1!==e.enableFooterTotalSelected,e.isRowSelectable=angular.isDefined(e.isRowSelectable)?e.isRowSelectable:angular.noop},toggleRowSelection:function(e,t,i,o,n){if(!1!==t.enableSelection){var l,c=t.isSelected;o||(c?1<(l=a.getSelectedRows(e)).length&&(c=!1,a.clearSelectedRows(e,i)):a.clearSelectedRows(e,i)),c&&n||(t.setSelected(!c),!0===t.isSelected&&(e.selection.lastSelectedRow=t),l=a.getSelectedRows(e),e.selection.selectAll=e.rows.length===l.length,e.api.selection.raise.rowSelectionChanged(t,i))}},shiftSelect:function(e,t,i,o){if(o){var n=0({{"search.selectedItems" | t}} {{grid.selection.selectedCount}})'),e.put("ui-grid/selectionHeaderCell",'
    \x3c!--
     
    --\x3e
    '),e.put("ui-grid/selectionRowHeader",'
    '),e.put("ui-grid/selectionRowHeaderButtons",''),e.put("ui-grid/selectionSelectAllButtons",'')}]); \ No newline at end of file diff --git a/src/ui-grid.tree-base.js b/src/ui-grid.tree-base.js new file mode 100644 index 0000000000..3ce7e90b09 --- /dev/null +++ b/src/ui-grid.tree-base.js @@ -0,0 +1,1742 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.treeBase + * @description + * + * # ui.grid.treeBase + * + * + * + * This module provides base tree handling functions that are shared by other features, notably grouping + * and treeView. It provides a tree view of the data, with nodes in that + * tree and leaves. + * + * Design information: + * ------------------- + * + * The raw data that is provided must come with a $$treeLevel on any non-leaf node. Grouping will create + * these on all the group header rows, treeView will expect these to be set in the raw data by the user. + * TreeBase will run a rowsProcessor that: + * - builds `treeBase.tree` out of the provided rows + * - permits a recursive sort of the tree + * - maintains the expand/collapse state of each node + * - provides the expand/collapse all button and the expand/collapse buttons + * - maintains the count of children for each node + * + * Each row is updated with a link to the tree node that represents it. Refer {@link ui.grid.treeBase.grid:treeBase.tree tree documentation} + * for information. + * + * TreeBase adds information to the rows + * - treeLevel: if present and > -1 tells us the level (level 0 is the top level) + * - treeNode: pointer to the node in the grid.treeBase.tree that refers + * to this row, allowing us to manipulate the state + * + * Since the logic is baked into the rowsProcessors, it should get triggered whenever + * row order or filtering or anything like that is changed. We recall the expanded state + * across invocations of the rowsProcessors by the reference to the treeNode on the individual + * rows. We rebuild the tree itself quite frequently, when we do this we use the saved treeNodes to + * get the state, but we overwrite the other data in that treeNode. + * + * By default rows are collapsed, which means all data rows have their visible property + * set to false, and only level 0 group rows are set to visible. + * + * We rely on the rowsProcessors to do the actual expanding and collapsing, so we set the flags we want into + * grid.treeBase.tree, then call refresh. This is because we can't easily change the visible + * row cache without calling the processors, and once we've built the logic into the rowProcessors we may as + * well use it all the time. + * + * Tree base provides sorting (on non-grouped columns). + * + * Sorting works in two passes. The standard sorting is performed for any columns that are important to building + * the tree (for example, any grouped columns). Then after the tree is built, a recursive tree sort is performed + * for the remaining sort columns (including the original sort) - these columns are sorted within each tree level + * (so all the level 1 nodes are sorted, then all the level 2 nodes within each level 1 node etc). + * + * To achieve this we make use of the `ignoreSort` property on the sort configuration. The parent feature (treeView or grouping) + * must provide a rowsProcessor that runs with very low priority (typically in the 60-65 range), and that sets + * the `ignoreSort`on any sort that it wants to run on the tree. TreeBase will clear the ignoreSort on all sorts - so it + * will turn on any sorts that haven't run. It will then call a recursive sort on the tree. + * + * Tree base provides treeAggregation. It checks the treeAggregation configuration on each column, and aggregates based on + * the logic provided as it builds the tree. Footer aggregation from the uiGrid core should not be used with treeBase aggregation, + * since it operates on all visible rows, as opposed to to leaf nodes only. Setting `showColumnFooter: true` will show the + * treeAggregations in the column footer. Aggregation information will be collected in the format: + * + * ``` + * { + * type: 'count', + * value: 4, + * label: 'count: ', + * rendered: 'count: 4' + * } + * ``` + * + * A callback is provided to format the value once it is finalised (aka a valueFilter). + * + *
    + *
    + * + *
    + */ + + var module = angular.module('ui.grid.treeBase', ['ui.grid']); + + /** + * @ngdoc object + * @name ui.grid.treeBase.constant:uiGridTreeBaseConstants + * + * @description constants available in treeBase module. + * + * These constants are manually copied into grouping and treeView, + * as I haven't found a way to simply include them, and it's not worth + * investing time in for something that changes very infrequently. + * + */ + module.constant('uiGridTreeBaseConstants', { + featureName: "treeBase", + rowHeaderColName: 'treeBaseRowHeaderCol', + EXPANDED: 'expanded', + COLLAPSED: 'collapsed', + aggregation: { + COUNT: 'count', + SUM: 'sum', + MAX: 'max', + MIN: 'min', + AVG: 'avg' + } + }); + + /** + * @ngdoc service + * @name ui.grid.treeBase.service:uiGridTreeBaseService + * + * @description Services for treeBase feature + */ + /** + * @ngdoc object + * @name ui.grid.treeBase.api:ColumnDef + * + * @description ColumnDef for tree feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions.columnDef gridOptions.columnDefs} + */ + + module.service('uiGridTreeBaseService', ['$q', 'uiGridTreeBaseConstants', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', 'rowSorter', + function ($q, uiGridTreeBaseConstants, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants, rowSorter) { + + var service = { + + initializeGrid: function (grid) { + + // add feature namespace and any properties to grid for needed + /** + * @ngdoc object + * @name ui.grid.treeBase.grid:treeBase + * + * @description Grid properties and functions added for treeBase + */ + grid.treeBase = {}; + + /** + * @ngdoc property + * @propertyOf ui.grid.treeBase.grid:treeBase + * @name numberLevels + * + * @description Total number of tree levels currently used, calculated by the rowsProcessor by + * retaining the highest tree level it sees + */ + grid.treeBase.numberLevels = 0; + + /** + * @ngdoc property + * @propertyOf ui.grid.treeBase.grid:treeBase + * @name expandAll + * + * @description Whether or not the expandAll box is selected + */ + grid.treeBase.expandAll = false; + + /** + * @ngdoc property + * @propertyOf ui.grid.treeBase.grid:treeBase + * @name tree + * + * @description Tree represented as a nested array that holds the state of each node, along with a + * pointer to the row. The array order is material - we will display the children in the order + * they are stored in the array + * + * Each node stores: + * + * - the state of this node + * - an array of children of this node + * - a pointer to the parent of this node (reverse pointer, allowing us to walk up the tree) + * - the number of children of this node + * - aggregation information calculated from the nodes + * + * ``` + * [{ + * state: 'expanded', + * row: , + * parentRow: null, + * aggregations: [{ + * type: 'count', + * col: , + * value: 2, + * label: 'count: ', + * rendered: 'count: 2' + * }], + * children: [ + * { + * state: 'expanded', + * row: , + * parentRow: , + * aggregations: [{ + * type: 'count', + * col: ', + * value: 4, + * label: 'count: ', + * rendered: 'count: 4' + * }], + * children: [ + * { state: 'expanded', row: , parentRow: }, + * { state: 'collapsed', row: , parentRow: }, + * { state: 'expanded', row: , parentRow: }, + * { state: 'collapsed', row: , parentRow: } + * ] + * }, + * { + * state: 'collapsed', + * row: , + * parentRow: , + * aggregations: [{ + * type: 'count', + * col: , + * value: 3, + * label: 'count: ', + * rendered: 'count: 3' + * }], + * children: [ + * { state: 'expanded', row: , parentRow: }, + * { state: 'collapsed', row: , parentRow: }, + * { state: 'expanded', row: , parentRow: } + * ] + * } + * ] + * }, {} ] + * ``` + * Missing state values are false - meaning they aren't expanded. + * + * This is used because the rowProcessors run every time the grid is refreshed, so + * we'd lose the expanded state every time the grid was refreshed. This instead gives + * us a reliable lookup that persists across rowProcessors. + * + * This tree is rebuilt every time we run the rowsProcessors. Since each row holds a pointer + * to it's tree node we can persist expand/collapse state across calls to rowsProcessor, we discard + * all transient information on the tree (children, childCount) and recalculate it + * + */ + grid.treeBase.tree = []; + + service.defaultGridOptions(grid.options); + + grid.registerRowsProcessor(service.treeRows, 410); + + grid.registerColumnBuilder( service.treeBaseColumnBuilder ); + + service.createRowHeader( grid ); + + /** + * @ngdoc object + * @name ui.grid.treeBase.api:PublicApi + * + * @description Public Api for treeBase feature + */ + var publicApi = { + events: { + treeBase: { + /** + * @ngdoc event + * @eventOf ui.grid.treeBase.api:PublicApi + * @name rowExpanded + * @description raised whenever a row is expanded. If you are dynamically + * rendering your tree you can listen to this event, and then retrieve + * the children of this row and load them into the grid data. + * + * When the data is loaded the grid will automatically refresh to show these new rows + * + *
    +               *      gridApi.treeBase.on.rowExpanded(scope,function(row) {})
    +               * 
    + * @param {gridRow} row the row that was expanded. You can also + * retrieve the grid from this row with row.grid + */ + rowExpanded: {}, + + /** + * @ngdoc event + * @eventOf ui.grid.treeBase.api:PublicApi + * @name rowCollapsed + * @description raised whenever a row is collapsed. Doesn't really have + * a purpose at the moment, included for symmetry + * + *
    +               *      gridApi.treeBase.on.rowCollapsed(scope,function(row) {})
    +               * 
    + * @param {gridRow} row the row that was collapsed. You can also + * retrieve the grid from this row with row.grid + */ + rowCollapsed: {} + } + }, + + methods: { + treeBase: { + /** + * @ngdoc function + * @name expandAllRows + * @methodOf ui.grid.treeBase.api:PublicApi + * @description Expands all tree rows + */ + expandAllRows: function () { + service.expandAllRows(grid); + }, + + /** + * @ngdoc function + * @name collapseAllRows + * @methodOf ui.grid.treeBase.api:PublicApi + * @description collapse all tree rows + */ + collapseAllRows: function () { + service.collapseAllRows(grid); + }, + + /** + * @ngdoc function + * @name toggleRowTreeState + * @methodOf ui.grid.treeBase.api:PublicApi + * @description call expand if the row is collapsed, collapse if it is expanded + * @param {gridRow} row the row you wish to toggle + */ + toggleRowTreeState: function (row) { + service.toggleRowTreeState(grid, row); + }, + + /** + * @ngdoc function + * @name expandRow + * @methodOf ui.grid.treeBase.api:PublicApi + * @description expand the immediate children of the specified row + * @param {gridRow} row the row you wish to expand + * @param {boolean} recursive true if you wish to expand the row's ancients + */ + expandRow: function (row, recursive) { + service.expandRow(grid, row, recursive); + }, + + /** + * @ngdoc function + * @name expandRowChildren + * @methodOf ui.grid.treeBase.api:PublicApi + * @description expand all children of the specified row + * @param {gridRow} row the row you wish to expand + */ + expandRowChildren: function (row) { + service.expandRowChildren(grid, row); + }, + + /** + * @ngdoc function + * @name collapseRow + * @methodOf ui.grid.treeBase.api:PublicApi + * @description collapse the specified row. When + * you expand the row again, all grandchildren will retain their state + * @param {gridRow} row the row you wish to collapse + */ + collapseRow: function ( row ) { + service.collapseRow(grid, row); + }, + + /** + * @ngdoc function + * @name collapseRowChildren + * @methodOf ui.grid.treeBase.api:PublicApi + * @description collapse all children of the specified row. When + * you expand the row again, all grandchildren will be collapsed + * @param {gridRow} row the row you wish to collapse children for + */ + collapseRowChildren: function ( row ) { + service.collapseRowChildren(grid, row); + }, + + /** + * @ngdoc function + * @name getTreeState + * @methodOf ui.grid.treeBase.api:PublicApi + * @description Get the tree state for this grid, + * used by the saveState feature + * Returned treeState as an object + * `{ expandedState: { uid: 'expanded', uid: 'collapsed' } }` + * where expandedState is a hash of row uid and the current expanded state + * + * @returns {object} tree state + * + * TODO - this needs work - we need an identifier that persists across instantiations, + * not uid. This really means we need a row identity defined, but that won't work for + * grouping. Perhaps this needs to be moved up to treeView and grouping, rather than + * being in base. + */ + getTreeExpandedState: function () { + return { expandedState: service.getTreeState(grid) }; + }, + + /** + * @ngdoc function + * @name setTreeState + * @methodOf ui.grid.treeBase.api:PublicApi + * @description Set the expanded states of the tree + * @param {object} config the config you want to apply, in the format + * provided by getTreeState + */ + setTreeState: function ( config ) { + service.setTreeState( grid, config ); + }, + + /** + * @ngdoc function + * @name getRowChildren + * @methodOf ui.grid.treeBase.api:PublicApi + * @description Get the children of the specified row + * @param {GridRow} row the row you want the children of + * @returns {Array} array of children of this row, the children + * are all gridRows + */ + getRowChildren: function ( row ) { + return row.treeNode.children.map( function( childNode ) { + return childNode.row; + }); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + }, + + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.treeBase.api:GridOptions + * + * @description GridOptions for treeBase feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + */ + + /** + * @ngdoc object + * @name treeRowHeaderBaseWidth + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description Base width of the tree header, provides for a single level of tree. This + * is incremented by `treeIndent` for each extra level + *
    Defaults to 30 + */ + gridOptions.treeRowHeaderBaseWidth = gridOptions.treeRowHeaderBaseWidth || 30; + + /** + * @ngdoc object + * @name treeIndent + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description Number of pixels of indent for the icon at each tree level, wider indents are visually more pleasing, + * but will make the tree row header wider + *
    Defaults to 10 + */ + gridOptions.treeIndent = (gridOptions.treeIndent != null) ? gridOptions.treeIndent : 10; + + /** + * @ngdoc object + * @name showTreeRowHeader + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description If set to false, don't create the row header. You'll need to programmatically control the expand + * states + *
    Defaults to true + */ + gridOptions.showTreeRowHeader = gridOptions.showTreeRowHeader !== false; + + /** + * @ngdoc object + * @name showTreeExpandNoChildren + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description If set to true, show the expand/collapse button even if there are no + * children of a node. You'd use this if you're planning to dynamically load the children + * + *
    Defaults to true, grouping overrides to false + */ + gridOptions.showTreeExpandNoChildren = gridOptions.showTreeExpandNoChildren !== false; + + /** + * @ngdoc object + * @name treeRowHeaderAlwaysVisible + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description If set to true, row header even if there are no tree nodes + * + *
    Defaults to true + */ + gridOptions.treeRowHeaderAlwaysVisible = gridOptions.treeRowHeaderAlwaysVisible !== false; + + /** + * @ngdoc object + * @name treeCustomAggregations + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description Define custom aggregation functions. The properties of this object will be + * aggregation types available for use on columnDef with {@link ui.grid.treeBase.api:ColumnDef treeAggregationType} or through the column menu. + * If a function defined here uses the same name as one of the native aggregations, this one will take precedence. + * The object format is: + * + *
    +         *    {
    +         *      aggregationName: {
    +         *        label: (optional) string,
    +         *        aggregationFn: function( aggregation, fieldValue, numValue, row ) {...},
    +         *        finalizerFn: (optional) function( aggregation ) {...}
    +         *      },
    +         *      mean: {
    +         *        label: 'mean',
    +         *        aggregationFn: function( aggregation, fieldValue, numValue ) {
    +         *          aggregation.count = (aggregation.count || 1) + 1;
    +         *          aggregation.sum = (aggregation.sum || 0) + numValue;
    +         *        },
    +         *        finalizerFn: function( aggregation ) {
    +         *          aggregation.value = aggregation.sum / aggregation.count
    +         *        }
    +         *      }
    +         *    }
    +         *  
    + * + *
    The `finalizerFn` may be used to manipulate the value before rendering, or to + * apply a custom rendered value. If `aggregation.rendered` is left undefined, the value will be + * rendered. Note that the native aggregation functions use an `finalizerFn` to concatenate + * the label and the value. + * + *
    Defaults to {} + */ + gridOptions.treeCustomAggregations = gridOptions.treeCustomAggregations || {}; + + /** + * @ngdoc object + * @name enableExpandAll + * @propertyOf ui.grid.treeBase.api:GridOptions + * @description Enable the expand all button at the top of the row header + * + *
    Defaults to true + */ + gridOptions.enableExpandAll = gridOptions.enableExpandAll !== false; + }, + + + /** + * @ngdoc function + * @name treeBaseColumnBuilder + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Sets the tree defaults based on the columnDefs + * + * @param {object} colDef columnDef we're basing on + * @param {GridColumn} col the column we're to update + * @param {object} gridOptions the options we should use + * @returns {promise} promise for the builder - actually we do it all inline so it's immediately resolved + */ + treeBaseColumnBuilder: function (colDef, col, gridOptions) { + + + /** + * @ngdoc object + * @name customTreeAggregationFn + * @propertyOf ui.grid.treeBase.api:ColumnDef + * @description A custom function that aggregates rows into some form of + * total. Aggregations run row-by-row, the function needs to be capable of + * creating a running total. + * + * The function will be provided the aggregation item (in which you can store running + * totals), the row value that is to be aggregated, and that same row value converted to + * a number (most aggregations work on numbers) + * @example + *
    +         *    customTreeAggregationFn = function ( aggregation, fieldValue, numValue, row ) {
    +         *      // calculates the average of the squares of the values
    +         *      if ( typeof(aggregation.count) === 'undefined' ) {
    +         *        aggregation.count = 0;
    +         *      }
    +         *      aggregation.count++;
    +         *
    +         *      if ( !isNaN(numValue) ) {
    +         *        if ( typeof(aggregation.total) === 'undefined' ) {
    +         *          aggregation.total = 0;
    +         *        }
    +         *        aggregation.total = aggregation.total + numValue * numValue;
    +         *      }
    +         *
    +         *      aggregation.value = aggregation.total / aggregation.count;
    +         *    }
    +         *  
    + *
    Defaults to undefined. May be overwritten by treeAggregationType, the two options should not be used together. + */ + if ( typeof(colDef.customTreeAggregationFn) !== 'undefined' ) { + col.treeAggregationFn = colDef.customTreeAggregationFn; + } + + /** + * @ngdoc object + * @name treeAggregationType + * @propertyOf ui.grid.treeBase.api:ColumnDef + * @description Use one of the native or grid-level aggregation methods for calculating aggregations on this column. + * Native method are in the constants file and include: SUM, COUNT, MIN, MAX, AVG. This may also be the property the + * name of an aggregation function defined with {@link ui.grid.treeBase.api:GridOptions treeCustomAggregations}. + * + *
    +         *      treeAggregationType = uiGridTreeBaseConstants.aggregation.SUM,
    +         *    }
    +         *  
    + * + * If you are using aggregations you should either: + * + * - also use grouping, in which case the aggregations are displayed in the group header, OR + * - use treeView, in which case you can set `treeAggregationUpdateEntity: true` in the colDef, and + * treeBase will store the aggregation information in the entity, or you can set `treeAggregationUpdateEntity: false` + * in the colDef, and you need to manual retrieve the calculated aggregations from the row.treeNode.aggregations + * + *
    Takes precendence over a treeAggregationFn, the two options should not be used together. + *
    Defaults to undefined. + */ + if ( typeof(colDef.treeAggregationType) !== 'undefined' ) { + col.treeAggregation = { type: colDef.treeAggregationType }; + if ( typeof(gridOptions.treeCustomAggregations[colDef.treeAggregationType]) !== 'undefined' ) { + col.treeAggregationFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].aggregationFn; + col.treeAggregationFinalizerFn = gridOptions.treeCustomAggregations[colDef.treeAggregationType].finalizerFn; + col.treeAggregation.label = gridOptions.treeCustomAggregations[colDef.treeAggregationType].label; + } + else if ( typeof(service.nativeAggregations()[colDef.treeAggregationType]) !== 'undefined' ) { + col.treeAggregationFn = service.nativeAggregations()[colDef.treeAggregationType].aggregationFn; + col.treeAggregation.label = service.nativeAggregations()[colDef.treeAggregationType].label; + } + } + + /** + * @ngdoc object + * @name treeAggregationLabel + * @propertyOf ui.grid.treeBase.api:ColumnDef + * @description A custom label to use for this aggregation. If provided we don't use native i18n. + */ + if ( typeof(colDef.treeAggregationLabel) !== 'undefined' ) { + if (typeof(col.treeAggregation) === 'undefined' ) { + col.treeAggregation = {}; + } + col.treeAggregation.label = colDef.treeAggregationLabel; + } + + /** + * @ngdoc object + * @name treeAggregationUpdateEntity + * @propertyOf ui.grid.treeBase.api:ColumnDef + * @description Store calculated aggregations into the entity, allowing them + * to be displayed in the grid using a standard cellTemplate. This defaults to true, + * if you are using grouping then you shouldn't set it to false, as then the aggregations won't + * display. + * + * If you are using treeView in most cases you'll want to set this to true. This will result in + * getCellValue returning the aggregation rather than whatever was stored in the cell attribute on + * the entity. If you want to render the underlying entity value (and do something else with the aggregation) + * then you could use a custom cellTemplate to display `row.entity.myAttribute`, rather than using getCellValue. + * + *
    Defaults to true + * + * @example + *
    +         *    gridOptions.columns = [{
    +         *      name: 'myCol',
    +         *      treeAggregation: { type: uiGridTreeBaseConstants.aggregation.SUM },
    +         *      treeAggregationUpdateEntity: true
    +         *      cellTemplate: '
    {{row.entity.myCol + " " + row.treeNode.aggregations[0].rendered}}
    ' + * }]; + *
    + */ + col.treeAggregationUpdateEntity = colDef.treeAggregationUpdateEntity !== false; + + /** + * @ngdoc object + * @name customTreeAggregationFinalizerFn + * @propertyOf ui.grid.treeBase.api:ColumnDef + * @description A custom function that populates aggregation.rendered, this is called when + * a particular aggregation has been fully calculated, and we want to render the value. + * + * With the native aggregation options we just concatenate `aggregation.label` and + * `aggregation.value`, but if you wanted to apply a filter or otherwise manipulate the label + * or the value, you can do so with this function. This function will be called after the + * the default `finalizerFn`. + * + * @example + *
    +         *    customTreeAggregationFinalizerFn = function ( aggregation ) {
    +         *      aggregation.rendered = aggregation.label + aggregation.value / 100 + '%';
    +         *    }
    +         *  
    + *
    Defaults to undefined. + */ + if ( typeof(col.customTreeAggregationFinalizerFn) === 'undefined' ) { + col.customTreeAggregationFinalizerFn = colDef.customTreeAggregationFinalizerFn; + } + + }, + + + /** + * @ngdoc function + * @name createRowHeader + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Create the rowHeader. If treeRowHeaderAlwaysVisible then + * set it to visible, otherwise set it to invisible + * + * @param {Grid} grid grid object + */ + createRowHeader: function( grid ) { + var rowHeaderColumnDef = { + name: uiGridTreeBaseConstants.rowHeaderColName, + displayName: '', + width: grid.options.treeRowHeaderBaseWidth, + minWidth: 10, + cellTemplate: 'ui-grid/treeBaseRowHeader', + headerCellTemplate: 'ui-grid/treeBaseHeaderCell', + enableColumnResizing: false, + enableColumnMenu: false, + exporterSuppressExport: true, + allowCellFocus: true + }; + + rowHeaderColumnDef.visible = grid.options.treeRowHeaderAlwaysVisible; + grid.addRowHeaderColumn(rowHeaderColumnDef, -100); + }, + + + /** + * @ngdoc function + * @name expandAllRows + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Expands all nodes in the tree + * + * @param {Grid} grid grid object + */ + expandAllRows: function (grid) { + grid.treeBase.tree.forEach( function( node ) { + service.setAllNodes( grid, node, uiGridTreeBaseConstants.EXPANDED); + }); + grid.treeBase.expandAll = true; + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name collapseAllRows + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Collapses all nodes in the tree + * + * @param {Grid} grid grid object + */ + collapseAllRows: function (grid) { + grid.treeBase.tree.forEach( function( node ) { + service.setAllNodes( grid, node, uiGridTreeBaseConstants.COLLAPSED); + }); + grid.treeBase.expandAll = false; + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name setAllNodes + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Works through a subset of grid.treeBase.rowExpandedStates, setting + * all child nodes (and their descendents) of the provided node to the given state. + * + * Calls itself recursively on all nodes so as to achieve this. + * + * @param {Grid} grid the grid we're operating on (so we can raise events) + * @param {object} treeNode a node in the tree that we want to update + * @param {string} targetState the state we want to set it to + */ + setAllNodes: function (grid, treeNode, targetState) { + if ( typeof(treeNode.state) !== 'undefined' && treeNode.state !== targetState ) { + treeNode.state = targetState; + + if ( targetState === uiGridTreeBaseConstants.EXPANDED ) { + grid.api.treeBase.raise.rowExpanded(treeNode.row); + } + else { + grid.api.treeBase.raise.rowCollapsed(treeNode.row); + } + } + + // set all child nodes + if ( treeNode.children ) { + treeNode.children.forEach(function( childNode ) { + service.setAllNodes(grid, childNode, targetState); + }); + } + }, + + + /** + * @ngdoc function + * @name toggleRowTreeState + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Toggles the expand or collapse state of this grouped row, if + * it's a parent row + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to toggle + */ + toggleRowTreeState: function ( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } + + if (row.treeNode.state === uiGridTreeBaseConstants.EXPANDED) { + service.collapseRow(grid, row); + } + else { + service.expandRow(grid, row, false); + } + + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name expandRow + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Expands this specific row, showing only immediate children. + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to expand + * @param {boolean} recursive true if you wish to expand the row's ancients + */ + expandRow: function ( grid, row, recursive ) { + if ( recursive ) { + var parents = []; + while ( row && typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 && row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ) { + parents.push(row); + row = row.treeNode.parentRow; + } + + if ( parents.length > 0 ) { + row = parents.pop(); + while ( row ) { + row.treeNode.state = uiGridTreeBaseConstants.EXPANDED; + grid.api.treeBase.raise.rowExpanded(row); + row = parents.pop(); + } + + grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); + grid.queueGridRefresh(); + } + } + else { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } + + if ( row.treeNode.state !== uiGridTreeBaseConstants.EXPANDED ) { + row.treeNode.state = uiGridTreeBaseConstants.EXPANDED; + grid.api.treeBase.raise.rowExpanded(row); + grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); + grid.queueGridRefresh(); + } + } + }, + + + /** + * @ngdoc function + * @name expandRowChildren + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Expands this specific row, showing all children. + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to expand + */ + expandRowChildren: function ( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } + + service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.EXPANDED); + grid.treeBase.expandAll = service.allExpanded(grid.treeBase.tree); + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name collapseRow + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Collapses this specific row + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to collapse + */ + collapseRow: function( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } + + if ( row.treeNode.state !== uiGridTreeBaseConstants.COLLAPSED ) { + row.treeNode.state = uiGridTreeBaseConstants.COLLAPSED; + grid.treeBase.expandAll = false; + grid.api.treeBase.raise.rowCollapsed(row); + grid.queueGridRefresh(); + } + }, + + + /** + * @ngdoc function + * @name collapseRowChildren + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Collapses this specific row and all children + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to collapse + */ + collapseRowChildren: function( grid, row ) { + if ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) { + return; + } + + service.setAllNodes(grid, row.treeNode, uiGridTreeBaseConstants.COLLAPSED); + grid.treeBase.expandAll = false; + grid.queueGridRefresh(); + }, + + + /** + * @ngdoc function + * @name allExpanded + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Returns true if all rows are expanded, false + * if they're not. Walks the tree to determine this. Used + * to set the expandAll state. + * + * If the node has no children, then return true (it's immaterial + * whether it is expanded). If the node has children, then return + * false if this node is collapsed, or if any child node is not all expanded + * + * @param {object} tree the grid to check + * @returns {boolean} whether or not the tree is all expanded + */ + allExpanded: function( tree ) { + var allExpanded = true; + + tree.forEach(function( node ) { + if ( !service.allExpandedInternal( node ) ) { + allExpanded = false; + } + }); + return allExpanded; + }, + + allExpandedInternal: function( treeNode ) { + if ( treeNode.children && treeNode.children.length > 0 ) { + if ( treeNode.state === uiGridTreeBaseConstants.COLLAPSED ) { + return false; + } + var allExpanded = true; + treeNode.children.forEach( function( node ) { + if ( !service.allExpandedInternal( node ) ) { + allExpanded = false; + } + }); + return allExpanded; + } + else { + return true; + } + }, + + + /** + * @ngdoc function + * @name treeRows + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description The rowProcessor that adds the nodes to the tree, and sets the visible + * state of each row based on it's parent state + * + * Assumes it is always called after the sorting processor, and the grouping processor if there is one. + * Performs any tree sorts itself after having built the tree + * + * Processes all the rows in order, setting the group level based on the $$treeLevel in the associated + * entity, and setting the visible state based on the parent's state. + * + * Calculates the deepest level of tree whilst it goes, and updates that so that the header column can be correctly + * sized. + * + * Aggregates if necessary along the way. + * + * @param {array} renderableRows the rows we want to process, usually the output from the previous rowProcessor + * @returns {array} the updated rows + */ + treeRows: function( renderableRows ) { + var grid = this; + + if (renderableRows.length === 0) { + service.updateRowHeaderWidth( grid ); + return renderableRows; + } + + grid.treeBase.tree = service.createTree( grid, renderableRows ); + service.updateRowHeaderWidth( grid ); + + service.sortTree( grid ); + service.fixFilter( grid ); + + return service.renderTree( grid.treeBase.tree ); + }, + + + /** + * @ngdoc function + * @name createOrUpdateRowHeaderWidth + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Calculates the rowHeader width. + * + * If rowHeader is always present, updates the width. + * + * If rowHeader is only sometimes present (`treeRowHeaderAlwaysVisible: false`), determines whether there + * should be one, then creates or removes it as appropriate, with the created rowHeader having the + * right width. + * + * If there's never a rowHeader then never creates one: `showTreeRowHeader: false` + * + * @param {Grid} grid the grid we want to set the row header on + */ + updateRowHeaderWidth: function( grid ) { + var rowHeader = grid.getColumn(uiGridTreeBaseConstants.rowHeaderColName), + newWidth = grid.options.treeRowHeaderBaseWidth + grid.options.treeIndent * Math.max(grid.treeBase.numberLevels - 1, 0); + + if ( rowHeader && newWidth !== rowHeader.width ) { + rowHeader.width = newWidth; + grid.queueRefresh(); + } + + var newVisibility = true; + + if ( grid.options.showTreeRowHeader === false ) { + newVisibility = false; + } + if ( grid.options.treeRowHeaderAlwaysVisible === false && grid.treeBase.numberLevels <= 0 ) { + newVisibility = false; + } + if ( rowHeader && rowHeader.visible !== newVisibility ) { + rowHeader.visible = newVisibility; + rowHeader.colDef.visible = newVisibility; + grid.queueGridRefresh(); + } + }, + + + /** + * @ngdoc function + * @name renderTree + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Creates an array of rows based on the tree, exporting only + * the visible nodes and leaves + * + * @param {array} nodeList The list of nodes - can be grid.treeBase.tree, or can be node.children when + * we're calling recursively + * @returns {array} renderable rows + */ + renderTree: function( nodeList ) { + var renderableRows = []; + + nodeList.forEach( function ( node ) { + if ( node.row.visible ) { + renderableRows.push( node.row ); + } + if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ) { + renderableRows = renderableRows.concat( service.renderTree( node.children ) ); + } + }); + return renderableRows; + }, + + + /** + * @ngdoc function + * @name createTree + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Creates a tree from the renderableRows + * + * @param {Grid} grid The grid + * @param {array} renderableRows The rows we want to create a tree from + * @returns {object} The tree we've build + */ + createTree: function( grid, renderableRows ) { + var currentLevel = -1, + parentsCache = {}, + parents = [], + currentState; + + grid.treeBase.tree = []; + grid.treeBase.numberLevels = 0; + + var aggregations = service.getAggregations( grid ); + + function createNode( row ) { + if ( !row.internalRow && row.treeLevel !== row.entity.$$treeLevel ) { + row.treeLevel = row.entity.$$treeLevel; + } + + if ( row.treeLevel <= currentLevel ) { + // pop any levels that aren't parents of this level, formatting the aggregation at the same time + while ( row.treeLevel <= currentLevel ) { + var lastParent = parents.pop(); + service.finaliseAggregations( lastParent ); + currentLevel--; + } + + // reset our current state based on the new parent, set to expanded if this is a level 0 node + if ( parents.length > 0 ) { + currentState = service.setCurrentState(parents); + } + else { + currentState = uiGridTreeBaseConstants.EXPANDED; + } + } + + // If row header as parent exists in parentsCache + if ( + typeof row.treeLevel !== 'undefined' && + row.treeLevel !== null && + row.treeLevel >= 0 && + parentsCache.hasOwnProperty(row.uid) + ) { + parents.push(parentsCache[row.uid]); + } + + // aggregate if this is a leaf node + if ( ( typeof(row.treeLevel) === 'undefined' || row.treeLevel === null || row.treeLevel < 0 ) && row.visible ) { + service.aggregate( grid, row, parents ); + } + + // add this node to the tree + if (!parentsCache.hasOwnProperty(row.uid)) { + service.addOrUseNode(grid, row, parents, aggregations); + } + + if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel !== null && row.treeLevel >= 0 ) { + if (!parentsCache.hasOwnProperty(row.uid)) { + parentsCache[row.uid] = row; + parents.push(row); + } + currentLevel++; + currentState = service.setCurrentState(parents); + } + + // update the tree number of levels, so we can set header width if we need to + if ( grid.treeBase.numberLevels < row.treeLevel + 1) { + grid.treeBase.numberLevels = row.treeLevel + 1; + } + } + + renderableRows.forEach( createNode ); + + // finalize remaining aggregations + while ( parents.length > 0 ) { + var lastParent = parents.pop(); + service.finaliseAggregations( lastParent ); + } + + return grid.treeBase.tree; + }, + + + /** + * @ngdoc function + * @name addOrUseNode + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Creates a tree node for this row. If this row already has a treeNode + * recorded against it, preserves the state, but otherwise overwrites the data. + * + * @param {grid} grid The grid we're operating on + * @param {gridRow} row The row we want to set + * @param {array} parents An array of the parents this row should have + * @param {array} aggregationBase Empty aggregation information + * @returns {undefined} Updates the parents array, updates the row to have a treeNode, and updates the + * grid.treeBase.tree + */ + addOrUseNode: function( grid, row, parents, aggregationBase ) { + var newAggregations = []; + aggregationBase.forEach( function(aggregation) { + newAggregations.push(service.buildAggregationObject(aggregation.col)); + }); + + var newNode = { state: uiGridTreeBaseConstants.COLLAPSED, row: row, parentRow: null, aggregations: newAggregations, children: [] }; + if ( row.treeNode ) { + newNode.state = row.treeNode.state; + } + if ( parents.length > 0 ) { + newNode.parentRow = parents[parents.length - 1]; + } + row.treeNode = newNode; + + if ( parents.length === 0 ) { + grid.treeBase.tree.push( newNode ); + } else { + parents[parents.length - 1].treeNode.children.push( newNode ); + } + }, + + + /** + * @ngdoc function + * @name setCurrentState + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Looks at the parents array to determine our current state. + * If any node in the hierarchy is collapsed, then return collapsed, otherwise return + * expanded. + * + * @param {array} parents An array of the parents this row should have + * @returns {string} The state we should be setting to any nodes we see + */ + setCurrentState: function( parents ) { + var currentState = uiGridTreeBaseConstants.EXPANDED; + + parents.forEach( function(parent) { + if ( parent.treeNode.state === uiGridTreeBaseConstants.COLLAPSED ) { + currentState = uiGridTreeBaseConstants.COLLAPSED; + } + }); + return currentState; + }, + + + /** + * @ngdoc function + * @name sortTree + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Performs a recursive sort on the tree nodes, sorting the + * children of each node and putting them back into the children array. + * + * Before doing this it turns back on all the sortIgnore - things that were previously + * ignored we process now. Since we're sorting within the nodes, presumably anything + * that was already sorted is how we derived the nodes, we can keep those sorts too. + * + * We only sort tree nodes that are expanded - no point in wasting effort sorting collapsed + * nodes + * + * @param {Grid} grid The grid to get the aggregation information from + * @returns {array} The aggregation information + */ + sortTree: function( grid ) { + grid.columns.forEach( function( column ) { + if ( column.sort && column.sort.ignoreSort ) { + delete column.sort.ignoreSort; + } + }); + + grid.treeBase.tree = service.sortInternal( grid, grid.treeBase.tree ); + }, + + sortInternal: function( grid, treeList ) { + var rows = treeList.map( function( node ) { + return node.row; + }); + + rows = rowSorter.sort( grid, rows, grid.columns ); + + var treeNodes = rows.map( function( row ) { + return row.treeNode; + }); + + treeNodes.forEach( function( node ) { + if ( node.state === uiGridTreeBaseConstants.EXPANDED && node.children && node.children.length > 0 ) { + node.children = service.sortInternal( grid, node.children ); + } + }); + + return treeNodes; + }, + + /** + * @ngdoc function + * @name fixFilter + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description After filtering has run, we need to go back through the tree + * and make sure the parent rows are always visible if any of the child rows + * are visible (filtering may make a child visible, but the parent may not + * match the filter criteria) + * + * This has a risk of being computationally expensive, we do it by walking + * the tree and remembering whether there are any invisible nodes on the + * way down. + * + * @param {Grid} grid the grid to fix filters on + */ + fixFilter: function( grid ) { + var parentsVisible; + + grid.treeBase.tree.forEach( function( node ) { + if ( node.children && node.children.length > 0 ) { + parentsVisible = node.row.visible; + service.fixFilterInternal( node.children, parentsVisible ); + } + }); + }, + + fixFilterInternal: function( nodes, parentsVisible) { + nodes.forEach(function( node ) { + if ( node.row.visible && !parentsVisible ) { + service.setParentsVisible( node ); + parentsVisible = true; + } + + if ( node.children && node.children.length > 0 ) { + if ( service.fixFilterInternal( node.children, ( parentsVisible && node.row.visible ) ) ) { + parentsVisible = true; + } + } + }); + + return parentsVisible; + }, + + setParentsVisible: function( node ) { + while ( node.parentRow ) { + node.parentRow.visible = true; + node = node.parentRow.treeNode; + } + }, + + /** + * @ngdoc function + * @name buildAggregationObject + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Build the object which is stored on the column for holding meta-data about the aggregation. + * This method should only be called with columns which have an aggregation. + * + * @param {GridColumn} column The column which this object relates to + * @returns {object} {col: GridColumn object, label: string, type: string (optional)} + */ + buildAggregationObject: function( column ) { + var newAggregation = { col: column }; + + if ( column.treeAggregation && column.treeAggregation.type ) { + newAggregation.type = column.treeAggregation.type; + } + + if ( column.treeAggregation && column.treeAggregation.label ) { + newAggregation.label = column.treeAggregation.label; + } + + return newAggregation; + }, + + /** + * @ngdoc function + * @name getAggregations + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Looks through the grid columns to find those with aggregations, + * and collates the aggregation information into an array, returns that array + * + * @param {Grid} grid the grid to get the aggregation information from + * @returns {array} the aggregation information + */ + getAggregations: function( grid ) { + var aggregateArray = []; + + grid.columns.forEach( function(column) { + if ( typeof(column.treeAggregationFn) !== 'undefined' ) { + aggregateArray.push( service.buildAggregationObject(column) ); + + if ( grid.options.showColumnFooter && typeof(column.colDef.aggregationType) === 'undefined' && column.treeAggregation ) { + // Add aggregation object for footer + column.treeFooterAggregation = service.buildAggregationObject(column); + column.aggregationType = service.treeFooterAggregationType; + } + } + }); + return aggregateArray; + }, + + + /** + * @ngdoc function + * @name aggregate + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Accumulate the data from this row onto the aggregations for each parent + * + * Iterate over the parents, then iterate over the aggregations for each of those parents, + * and perform the aggregation for each individual aggregation + * + * @param {Grid} grid grid object + * @param {GridRow} row the row we want to set grouping visibility on + * @param {array} parents the parents that we would want to aggregate onto + */ + aggregate: function( grid, row, parents ) { + if (parents.length === 0 && row.treeNode && row.treeNode.aggregations) { + row.treeNode.aggregations.forEach(function(aggregation) { + // Calculate aggregations for footer even if there are no grouped rows + if (typeof(aggregation.col.treeFooterAggregation) !== 'undefined') { + var fieldValue = grid.getCellValue(row, aggregation.col); + var numValue = Number(fieldValue); + if (aggregation.col.treeAggregationFn) { + aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + } else { + aggregation.col.treeFooterAggregation.value = undefined; + } + } + }); + } + + parents.forEach( function( parent, index ) { + if (parent.treeNode.aggregations) { + parent.treeNode.aggregations.forEach( function( aggregation ) { + var fieldValue = grid.getCellValue(row, aggregation.col); + var numValue = Number(fieldValue); + aggregation.col.treeAggregationFn(aggregation, fieldValue, numValue, row); + + if (index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined') { + if (aggregation.col.treeAggregationFn) { + aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row); + } else { + aggregation.col.treeFooterAggregation.value = undefined; + } + } + }); + } + }); + }, + + + // Aggregation routines - no doco needed as self evident + nativeAggregations: function() { + return { + count: { + label: i18nService.get().aggregation.count, + menuTitle: i18nService.get().grouping.aggregate_count, + aggregationFn: function (aggregation, fieldValue, numValue) { + if (typeof(aggregation.value) === 'undefined') { + aggregation.value = 1; + } else { + aggregation.value++; + } + } + }, + + sum: { + label: i18nService.get().aggregation.sum, + menuTitle: i18nService.get().grouping.aggregate_sum, + aggregationFn: function( aggregation, fieldValue, numValue ) { + if (!isNaN(numValue)) { + if (typeof(aggregation.value) === 'undefined') { + aggregation.value = numValue; + } else { + aggregation.value += numValue; + } + } + } + }, + + min: { + label: i18nService.get().aggregation.min, + menuTitle: i18nService.get().grouping.aggregate_min, + aggregationFn: function( aggregation, fieldValue, numValue ) { + if (typeof(aggregation.value) === 'undefined') { + aggregation.value = fieldValue; + } else { + if (typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue < aggregation.value || aggregation.value === null)) { + aggregation.value = fieldValue; + } + } + } + }, + + max: { + label: i18nService.get().aggregation.max, + menuTitle: i18nService.get().grouping.aggregate_max, + aggregationFn: function( aggregation, fieldValue, numValue ) { + if ( typeof(aggregation.value) === 'undefined' ) { + aggregation.value = fieldValue; + } else { + if ( typeof(fieldValue) !== 'undefined' && fieldValue !== null && (fieldValue > aggregation.value || aggregation.value === null)) { + aggregation.value = fieldValue; + } + } + } + }, + + avg: { + label: i18nService.get().aggregation.avg, + menuTitle: i18nService.get().grouping.aggregate_avg, + aggregationFn: function( aggregation, fieldValue, numValue ) { + if ( typeof(aggregation.count) === 'undefined' ) { + aggregation.count = 1; + } else { + aggregation.count++; + } + + if ( isNaN(numValue) ) { + return; + } + + if ( typeof(aggregation.value) === 'undefined' || typeof(aggregation.sum) === 'undefined' ) { + aggregation.value = numValue; + aggregation.sum = numValue; + } else { + aggregation.sum += numValue; + aggregation.value = aggregation.sum / aggregation.count; + } + } + } + }; + }, + + /** + * @ngdoc function + * @name finaliseAggregation + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Helper function used to finalize aggregation nodes and footer cells + * + * @param {gridRow} row The parent we're finalising + * @param {aggregation} aggregation The aggregation object manipulated by the aggregationFn + */ + finaliseAggregation: function(row, aggregation) { + if ( aggregation.col.treeAggregationUpdateEntity && typeof(row) !== 'undefined' && typeof(row.entity[ '$$' + aggregation.col.uid ]) !== 'undefined' ) { + angular.extend( aggregation, row.entity[ '$$' + aggregation.col.uid ]); + } + + if ( typeof(aggregation.col.treeAggregationFinalizerFn) === 'function' ) { + aggregation.col.treeAggregationFinalizerFn( aggregation ); + } + if ( typeof(aggregation.col.customTreeAggregationFinalizerFn) === 'function' ) { + aggregation.col.customTreeAggregationFinalizerFn( aggregation ); + } + if ( typeof(aggregation.rendered) === 'undefined' ) { + aggregation.rendered = aggregation.label ? aggregation.label + aggregation.value : aggregation.value; + } + }, + + /** + * @ngdoc function + * @name finaliseAggregations + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Format the data from the aggregation into the rendered text + * e.g. if we had label: 'sum: ' and value: 25, we'd create 'sum: 25'. + * + * As part of this we call any formatting callback routines we've been provided. + * + * We write our aggregation out to the row.entity if treeAggregationUpdateEntity is + * set on the column - we don't overwrite any information that's already there, we append + * to it so that grouping can have set the groupVal beforehand without us overwriting it. + * + * We need to copy the data from the row.entity first before we finalise the aggregation, + * we need that information for the finaliserFn + * + * @param {gridRow} row the parent we're finalising + */ + finaliseAggregations: function( row ) { + if ( row == null || typeof(row.treeNode.aggregations) === 'undefined' ) { + return; + } + + row.treeNode.aggregations.forEach( function( aggregation ) { + service.finaliseAggregation(row, aggregation); + + if ( aggregation.col.treeAggregationUpdateEntity ) { + var aggregationCopy = {}; + + angular.forEach( aggregation, function( value, key ) { + if ( aggregation.hasOwnProperty(key) && key !== 'col' ) { + aggregationCopy[key] = value; + } + }); + + row.entity[ '$$' + aggregation.col.uid ] = aggregationCopy; + } + }); + }, + + /** + * @ngdoc function + * @name treeFooterAggregationType + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Uses the tree aggregation functions and finalizers to set the + * column footer aggregations. + * + * @param {rows} rows The visible rows. not used, but accepted to match signature of GridColumn.aggregationType + * @param {GridColumn} column The column we are finalizing + */ + treeFooterAggregationType: function( rows, column ) { + service.finaliseAggregation(undefined, column.treeFooterAggregation); + if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ) { + // The was apparently no aggregation performed (perhaps this is a grouped column + return ''; + } + return column.treeFooterAggregation.rendered; + } + }; + + return service; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.treeBase.directive:uiGridTreeRowHeaderButtons + * @element div + * + * @description Provides the expand/collapse button on rows + */ + module.directive('uiGridTreeBaseRowHeaderButtons', ['$templateCache', 'uiGridTreeBaseService', + function ($templateCache, uiGridTreeBaseService) { + return { + replace: true, + restrict: 'E', + template: $templateCache.get('ui-grid/treeBaseRowHeaderButtons'), + scope: true, + require: '^uiGrid', + link: function($scope, $elm, $attrs, uiGridCtrl) { + var self = uiGridCtrl.grid; + $scope.treeButtonClass = function(row) { + if ( ( self.options.showTreeExpandNoChildren && row.treeLevel > -1 ) || ( row.treeNode.children && row.treeNode.children.length > 0 ) ) { + if (row.treeNode.state === 'expanded' ) { + return 'ui-grid-icon-minus-squared'; + } + if (row.treeNode.state === 'collapsed' ) { + return 'ui-grid-icon-plus-squared'; + } + } + }; + $scope.treeButtonClick = function(row, evt) { + evt.stopPropagation(); + uiGridTreeBaseService.toggleRowTreeState(self, row, evt); + }; + $scope.treeButtonKeyDown = function (row, evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + $scope.treeButtonClick(row, evt); + } + }; + } + }; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.treeBase.directive:uiGridTreeBaseExpandAllButtons + * @element div + * + * @description Provides the expand/collapse all button + */ + module.directive('uiGridTreeBaseExpandAllButtons', ['$templateCache', 'uiGridTreeBaseService', + function ($templateCache, uiGridTreeBaseService) { + return { + replace: true, + restrict: 'E', + template: $templateCache.get('ui-grid/treeBaseExpandAllButtons'), + scope: false, + link: function($scope) { + var self = $scope.col.grid; + $scope.headerButtonClass = function() { + if (self.treeBase.numberLevels > 0 && self.treeBase.expandAll) { + return 'ui-grid-icon-minus-squared'; + } + if (self.treeBase.numberLevels > 0 && !self.treeBase.expandAll) { + return 'ui-grid-icon-plus-squared'; + } + }; + $scope.headerButtonClick = function(row, evt) { + if ( self.treeBase.expandAll ) { + uiGridTreeBaseService.collapseAllRows(self, evt); + } else { + uiGridTreeBaseService.expandAllRows(self, evt); + } + }; + $scope.headerButtonKeyDown = function (evt) { + if (evt.keyCode === 32 || evt.keyCode === 13) { + $scope.headerButtonClick(self, evt); + } + }; + } + }; + }]); + + + /** + * @ngdoc directive + * @name ui.grid.treeBase.directive:uiGridViewport + * @element div + * + * @description Stacks on top of ui.grid.uiGridViewport to set formatting on a tree header row + */ + module.directive('uiGridViewport', + function () { + return { + priority: -200, // run after default directive + scope: false, + compile: function ($elm) { + var rowRepeatDiv = angular.element($elm.children().children()[0]); + + var existingNgClass = rowRepeatDiv.attr("ng-class"); + var newNgClass = ''; + if ( existingNgClass ) { + newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-tree-header-row': row.treeLevel > -1}"; + } else { + newNgClass = "{'ui-grid-tree-header-row': row.treeLevel > -1}"; + } + rowRepeatDiv.attr("ng-class", newNgClass); + + return { + pre: function ($scope, $elm, $attrs, controllers) { + + }, + post: function ($scope, $elm, $attrs, controllers) { + } + }; + } + }; + }); +})(); + +angular.module('ui.grid.treeBase').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/treeBaseExpandAllButtons', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseHeaderCell', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeader', + "
    " + ); + + + $templateCache.put('ui-grid/treeBaseRowHeaderButtons', + "
    -1 }\" tabindex=\"0\" ng-keydown=\"treeButtonKeyDown(row, $event)\" ng-click=\"treeButtonClick(row, $event)\">  
    " + ); + +}]); diff --git a/src/ui-grid.tree-base.min.js b/src/ui-grid.tree-base.min.js new file mode 100644 index 0000000000..2bb21d49c5 --- /dev/null +++ b/src/ui-grid.tree-base.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.treeBase",["ui.grid"]);e.constant("uiGridTreeBaseConstants",{featureName:"treeBase",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),e.service("uiGridTreeBaseService",["$q","uiGridTreeBaseConstants","gridUtil","GridRow","gridClassFactory","i18nService","uiGridConstants","rowSorter",function(e,l,t,r,n,o,a,i){var g={initializeGrid:function(r){r.treeBase={},r.treeBase.numberLevels=0,r.treeBase.expandAll=!1,r.treeBase.tree=[],g.defaultGridOptions(r.options),r.registerRowsProcessor(g.treeRows,410),r.registerColumnBuilder(g.treeBaseColumnBuilder),g.createRowHeader(r);var e={events:{treeBase:{rowExpanded:{},rowCollapsed:{}}},methods:{treeBase:{expandAllRows:function(){g.expandAllRows(r)},collapseAllRows:function(){g.collapseAllRows(r)},toggleRowTreeState:function(e){g.toggleRowTreeState(r,e)},expandRow:function(e,t){g.expandRow(r,e,t)},expandRowChildren:function(e){g.expandRowChildren(r,e)},collapseRow:function(e){g.collapseRow(r,e)},collapseRowChildren:function(e){g.collapseRowChildren(r,e)},getTreeExpandedState:function(){return{expandedState:g.getTreeState(r)}},setTreeState:function(e){g.setTreeState(r,e)},getRowChildren:function(e){return e.treeNode.children.map(function(e){return e.row})}}}};r.api.registerEventsFromObject(e.events),r.api.registerMethodsFromObject(e.methods)},defaultGridOptions:function(e){e.treeRowHeaderBaseWidth=e.treeRowHeaderBaseWidth||30,e.treeIndent=null!=e.treeIndent?e.treeIndent:10,e.showTreeRowHeader=!1!==e.showTreeRowHeader,e.showTreeExpandNoChildren=!1!==e.showTreeExpandNoChildren,e.treeRowHeaderAlwaysVisible=!1!==e.treeRowHeaderAlwaysVisible,e.treeCustomAggregations=e.treeCustomAggregations||{},e.enableExpandAll=!1!==e.enableExpandAll},treeBaseColumnBuilder:function(e,t,r){void 0!==e.customTreeAggregationFn&&(t.treeAggregationFn=e.customTreeAggregationFn),void 0!==e.treeAggregationType&&(t.treeAggregation={type:e.treeAggregationType},void 0!==r.treeCustomAggregations[e.treeAggregationType]?(t.treeAggregationFn=r.treeCustomAggregations[e.treeAggregationType].aggregationFn,t.treeAggregationFinalizerFn=r.treeCustomAggregations[e.treeAggregationType].finalizerFn,t.treeAggregation.label=r.treeCustomAggregations[e.treeAggregationType].label):void 0!==g.nativeAggregations()[e.treeAggregationType]&&(t.treeAggregationFn=g.nativeAggregations()[e.treeAggregationType].aggregationFn,t.treeAggregation.label=g.nativeAggregations()[e.treeAggregationType].label)),void 0!==e.treeAggregationLabel&&(void 0===t.treeAggregation&&(t.treeAggregation={}),t.treeAggregation.label=e.treeAggregationLabel),t.treeAggregationUpdateEntity=!1!==e.treeAggregationUpdateEntity,void 0===t.customTreeAggregationFinalizerFn&&(t.customTreeAggregationFinalizerFn=e.customTreeAggregationFinalizerFn)},createRowHeader:function(e){var t={name:l.rowHeaderColName,displayName:"",width:e.options.treeRowHeaderBaseWidth,minWidth:10,cellTemplate:"ui-grid/treeBaseRowHeader",headerCellTemplate:"ui-grid/treeBaseHeaderCell",enableColumnResizing:!1,enableColumnMenu:!1,exporterSuppressExport:!0,allowCellFocus:!0};t.visible=e.options.treeRowHeaderAlwaysVisible,e.addRowHeaderColumn(t,-100)},expandAllRows:function(t){t.treeBase.tree.forEach(function(e){g.setAllNodes(t,e,l.EXPANDED)}),t.treeBase.expandAll=!0,t.queueGridRefresh()},collapseAllRows:function(t){t.treeBase.tree.forEach(function(e){g.setAllNodes(t,e,l.COLLAPSED)}),t.treeBase.expandAll=!1,t.queueGridRefresh()},setAllNodes:function(t,e,r){void 0!==e.state&&e.state!==r&&((e.state=r)===l.EXPANDED?t.api.treeBase.raise.rowExpanded(e.row):t.api.treeBase.raise.rowCollapsed(e.row)),e.children&&e.children.forEach(function(e){g.setAllNodes(t,e,r)})},toggleRowTreeState:function(e,t){void 0===t.treeLevel||null===t.treeLevel||t.treeLevel<0||(t.treeNode.state===l.EXPANDED?g.collapseRow(e,t):g.expandRow(e,t,!1),e.queueGridRefresh())},expandRow:function(e,t,r){if(r){for(var n=[];t&&void 0!==t.treeLevel&&null!==t.treeLevel&&0<=t.treeLevel&&t.treeNode.state!==l.EXPANDED;)n.push(t),t=t.treeNode.parentRow;if(0e.value||null===e.value)&&(e.value=t)}},avg:{label:o.get().aggregation.avg,menuTitle:o.get().grouping.aggregate_avg,aggregationFn:function(e,t,r){void 0===e.count?e.count=1:e.count++,isNaN(r)||(void 0===e.value||void 0===e.sum?(e.value=r,e.sum=r):(e.sum+=r,e.value=e.sum/e.count))}}}},finaliseAggregation:function(e,t){t.col.treeAggregationUpdateEntity&&void 0!==e&&void 0!==e.entity["$$"+t.col.uid]&&angular.extend(t,e.entity["$$"+t.col.uid]),"function"==typeof t.col.treeAggregationFinalizerFn&&t.col.treeAggregationFinalizerFn(t),"function"==typeof t.col.customTreeAggregationFinalizerFn&&t.col.customTreeAggregationFinalizerFn(t),void 0===t.rendered&&(t.rendered=t.label?t.label+t.value:t.value)},finaliseAggregations:function(e){null!=e&&void 0!==e.treeNode.aggregations&&e.treeNode.aggregations.forEach(function(r){if(g.finaliseAggregation(e,r),r.col.treeAggregationUpdateEntity){var n={};angular.forEach(r,function(e,t){r.hasOwnProperty(t)&&"col"!==t&&(n[t]=e)}),e.entity["$$"+r.col.uid]=n}})},treeFooterAggregationType:function(e,t){return g.finaliseAggregation(void 0,t.treeFooterAggregation),void 0===t.treeFooterAggregation.value||null===t.treeFooterAggregation.rendered?"":t.treeFooterAggregation.rendered}};return g}]),e.directive("uiGridTreeBaseRowHeaderButtons",["$templateCache","uiGridTreeBaseService",function(e,a){return{replace:!0,restrict:"E",template:e.get("ui-grid/treeBaseRowHeaderButtons"),scope:!0,require:"^uiGrid",link:function(r,e,t,n){var o=n.grid;r.treeButtonClass=function(e){if(o.options.showTreeExpandNoChildren&&-1 -1}":"{'ui-grid-tree-header-row': row.treeLevel > -1}",t.attr("ng-class",n),{pre:function(e,t,r,n){},post:function(e,t,r,n){}}}}})}(),angular.module("ui.grid.treeBase").run(["$templateCache",function(e){"use strict";e.put("ui-grid/treeBaseExpandAllButtons",'
    '),e.put("ui-grid/treeBaseHeaderCell",'
    '),e.put("ui-grid/treeBaseRowHeader",'
    '),e.put("ui-grid/treeBaseRowHeaderButtons",'
     
    ')}]); \ No newline at end of file diff --git a/src/ui-grid.tree-view.js b/src/ui-grid.tree-view.js new file mode 100644 index 0000000000..852017f4bd --- /dev/null +++ b/src/ui-grid.tree-view.js @@ -0,0 +1,217 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.treeView + * @description + * + * # ui.grid.treeView + * + * + * + * This module provides a tree view of the data that it is provided, with nodes in that + * tree and leaves. Unlike grouping, the tree is an inherent property of the data and must + * be provided with your data array. + * + * Design information: + * ------------------- + * + * TreeView uses treeBase for the underlying functionality, and is a very thin wrapper around + * that logic. Most of the design information has now moved to treebase. + *
    + *
    + * + *
    + */ + + var module = angular.module('ui.grid.treeView', ['ui.grid', 'ui.grid.treeBase']); + + /** + * @ngdoc object + * @name ui.grid.treeView.constant:uiGridTreeViewConstants + * + * @description constants available in treeView module, this includes + * all the constants declared in the treeBase module (these are manually copied + * as there isn't an easy way to include constants in another constants file, and + * we don't want to make users include treeBase) + * + */ + module.constant('uiGridTreeViewConstants', { + featureName: "treeView", + rowHeaderColName: 'treeBaseRowHeaderCol', + EXPANDED: 'expanded', + COLLAPSED: 'collapsed', + aggregation: { + COUNT: 'count', + SUM: 'sum', + MAX: 'max', + MIN: 'min', + AVG: 'avg' + } + }); + + /** + * @ngdoc service + * @name ui.grid.treeView.service:uiGridTreeViewService + * + * @description Services for treeView features + */ + module.service('uiGridTreeViewService', ['$q', 'uiGridTreeViewConstants', 'uiGridTreeBaseConstants', 'uiGridTreeBaseService', 'gridUtil', 'GridRow', 'gridClassFactory', 'i18nService', 'uiGridConstants', + function ($q, uiGridTreeViewConstants, uiGridTreeBaseConstants, uiGridTreeBaseService, gridUtil, GridRow, gridClassFactory, i18nService, uiGridConstants) { + + var service = { + + initializeGrid: function (grid, $scope) { + uiGridTreeBaseService.initializeGrid( grid, $scope ); + + /** + * @ngdoc object + * @name ui.grid.treeView.grid:treeView + * + * @description Grid properties and functions added for treeView + */ + grid.treeView = {}; + + grid.registerRowsProcessor(service.adjustSorting, 60); + + /** + * @ngdoc object + * @name ui.grid.treeView.api:PublicApi + * + * @description Public Api for treeView feature + */ + var publicApi = { + events: { + treeView: { + } + }, + methods: { + treeView: { + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + + grid.api.registerMethodsFromObject(publicApi.methods); + + }, + + defaultGridOptions: function (gridOptions) { + // default option to true unless it was explicitly set to false + /** + * @ngdoc object + * @name ui.grid.treeView.api:GridOptions + * + * @description GridOptions for treeView feature, these are available to be + * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions} + * + * Many tree options are set on treeBase, make sure to look at that feature in + * conjunction with these options. + */ + + /** + * @ngdoc object + * @name enableTreeView + * @propertyOf ui.grid.treeView.api:GridOptions + * @description Enable row tree view for entire grid. + *
    Defaults to true + */ + gridOptions.enableTreeView = gridOptions.enableTreeView !== false; + + }, + + + /** + * @ngdoc function + * @name adjustSorting + * @methodOf ui.grid.treeBase.service:uiGridTreeBaseService + * @description Trees cannot be sorted the same as flat lists of rows - + * trees are sorted recursively within each level - so the children of each + * node are sorted, but not the full set of rows. + * + * To achieve this, we suppress the normal sorting by setting ignoreSort on + * each of the sort columns. When the treeBase rowsProcessor runs it will then + * unignore these, and will perform a recursive sort against the tree that it builds. + * + * @param {array} renderableRows the rows that we need to pass on through + * @returns {array} renderableRows that we passed on through + */ + adjustSorting: function( renderableRows ) { + var grid = this; + + grid.columns.forEach( function( column ) { + if ( column.sort ) { + column.sort.ignoreSort = true; + } + }); + + return renderableRows; + } + }; + + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.treeView.directive:uiGridTreeView + * @element div + * @restrict A + * + * @description Adds treeView features to grid + * + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.treeView']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name', enableCellEdit: true}, + {name: 'title', enableCellEdit: true} + ]; + + $scope.gridOptions = { columnDefs: $scope.columnDefs, data: $scope.data }; + }]); + + +
    +
    +
    +
    +
    + */ + module.directive('uiGridTreeView', ['uiGridTreeViewConstants', 'uiGridTreeViewService', '$templateCache', + function (uiGridTreeViewConstants, uiGridTreeViewService, $templateCache) { + return { + replace: true, + priority: 0, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + if (uiGridCtrl.grid.options.enableTreeView !== false) { + uiGridTreeViewService.initializeGrid(uiGridCtrl.grid, $scope); + } + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + + } + }; + } + }; + }]); +})(); diff --git a/src/ui-grid.tree-view.min.js b/src/ui-grid.tree-view.min.js new file mode 100644 index 0000000000..8b5b1905b8 --- /dev/null +++ b/src/ui-grid.tree-view.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var e=angular.module("ui.grid.treeView",["ui.grid","ui.grid.treeBase"]);e.constant("uiGridTreeViewConstants",{featureName:"treeView",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),e.service("uiGridTreeViewService",["$q","uiGridTreeViewConstants","uiGridTreeBaseConstants","uiGridTreeBaseService","gridUtil","GridRow","gridClassFactory","i18nService","uiGridConstants",function(e,i,r,n,t,o,a,s,u){var d={initializeGrid:function(e,i){n.initializeGrid(e,i),e.treeView={},e.registerRowsProcessor(d.adjustSorting,60);var r={treeView:{}},t={treeView:{}};e.api.registerEventsFromObject(r),e.api.registerMethodsFromObject(t)},defaultGridOptions:function(e){e.enableTreeView=!1!==e.enableTreeView},adjustSorting:function(e){return this.columns.forEach(function(e){e.sort&&(e.sort.ignoreSort=!0)}),e}};return d}]),e.directive("uiGridTreeView",["uiGridTreeViewConstants","uiGridTreeViewService","$templateCache",function(e,n,i){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,r,t){!1!==t.grid.options.enableTreeView&&n.initializeGrid(t.grid,e)},post:function(e,i,r,t){}}}}}])}(); \ No newline at end of file diff --git a/src/ui-grid.validate.js b/src/ui-grid.validate.js new file mode 100644 index 0000000000..db493b5613 --- /dev/null +++ b/src/ui-grid.validate.js @@ -0,0 +1,588 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + +(function () { + 'use strict'; + + /** + * @ngdoc overview + * @name ui.grid.validate + * @description + * + * # ui.grid.validate + * + * + * + * This module provides the ability to validate cells upon change. + * + * Design information: + * ------------------- + * + * Validation is not based on angularjs validation, since it would work only when editing the field. + * + * Instead it adds custom properties to any field considered as invalid. + * + *
    + *
    + * + *
    + */ + var module = angular.module('ui.grid.validate', ['ui.grid']); + + /** + * @ngdoc service + * @name ui.grid.validate.service:uiGridValidateService + * + * @description Services for validation features + */ + module.service('uiGridValidateService', ['$sce', '$q', '$http', 'i18nService', 'uiGridConstants', function ($sce, $q, $http, i18nService, uiGridConstants) { + + var service = { + + /** + * @ngdoc object + * @name validatorFactories + * @propertyOf ui.grid.validate.service:uiGridValidateService + * @description object containing all the factories used to validate data.
    + * These factories will be in the form
    + * ``` + * { + * validatorFactory: function(argument) { + * return function(newValue, oldValue, rowEntity, colDef) { + * return true || false || promise + * } + * }, + * messageFunction: function(argument) { + * return string + * } + * } + * ``` + * + * Promises should return true or false as result according to the result of validation. + */ + validatorFactories: {}, + + /** + * @ngdoc service + * @name setExternalFactoryFunction + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Adds a way to retrieve validators from an external service + *

    Validators from this external service have a higher priority than default + * ones + * @param {function} externalFactoryFunction a function that accepts name and argument to pass to a + * validator factory and that returns an object with the same properties as + * you can see in {@link ui.grid.validate.service:uiGridValidateService#properties_validatorFactories validatorFactories} + */ + setExternalFactoryFunction: function(externalFactoryFunction) { + service.externalFactoryFunction = externalFactoryFunction; + }, + + /** + * @ngdoc service + * @name clearExternalFactory + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Removes any link to external factory from this service + */ + clearExternalFactory: function() { + delete service.externalFactoryFunction; + }, + + /** + * @ngdoc service + * @name getValidatorFromExternalFactory + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Retrieves a validator by executing a validatorFactory + * stored in an external service. + * @param {string} name the name of the validator to retrieve + * @param {object} argument an argument to pass to the validator factory + */ + getValidatorFromExternalFactory: function(name, argument) { + return service.externalFactoryFunction(name, argument).validatorFactory(argument); + }, + + /** + * @ngdoc service + * @name getMessageFromExternalFactory + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Retrieves a message stored in an external service. + * @param {string} name the name of the validator + * @param {object} argument an argument to pass to the message function + */ + getMessageFromExternalFactory: function(name, argument) { + return service.externalFactoryFunction(name, argument).messageFunction(argument); + }, + + /** + * @ngdoc service + * @name setValidator + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Adds a new validator to the service + * @param {string} name the name of the validator, must be unique + * @param {function} validatorFactory a factory that return a validatorFunction + * @param {function} messageFunction a function that return the error message + */ + setValidator: function(name, validatorFactory, messageFunction) { + service.validatorFactories[name] = { + validatorFactory: validatorFactory, + messageFunction: messageFunction + }; + }, + + /** + * @ngdoc service + * @name getValidator + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Returns a validator registered to the service + * or retrieved from the external factory + * @param {string} name the name of the validator to retrieve + * @param {object} argument an argument to pass to the validator factory + * @returns {object} the validator function + */ + getValidator: function(name, argument) { + if (service.externalFactoryFunction) { + var validator = service.getValidatorFromExternalFactory(name, argument); + if (validator) { + return validator; + } + } + if (!service.validatorFactories[name]) { + throw ("Invalid validator name: " + name); + } + return service.validatorFactories[name].validatorFactory(argument); + }, + + /** + * @ngdoc service + * @name getMessage + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Returns the error message related to the validator + * @param {string} name the name of the validator + * @param {object} argument an argument to pass to the message function + * @returns {string} the error message related to the validator + */ + getMessage: function(name, argument) { + if (service.externalFactoryFunction) { + var message = service.getMessageFromExternalFactory(name, argument); + if (message) { + return message; + } + } + return service.validatorFactories[name].messageFunction(argument); + }, + + /** + * @ngdoc service + * @name isInvalid + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Returns true if the cell (identified by rowEntity, colDef) is invalid + * @param {object} rowEntity the row entity of the cell + * @param {object} colDef the colDef of the cell + * @returns {boolean} true if the cell is invalid + */ + isInvalid: function (rowEntity, colDef) { + return rowEntity['$$invalid'+colDef.name]; + }, + + /** + * @ngdoc service + * @name setInvalid + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Makes the cell invalid by adding the proper field to the entity + * @param {object} rowEntity the row entity of the cell + * @param {object} colDef the colDef of the cell + */ + setInvalid: function (rowEntity, colDef) { + rowEntity['$$invalid'+colDef.name] = true; + }, + + /** + * @ngdoc service + * @name setValid + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Makes the cell valid by removing the proper error field from the entity + * @param {object} rowEntity the row entity of the cell + * @param {object} colDef the colDef of the cell + */ + setValid: function (rowEntity, colDef) { + delete rowEntity['$$invalid'+colDef.name]; + }, + + /** + * @ngdoc service + * @name setError + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Adds the proper error to the entity errors field + * @param {object} rowEntity the row entity of the cell + * @param {object} colDef the colDef of the cell + * @param {string} validatorName the name of the validator that is failing + */ + setError: function(rowEntity, colDef, validatorName) { + if (!rowEntity['$$errors'+colDef.name]) { + rowEntity['$$errors'+colDef.name] = {}; + } + rowEntity['$$errors'+colDef.name][validatorName] = true; + }, + + /** + * @ngdoc service + * @name clearError + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Removes the proper error from the entity errors field + * @param {object} rowEntity the row entity of the cell + * @param {object} colDef the colDef of the cell + * @param {string} validatorName the name of the validator that is failing + */ + clearError: function(rowEntity, colDef, validatorName) { + if (!rowEntity['$$errors'+colDef.name]) { + return; + } + if (validatorName in rowEntity['$$errors'+colDef.name]) { + delete rowEntity['$$errors'+colDef.name][validatorName]; + } + }, + + /** + * @ngdoc function + * @name getErrorMessages + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description returns an array of i18n-ed error messages. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {array} An array of strings containing all the error messages for the cell + */ + getErrorMessages: function(rowEntity, colDef) { + var errors = []; + + if (!rowEntity['$$errors'+colDef.name] || Object.keys(rowEntity['$$errors'+colDef.name]).length === 0) { + return errors; + } + + Object.keys(rowEntity['$$errors'+colDef.name]).sort().forEach(function(validatorName) { + errors.push(service.getMessage(validatorName, colDef.validators[validatorName])); + }); + + return errors; + }, + + /** + * @ngdoc function + * @name getFormattedErrors + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description returns the error i18n-ed and formatted in html to be shown inside the page. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {object} An object that can be used in a template (like a cellTemplate) to display the + * message inside the page (i.e. inside a div) + */ + getFormattedErrors: function(rowEntity, colDef) { + var msgString = "", + errors = service.getErrorMessages(rowEntity, colDef); + + if (!errors.length) { + return; + } + + errors.forEach(function(errorMsg) { + msgString += errorMsg + "
    "; + }); + + return $sce.trustAsHtml('

    ' + i18nService.getSafeText('validate.error') + '

    ' + msgString ); + }, + + /** + * @ngdoc function + * @name getTitleFormattedErrors + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html + * title attribute. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {object} An object that can be used in a template (like a cellTemplate) to display the + * message inside an html title attribute + */ + getTitleFormattedErrors: function(rowEntity, colDef) { + var newLine = "\n", + msgString = "", + errors = service.getErrorMessages(rowEntity, colDef); + + if (!errors.length) { + return; + } + + errors.forEach(function(errorMsg) { + msgString += errorMsg + newLine; + }); + + return $sce.trustAsHtml(i18nService.getSafeText('validate.error') + newLine + msgString); + }, + + /** + * @ngdoc function + * @name getTitleFormattedErrors + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description Executes all validators on a cell (identified by row entity and column definition) and sets or clears errors + * @param {object} rowEntity the row entity of the cell we want to run the validators on + * @param {object} colDef the column definition of the cell we want to run the validators on + * @param {object} newValue the value the user just entered + * @param {object} oldValue the value the field had before + */ + runValidators: function(rowEntity, colDef, newValue, oldValue, grid) { + if (newValue === oldValue) { + // If the value has not changed we perform no validation + return; + } + + if (typeof(colDef.name) === 'undefined' || !colDef.name) { + throw new Error('colDef.name is required to perform validation'); + } + + service.setValid(rowEntity, colDef); + + var validateClosureFactory = function(rowEntity, colDef, validatorName) { + return function(value) { + if (!value) { + service.setInvalid(rowEntity, colDef); + service.setError(rowEntity, colDef, validatorName); + if (grid) { + grid.api.validate.raise.validationFailed(rowEntity, colDef, newValue, oldValue); + } + } + }; + }; + + var promises = []; + + for (var validatorName in colDef.validators) { + service.clearError(rowEntity, colDef, validatorName); + var validatorFunction = service.getValidator(validatorName, colDef.validators[validatorName]); + + // We pass the arguments as oldValue, newValue so they are in the same order + // as ng-model validators (modelValue, viewValue) + var promise = $q.when(validatorFunction(oldValue, newValue, rowEntity, colDef)) + .then(validateClosureFactory(rowEntity, colDef, validatorName)); + + promises.push(promise); + } + + return $q.all(promises); + }, + + /** + * @ngdoc function + * @name createDefaultValidators + * @methodOf ui.grid.validate.service:uiGridValidateService + * @description adds the basic validators to the list of service validators + */ + createDefaultValidators: function() { + service.setValidator('minLength', function (argument) { + return function (oldValue, newValue) { + if (newValue === undefined || newValue === null || newValue === '') { + return true; + } + return newValue.length >= argument; + }; + }, function(argument) { + return i18nService.getSafeText('validate.minLength').replace('THRESHOLD', argument); + }); + + service.setValidator('maxLength', function (argument) { + return function (oldValue, newValue) { + if (newValue === undefined || newValue === null || newValue === '') { + return true; + } + return newValue.length <= argument; + }; + }, function(threshold) { + return i18nService.getSafeText('validate.maxLength').replace('THRESHOLD', threshold); + }); + + service.setValidator('required', function (argument) { + return function (oldValue, newValue) { + if (argument) { + return !(newValue === undefined || newValue === null || newValue === ''); + } + return true; + }; + }, function() { + return i18nService.getSafeText('validate.required'); + }); + }, + + initializeGrid: function (scope, grid) { + grid.validate = { + + isInvalid: service.isInvalid, + + getErrorMessages: service.getErrorMessages, + + getFormattedErrors: service.getFormattedErrors, + + getTitleFormattedErrors: service.getTitleFormattedErrors, + + runValidators: service.runValidators + }; + + /** + * @ngdoc object + * @name ui.grid.validate.api:PublicApi + * + * @description Public Api for validation feature + */ + var publicApi = { + events: { + validate: { + /** + * @ngdoc event + * @name validationFailed + * @eventOf ui.grid.validate.api:PublicApi + * @description raised when one or more failure happened during validation + *
    +               *      gridApi.validate.on.validationFailed(scope, function(rowEntity, colDef, newValue, oldValue){...})
    +               * 
    + * @param {object} rowEntity the options.data element whose validation failed + * @param {object} colDef the column whose validation failed + * @param {object} newValue new value + * @param {object} oldValue old value + */ + validationFailed: function (rowEntity, colDef, newValue, oldValue) { + } + } + }, + methods: { + validate: { + /** + * @ngdoc function + * @name isInvalid + * @methodOf ui.grid.validate.api:PublicApi + * @description checks if a cell (identified by rowEntity, colDef) is invalid + * @param {object} rowEntity gridOptions.data[] array instance we want to check + * @param {object} colDef the column whose errors we want to check + * @returns {boolean} true if the cell value is not valid + */ + isInvalid: function(rowEntity, colDef) { + return grid.validate.isInvalid(rowEntity, colDef); + }, + /** + * @ngdoc function + * @name getErrorMessages + * @methodOf ui.grid.validate.api:PublicApi + * @description returns an array of i18n-ed error messages. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {array} An array of strings containing all the error messages for the cell + */ + getErrorMessages: function (rowEntity, colDef) { + return grid.validate.getErrorMessages(rowEntity, colDef); + }, + /** + * @ngdoc function + * @name getFormattedErrors + * @methodOf ui.grid.validate.api:PublicApi + * @description returns the error i18n-ed and formatted in html to be shown inside the page. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {object} An object that can be used in a template (like a cellTemplate) to display the + * message inside the page (i.e. inside a div) + */ + getFormattedErrors: function (rowEntity, colDef) { + return grid.validate.getFormattedErrors(rowEntity, colDef); + }, + /** + * @ngdoc function + * @name getTitleFormattedErrors + * @methodOf ui.grid.validate.api:PublicApi + * @description returns the error i18n-ed and formatted in javaScript to be shown inside an html + * title attribute. + * @param {object} rowEntity gridOptions.data[] array instance whose errors we are looking for + * @param {object} colDef the column whose errors we are looking for + * @returns {object} An object that can be used in a template (like a cellTemplate) to display the + * message inside an html title attribute + */ + getTitleFormattedErrors: function (rowEntity, colDef) { + return grid.validate.getTitleFormattedErrors(rowEntity, colDef); + } + } + } + }; + + grid.api.registerEventsFromObject(publicApi.events); + grid.api.registerMethodsFromObject(publicApi.methods); + + if (grid.edit) { + grid.api.edit.on.afterCellEdit(scope, function(rowEntity, colDef, newValue, oldValue) { + grid.validate.runValidators(rowEntity, colDef, newValue, oldValue, grid); + }); + } + + service.createDefaultValidators(); + } + }; + + return service; + }]); + + /** + * @ngdoc directive + * @name ui.grid.validate.directive:uiGridValidate + * @element div + * @restrict A + * @description Adds validating features to the ui-grid directive. + * @example + + + var app = angular.module('app', ['ui.grid', 'ui.grid.edit', 'ui.grid.validate']); + + app.controller('MainCtrl', ['$scope', function ($scope) { + $scope.data = [ + { name: 'Bob', title: 'CEO' }, + { name: 'Frank', title: 'Lowly Developer' } + ]; + + $scope.columnDefs = [ + {name: 'name', enableCellEdit: true, validators: {minLength: 3, maxLength: 9}, cellTemplate: 'ui-grid/cellTitleValidator'}, + {name: 'title', enableCellEdit: true, validators: {required: true}, cellTemplate: 'ui-grid/cellTitleValidator'} + ]; + }]); + + +
    +
    +
    +
    +
    + */ + + module.directive('uiGridValidate', ['gridUtil', 'uiGridValidateService', function (gridUtil, uiGridValidateService) { + return { + priority: 0, + replace: true, + require: '^uiGrid', + scope: false, + compile: function () { + return { + pre: function ($scope, $elm, $attrs, uiGridCtrl) { + uiGridValidateService.initializeGrid($scope, uiGridCtrl.grid); + }, + post: function ($scope, $elm, $attrs, uiGridCtrl) { + } + }; + } + }; + }]); +})(); + +angular.module('ui.grid.validate').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('ui-grid/cellTitleValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + + + $templateCache.put('ui-grid/cellTooltipValidator', + "
    {{COL_FIELD CUSTOM_FILTERS}}
    " + ); + +}]); diff --git a/src/ui-grid.validate.min.js b/src/ui-grid.validate.min.js new file mode 100644 index 0000000000..3ecae4f725 --- /dev/null +++ b/src/ui-grid.validate.min.js @@ -0,0 +1,7 @@ +/*! + * ui-grid - v4.11.0 - 2021-08-12 + * Copyright (c) 2021 ; License: MIT + */ + + +!function(){"use strict";var t=angular.module("ui.grid.validate",["ui.grid"]);t.service("uiGridValidateService",["$sce","$q","$http","i18nService","uiGridConstants",function(i,c,t,n,r){var u={validatorFactories:{},setExternalFactoryFunction:function(t){u.externalFactoryFunction=t},clearExternalFactory:function(){delete u.externalFactoryFunction},getValidatorFromExternalFactory:function(t,r){return u.externalFactoryFunction(t,r).validatorFactory(r)},getMessageFromExternalFactory:function(t,r){return u.externalFactoryFunction(t,r).messageFunction(r)},setValidator:function(t,r,e){u.validatorFactories[t]={validatorFactory:r,messageFunction:e}},getValidator:function(t,r){if(u.externalFactoryFunction){var e=u.getValidatorFromExternalFactory(t,r);if(e)return e}if(!u.validatorFactories[t])throw"Invalid validator name: "+t;return u.validatorFactories[t].validatorFactory(r)},getMessage:function(t,r){if(u.externalFactoryFunction){var e=u.getMessageFromExternalFactory(t,r);if(e)return e}return u.validatorFactories[t].messageFunction(r)},isInvalid:function(t,r){return t["$$invalid"+r.name]},setInvalid:function(t,r){t["$$invalid"+r.name]=!0},setValid:function(t,r){delete t["$$invalid"+r.name]},setError:function(t,r,e){t["$$errors"+r.name]||(t["$$errors"+r.name]={}),t["$$errors"+r.name][e]=!0},clearError:function(t,r,e){t["$$errors"+r.name]&&e in t["$$errors"+r.name]&&delete t["$$errors"+r.name][e]},getErrorMessages:function(t,r){var e=[];return t["$$errors"+r.name]&&0!==Object.keys(t["$$errors"+r.name]).length&&Object.keys(t["$$errors"+r.name]).sort().forEach(function(t){e.push(u.getMessage(t,r.validators[t]))}),e},getFormattedErrors:function(t,r){var e="",a=u.getErrorMessages(t,r);if(a.length)return a.forEach(function(t){e+=t+"
    "}),i.trustAsHtml("

    "+n.getSafeText("validate.error")+"

    "+e)},getTitleFormattedErrors:function(t,r){var e="",a=u.getErrorMessages(t,r);if(a.length)return a.forEach(function(t){e+=t+"\n"}),i.trustAsHtml(n.getSafeText("validate.error")+"\n"+e)},runValidators:function(t,r,i,n,o){if(i!==n){if(void 0===r.name||!r.name)throw new Error("colDef.name is required to perform validation");u.setValid(t,r);var e=function(r,e,a){return function(t){t||(u.setInvalid(r,e),u.setError(r,e,a),o&&o.api.validate.raise.validationFailed(r,e,i,n))}},a=[];for(var l in r.validators){u.clearError(t,r,l);var d=u.getValidator(l,r.validators[l]),s=c.when(d(n,i,t,r)).then(e(t,r,l));a.push(s)}return c.all(a)}},createDefaultValidators:function(){u.setValidator("minLength",function(e){return function(t,r){return null==r||""===r||r.length>=e}},function(t){return n.getSafeText("validate.minLength").replace("THRESHOLD",t)}),u.setValidator("maxLength",function(e){return function(t,r){return null==r||""===r||r.length<=e}},function(t){return n.getSafeText("validate.maxLength").replace("THRESHOLD",t)}),u.setValidator("required",function(e){return function(t,r){return!e||!(null==r||""===r)}},function(){return n.getSafeText("validate.required")})},initializeGrid:function(t,i){i.validate={isInvalid:u.isInvalid,getErrorMessages:u.getErrorMessages,getFormattedErrors:u.getFormattedErrors,getTitleFormattedErrors:u.getTitleFormattedErrors,runValidators:u.runValidators};var r={events:{validate:{validationFailed:function(t,r,e,a){}}},methods:{validate:{isInvalid:function(t,r){return i.validate.isInvalid(t,r)},getErrorMessages:function(t,r){return i.validate.getErrorMessages(t,r)},getFormattedErrors:function(t,r){return i.validate.getFormattedErrors(t,r)},getTitleFormattedErrors:function(t,r){return i.validate.getTitleFormattedErrors(t,r)}}}};i.api.registerEventsFromObject(r.events),i.api.registerMethodsFromObject(r.methods),i.edit&&i.api.edit.on.afterCellEdit(t,function(t,r,e,a){i.validate.runValidators(t,r,e,a,i)}),u.createDefaultValidators()}};return u}]),t.directive("uiGridValidate",["gridUtil","uiGridValidateService",function(t,i){return{priority:0,replace:!0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(t,r,e,a){i.initializeGrid(t,a.grid)},post:function(t,r,e,a){}}}}}])}(),angular.module("ui.grid.validate").run(["$templateCache",function(t){"use strict";t.put("ui-grid/cellTitleValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    '),t.put("ui-grid/cellTooltipValidator",'
    {{COL_FIELD CUSTOM_FILTERS}}
    ')}]); \ No newline at end of file