Class: WidgetList::List
- Includes:
- ActionView::Helpers::NumberHelper, ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/widget_list.rb
Instance Attribute Summary collapse
-
#isAdministrating ⇒ Object
Returns the value of attribute isAdministrating.
Class Method Summary collapse
- .build_drill_down(*params) ⇒ Object
-
.build_list(list_parms) ⇒ Object
build_list controls a default AJAX/Export and full HTML return output in some cases you should copy and paste this logic for custom scenarios in your controller, but in most cases, this is okay.
- .build_search_button_click(list_parms) ⇒ Object
-
.checkbox_helper(list_parms, primary_key) ⇒ Object
checkbox_helper just builds the proper Hashes to setup a checkbox widget row it assumes you have a fake column called ” AS checkbox to fill in with the widget_check.
- .clear_check_box_session(name = '') ⇒ Object
- .concat_inner(primary) ⇒ Object
- .concat_outer(primary) ⇒ Object
- .concat_string(primary) ⇒ Object
- .determine_db_type(db_type) ⇒ Object
- .double_quote(primary) ⇒ Object
- .drill_down_back(list_name = '') ⇒ Object
- .get_db_type(primary = true) ⇒ Object
- .get_defaults ⇒ Object
- .get_filter_and_drilldown(listId) ⇒ Object
- .get_group_by_selection(list_parms) ⇒ Object
- .get_sequel(primary = true) ⇒ Object
- .group_by_max_each_field(list_parms, group_by_filter) ⇒ Object
- .init_config ⇒ Object
- .is_sequel(primary) ⇒ Object
- .load_widget_list_database_yml ⇒ Object
- .load_widget_list_yml ⇒ Object
- .mysql_to_mongo_predicate(predicate = '=', value = '', build_mongo_expression_hash = false) ⇒ Object
- .parse_inputs_for_mongo_predicates(active_record_model, field, predicate, value_original) ⇒ Object
- .where(list_parms, field, value, predicate = '=') ⇒ Object
Instance Method Summary collapse
- #ajax_maintain_checks ⇒ Object
- #auto_column_name(name = '') ⇒ Object
- #build_column_button(column, j) ⇒ Object
- #build_column_input(column, row = '') ⇒ Object
- #build_column_link(column, j) ⇒ Object
- #build_headers ⇒ Object
- #build_pagination ⇒ Object
- #build_rows ⇒ Object
- #build_statement ⇒ Object
- #build_summary_row ⇒ Object
- #cast_col ⇒ Object
- #clear_search_session(all = false) ⇒ Object
- #clear_sort_get_vars ⇒ Object
- #clear_sql_session(all = false) ⇒ Object
- #connect ⇒ Object
- #generate_error_output(ex = '') ⇒ Object
- #generate_limits ⇒ Object
- #get_database ⇒ Object
- #get_db_type(primary = true) ⇒ Object
- #get_grouping_functions ⇒ Object
- #get_header_pieces ⇒ Object
- #get_header_px_value ⇒ Object
- #get_radius_value ⇒ Object
- #get_shadow_inset_value ⇒ Object
- #get_shadow_spread_value ⇒ Object
- #get_total_records ⇒ Object
- #get_view ⇒ Object
-
#initialize(list = {}) ⇒ List
constructor
A new instance of List.
-
#render(results = {}) ⇒ Object
pass results of $DATABASE.final_results after running a _select query.
- #skip_column(fieldName) ⇒ Object
- #strip_aliases(name = '') ⇒ Object
- #tick_field ⇒ Object
Constructor Details
#initialize(list = {}) ⇒ List
Returns a new instance of List.
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 |
# File 'lib/widget_list.rb', line 1368 def initialize(list={}) # Defaults for all configs # See https://github.com/davidrenne/widget_list/blob/master/README.md#feature-configurations @items = WidgetList::List::get_defaults() if list.empty? || list == @items @isAdministrating = true return else @isAdministrating = false end @csv = [] @csv << [] @totalRowCount= 0 @totalPages = 0 @fixHtmlLinksReplace = {} @sequence = 1 @totalRows = 0 @totalPage = 0 @listSortNext = 'ASC' @filter = '' @listFilter = '' @fieldList = [] @templateFill = {} @results = {} @headerPieces = {} ac = ActionController::Base.new() #the main template and outer shell @items.deep_merge!({ 'template' => ac.render_to_string(:partial => 'widget_list/list_partials/outer_shell') }) @items.deep_merge!({ 'row' => ac.render_to_string(:partial => 'widget_list/list_partials/row') }) @items.deep_merge!({ 'list_description' => ac.render_to_string(:partial => 'widget_list/list_partials/list_description') }) @items.deep_merge!({ 'col' => ac.render_to_string(:partial => 'widget_list/list_partials/col') }) @items.deep_merge!({ 'templateSequence' => ac.render_to_string(:partial => 'widget_list/list_partials/sequence') }) #Sorting # @items.deep_merge!({ 'templateSortColumn' => ac.render_to_string(:partial => 'widget_list/list_partials/sort_column') }) @items.deep_merge!({ 'templateNoSortColumn' => ac.render_to_string(:partial => 'widget_list/list_partials/no_sort_column') }) #Pagintion # @items.deep_merge!({ 'template_pagination_wrapper' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_wrapper') }) @items.deep_merge!({ 'template_pagination_next_active' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_next_active') }) @items.deep_merge!({ 'template_pagination_next_disabled' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_next_disabled') }) @items.deep_merge!({ 'template_pagination_previous_active' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_previous_active') }) @items.deep_merge!({ 'template_pagination_previous_disabled' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_previous_disabled') }) @items.deep_merge!({ 'template_pagination_jump_active' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_jump_active') }) @items.deep_merge!({ 'template_pagination_jump_unactive' => ac.render_to_string(:partial => 'widget_list/list_partials/pagination_jump_unactive') }) if list['view'].class.name == 'ActiveRecord::Relation' tag_fields = '<!--FIELDS_PLAIN-->' else #In a case where someone passes a SQL query raw with Sequel, we need to support fieldFunction's like action buttons which wouldnt be in your query, so use FIELDS to build entire query tag_fields = '<!--FIELDS-->' end @items.deep_merge!({ 'statement' => {'select'=> {'view' =>'SELECT ' + tag_fields + ' FROM <!--SOURCE--> <!--WHERE--> <!--GROUPBY--> <!--ORDERBY--> <!--LIMIT-->'} } }) @items.deep_merge!({ 'statement' => {'count'=> {'view' => 'SELECT count(1) total FROM <!--VIEW--> <!--WHERE--> <!--GROUPBY-->'} } }) #inject site wide configs before list specific configs if a helper exists if defined?(WidgetListHelper) == 'constant' && WidgetListHelper::SiteDefaults.class == Class && WidgetListHelper::SiteDefaults.respond_to?('get_site_widget_list_defaults') @items = WidgetList::Widgets::populate_items(WidgetListHelper::SiteDefaults::() ,@items) end if defined?(WidgetListThemeHelper) == 'constant' && WidgetListThemeHelper::ThemeDefaults.class == Class && WidgetListThemeHelper::ThemeDefaults.respond_to?('get_theme_widget_list_defaults') @items = WidgetList::Widgets::populate_items(WidgetListThemeHelper::ThemeDefaults::() ,@items) end @items = WidgetList::Widgets::populate_items(list,@items) # If ransack is used if @items['view'].class.name == 'ActiveRecord::Relation' && @items['ransackSearch'].class.name == 'Ransack::Search' @items['ransackSearch'].build_condition if @items['ransackSearch'].conditions.empty? if @items['listSearchForm'].empty? # # if no one passed a listSearchForm inject a default one to show the ransack form # fill = { '<!--BUTTON_SEARCH-->' => WidgetList::Widgets::('Search', {'onclick' => WidgetList::List::(@items), 'innerClass' => @items['defaultButtonClass'] }), '<!--BUTTON_CLOSE-->' => "HideAdvancedSearch(this)" } @items['listSearchForm'] = WidgetList::Utils::fill( fill , ac.render_to_string(:partial => 'widget_list/ransack_widget_list_advanced_search') ) end end # I have several different styles for borders, but using borders Everywhere will setup everything with one call if @items['bordersEverywhere?'] @items['borderedColumns'] = @items['borderHeadFoot'] = @items['borderedRows'] = true @items['borderColumnStyle'] = @items['borderRowStyle'] = @items['headFootBorderStyle'] = @items['tableBorder'] = @items['borderEverywhere'] end # current_db is a flag of the last known primary or secondary YML used or defaulted when running a list @current_db_selection = @items['database'] if get_database.db_type == 'oracle' @items.deep_merge!({'statement' => {'count'=> {'view' => ' SELECT count(1) total FROM <!--VIEW--> ' + ((@items['groupBy'].empty? && !@active_record_model) ? '<!--WHERE--> <!--GROUPBY-->' : '' ) } } }) @items.deep_merge!({'statement' => {'select'=> {'view' => 'SELECT <!--FIELDS_PLAIN--> FROM ( SELECT a.*, DENSE_RANK() over (<!--ORDERBY-->) rn FROM ( SELECT ' + ( (!get_view().include?('(')) ? '<!--SOURCE-->' : get_view().strip.split(" ").last ) + '.* FROM <!--SOURCE--> ) a ' + ((@items['groupBy'].empty?) ? '<!--WHERE-->' : '') + ' <!--ORDERBY--> ) <!--LIMIT--> ' + ((!@active_record_model) ? '<!--GROUPBY-->' : '') } } }) end if $_REQUEST.key?('searchClear') clear_search_session() end begin @isJumpingList = false #Ajax ListJump if ! $_REQUEST.empty? if $_REQUEST.key?('LIST_FILTER_ALL') && !$_REQUEST['LIST_FILTER_ALL'].empty? @items['LIST_FILTER_ALL'] = $_REQUEST['LIST_FILTER_ALL'] @isJumpingList = true end if $_REQUEST.key?('LIST_COL_SORT') && !$_REQUEST['LIST_COL_SORT'].empty? @items['LIST_COL_SORT'] = $_REQUEST['LIST_COL_SORT'] @isJumpingList = true end if $_REQUEST.key?('LIST_COL_SORT_ORDER') && !$_REQUEST['LIST_COL_SORT_ORDER'].empty? @items['LIST_COL_SORT_ORDER'] = $_REQUEST['LIST_COL_SORT_ORDER'] @isJumpingList = true end if $_REQUEST.key?('LIST_SEQUENCE') && !$_REQUEST['LIST_SEQUENCE'].empty? @items['LIST_SEQUENCE'] = $_REQUEST['LIST_SEQUENCE'].to_i @isJumpingList = true end if $_REQUEST.key?('ROW_LIMIT') && !$_REQUEST['ROW_LIMIT'].empty? @items['ROW_LIMIT'] = $_REQUEST['ROW_LIMIT'] @isJumpingList = true if @items['showPagination'] $_SESSION['pageDisplayLimit'] = $_REQUEST['ROW_LIMIT'] $_SESSION.deep_merge!({'ROW_LIMIT' => { @items['name'] => $_REQUEST['ROW_LIMIT']} }) end end clear_sort_get_vars() if $_REQUEST.key?('list_action') && $_REQUEST['list_action'] == 'ajax_widgetlist_checks' && @items['storeSessionChecks'] ajax_maintain_checks() end end @items['groupByClick'] = WidgetList::Utils::fill({'<!--NAME-->' => @items['name']}, @items['groupByClickDefault'] + @items['groupByClick']) begin if @items['searchClear'] || @items['searchClearAll'] clear_search_session(@items.key?('searchClearAll')) end matchesCurrentList = $_REQUEST.key?('BUTTON_VALUE') && $_REQUEST['BUTTON_VALUE'] == @items['buttonVal'] isSearchRequest = $_REQUEST.key?('search_filter') && $_REQUEST['search_filter'] != 'undefined' templateCustomSearch = !@items['templateFilter'].empty? # if you define templateFilter WidgetList will not attempt to build a where clause with search # # Search restore # if !isSearchRequest && !$_SESSION.empty? && $_SESSION.key?('SEARCH_FILTER') && $_SESSION['SEARCH_FILTER'].key?(@items['name']) && @items['searchSession'] isSearchRestore = true end if (isSearchRequest && matchesCurrentList && !templateCustomSearch && @items['showSearch']) || isSearchRestore get_view() if $is_mongo # call function to fill in @active_record_model if !isSearchRestore $_SESSION.deep_merge!({'SEARCH_FILTER' => { @items['name'] => $_REQUEST['search_filter']} }) searchFilter = $_REQUEST['search_filter'].strip_or_self() else searchFilter = $_SESSION['SEARCH_FILTER'][@items['name']] end if ! searchFilter.empty? if ! @items['filter'].empty? && @items['filter'].class.name != 'Array' # convert string to array filter filterString = @items['filter'] @items['filter'] = [] unless $is_mongo @items['filter'] << filterString unless $is_mongo end fieldsToSearch = @items['fields'].dup if @items['fieldsHidden'].class.name == 'Array' @items['fieldsHidden'].each { |columnPivot| fieldsToSearch[columnPivot] = strip_aliases(columnPivot) } elsif @items['fieldsHidden'].class.name == 'Hash' @items['fieldsHidden'].each { |columnPivot| fieldsToSearch[columnPivot[0]] = strip_aliases(columnPivot[0]) } end fieldsToSearch.delete('cnt') if fieldsToSearch.key?('cnt') searchCriteria = searchFilter.strip_or_self() searchSQL = [] numericSearch = false # # Comma delimited search # if searchFilter.include?(',') #It is either a CSV or a comma inside the search string # criteriaTmp = searchFilter.split_it(',') #Assumed a CSV of numeric ids # isNumeric = true criteriaTmp.each_with_index { |value, key| if !value.empty? criteriaTmp[key] = value.strip_or_self() if !criteriaTmp[key].nil? && ! criteriaTmp[key].empty? if ! WidgetList::Utils::numeric?(criteriaTmp[key]) isNumeric = false end else criteriaTmp.delete(key) end end } if isNumeric numericSearch = true if @items['searchIdCol'].class.name == 'Array' @items['searchIdCol'].each { |searchIdCol| if(fieldsToSearch.key?(searchIdCol)) searchSQL << tick_field() + searchIdCol + tick_field() + " IN(" + searchFilter + ")" if $is_mongo criteriaTmp.each_with_index { |value, key| if !@items['groupBy'].empty? @items['filter'] << searchIdCol @items['predicate']<< '=' @items['bindVars'] << value end @active_record_model = @active_record_model.where('$or' => [{searchIdCol=>value}]) if @items['groupBy'].empty? } end end } if !searchSQL.empty? # # Assemble Numeric Filter # @items['filter'] << "(" + searchSQL.join(' OR ') + ")" unless $is_mongo end elsif @items['fields'].key?(@items['searchIdCol']) numericSearch = true @items['filter'] << tick_field() + "#{@items['searchIdCol']}" + tick_field() + " IN(" + criteriaTmp.join(',') + ")" unless $is_mongo if $is_mongo criteriaTmp.each_with_index { |value, key| if !@items['groupBy'].empty? @items['filter'] << @items['searchIdCol'] @items['predicate']<< '=' @items['bindVars'] << value end @active_record_model = @active_record_model.where('$or' => [{@items['searchIdCol']=>value}]) if @items['groupBy'].empty? } end end end elsif @items['searchIdCol'].class.name == 'Array' if WidgetList::Utils::numeric?(searchFilter) && ! searchFilter.include?('.') numericSearch = true @items['searchIdCol'].each { |searchIdCol| if fieldsToSearch.key?(searchIdCol) searchSQL << tick_field() + "#{searchIdCol}" + tick_field() + " IN(#{searchFilter})" if $is_mongo if !@items['groupBy'].empty? @items['filter'] << searchIdCol @items['predicate']<< '=' @items['bindVars'] << searchFilter end @active_record_model = @active_record_model.where('$or' => [{searchIdCol=>searchFilter}]) if @items['groupBy'].empty? end end } if !searchSQL.empty? # # Assemble Numeric Filter # @items['filter'] << "(" + searchSQL.join(' OR ') + ")" unless $is_mongo end end elsif WidgetList::Utils::numeric?(searchFilter) && ! searchFilter.include?('.') && @items['fields'].key?(@items['searchIdCol']) numericSearch = true @items['filter'] << tick_field() + "#{@items['searchIdCol']}" + tick_field() + " IN(" + searchFilter + ")" unless $is_mongo if $is_mongo if !@items['groupBy'].empty? @items['filter'] << @items['searchIdCol'] @items['predicate']<< '=' @items['bindVars'] << searchFilter end @active_record_model = @active_record_model.where('$or' => [{@items['searchIdCol']=>searchFilter}]) if @items['groupBy'].empty? end end # If it is not an id or a list of ids then it is assumed a string search if !numericSearch fieldValues = {} fieldsToSearch.each { |fieldName,fieldTitle| fieldName = strip_aliases(fieldName) # new lodgette. if fieldFunction exists, find all matches and skip them if @items['fieldFunction'].key?(fieldName) if get_database.db_type == 'oracle' theField = fieldName else theField = @items['fieldFunction'][fieldName] + cast_col() end else theField = tick_field() + "#{fieldName}" + cast_col() + tick_field() end skip = false skip = skip_column(fieldName) #buttons must ALWAYS BE ON THE RIGHT SIDE IN ORDER FOR THIS NOT TO SEARCH A NON-EXISTENT COLUMN (used to be hard coded to 'features' as a column to remove) if skip next end #Search only specified fields. This can involve a dynamic field list from an advanced search form # if ! @items['searchFieldsIn'].empty? # # If it exists in either key or value # if ! @items['searchFieldsIn'].key?(fieldName) && ! @items['searchFieldsIn'].include?(fieldName) next end elsif ! @items['searchFieldsOut'].empty? if @items['searchFieldsOut'].key?(fieldName) || @items['searchFieldsOut'].include?(fieldName) next end end #todo - escape bind variables using Sequel searchSQL << theField + " LIKE '%" + searchCriteria + "%'" fieldValues[theField] = searchCriteria if $is_mongo if !@items['groupBy'].empty? @items['filter'] << fieldName @items['predicate']<< '=' @items['bindVars'] << searchCriteria end if @items['groupBy'].empty? && (@active_record_model.respond_to?(:serializers) && ['DateTime','Time','Date'].include?(@active_record_model.serializers[fieldName].type.to_s)) == false if searchCriteria.include?(',') criteriaTmp = searchCriteria.split_it(',') criteriaTmp.each_with_index { |value, key| if !value.empty? @active_record_model = @active_record_model.where('$or' => [{fieldName=>value.strip_or_self()}]) end } else @active_record_model = @active_record_model.where('$or' => [{fieldName=>searchCriteria}]) end end end } # # Assemble String Filter # if(! searchSQL.empty?) @items['filter'] << "(" + searchSQL.join(' OR ') + ")" unless $is_mongo end end end end rescue Exception => e @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output(e) + @items['noDataMessage'] + '</div></td></tr>' end if !$_REQUEST.key?('BUTTON_VALUE') #Initialize page load/Session stuff whe list first loads # WidgetList::List::clear_check_box_session(@items['name']) end if ! @items.key?('templateHeader') @items['templateHeader'] = '' end #Set a list title if it exists # if ! $_REQUEST.key?('BUTTON_VALUE') && !@items['title'].empty? @items['templateHeader'] = ' <h1 style="font-size:' + get_header_px_value() + ';"><!--TITLE--></h1><div class="horizontal_rule"></div> <!--FILTER_HEADER--> ' elsif !$_REQUEST.key?('BUTTON_VALUE') # Only if not in ajax would we want to output the filter header # @items['templateHeader'] = '<!--FILTER_HEADER-->' end # Build the filter (If any) # # todo - unit test filter if !@items['filter'].empty? && @items['filter'].class.name == 'Array' @filter = @items['filter'].join(' AND ') elsif !@items['filter'].empty? && @items['filter'].class.name == 'String' @filter = @items['filter'] end #Sorting # if !@items['LIST_COL_SORT'].empty? @items['LIST_SEQUENCE'] = 1 end if @items['LIST_SEQUENCE'].class.name == 'Fixnum' && @items['LIST_SEQUENCE'] > 0 @sequence = @items['LIST_SEQUENCE'].to_i end if ! @items['ROW_LIMIT'].empty? @items['rowLimit'] = @items['ROW_LIMIT'].to_i end if $_SESSION.key?('ROW_LIMIT') && !$_SESSION['ROW_LIMIT'].nil? && $_SESSION['ROW_LIMIT'].key?(@items['name']) && !$_SESSION['ROW_LIMIT'][@items['name']].empty? @items['rowLimit'] = $_SESSION['ROW_LIMIT'][@items['name']].to_i end if ! @items['LIST_COL_SORT'].empty? case @items['LIST_COL_SORT_ORDER'] when 'ASC' @listSortNext = 'DESC' else @listSortNext = 'ASC' end end generate_limits() rescue Exception => e @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output(e) + @items['noDataMessage'] + '</div></td></tr>' end end |
Instance Attribute Details
#isAdministrating ⇒ Object
Returns the value of attribute isAdministrating.
1362 1363 1364 |
# File 'lib/widget_list.rb', line 1362 def @isAdministrating end |
Class Method Details
.build_drill_down(*params) ⇒ Object
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 |
# File 'lib/widget_list.rb', line 3390 def self.build_drill_down(*params) required_params = { :list_id => true, # -- your widget_list name (used for JS) :drill_down_name => true, # -- an identifier that is pass for the "column" or "type of drill down" which is passed as $_REQUEST['drill_down'] when the user clicks and returned from get_filter_and_drilldown based on session or request :data_to_pass_from_view => true, # -- Any SQL function or column name/value in the resultset in which would be the value passed when the user clicks the drill down :column_to_show => true, # -- The visible column or SQL functions to display to user for the link } optional_params = { :column_alias => '', # -- AS XXXX :extra_function => '', # -- Onclick of link, call another JS function after the drill down function is called :js_function_name => 'ListDrillDown', # -- name of JS Function :column_class => '', # -- custom class on the <a> tag :link_color => 'blue', # -- whatever color you want the link to be :extra_js_func_params => '', # -- Add extra params to ListDrillDown outside of the default :primary_database => true, # -- Since this function builds a column before widget_list is instantiated, tell which connection you are using } valid = WidgetList::Widgets::validate_items(params[0],required_params) items = WidgetList::Widgets::populate_items(params[0],optional_params) if items[:column_alias].empty? items[:column_alias] = items[:column_to_show] end if !items[:column_class].empty? items[:column_class] = ' "' + WidgetList::List::concat_string(items[:primary_database]) + items[:column_class] + WidgetList::List::concat_string(items[:primary_database]) + '"' end if WidgetList::List.get_db_type(items[:primary_database]) == 'oracle' link = %[q'[<a style='cursor:pointer;color:#{items[:link_color]};' class='#{items[:column_alias]}_drill#{items[:column_class]}' onclick='#{items[:js_function_name]}("#{items[:drill_down_name]}", ListDrillDownGetRowValue(this) ,"#{items[:list_id]}"#{items[:extra_js_func_params]});#{items[:extra_function]}'>]' #{WidgetList::List::concat_string(items[:primary_database])}#{items[:column_to_show]}#{WidgetList::List::concat_string(items[:primary_database])}q'[</a><script class='val-db' type='text'>]' #{WidgetList::List::concat_string(items[:primary_database])} #{items[:data_to_pass_from_view]} #{WidgetList::List::concat_string(items[:primary_database])} q'[</script>]' #{WidgetList::List::concat_outer(items[:primary_database])} #{WidgetList::List::is_sequel(items[:primary_database]) ? " as #{items[:column_alias]} " : ""}] else if WidgetList::List.get_db_type(items[:primary_database]) == 'postgres' link = %['<a style="cursor:pointer;color:#{items[:link_color]};" class="#{items[:column_alias]}_drill#{items[:column_class]}" onclick="#{items[:js_function_name]}(''#{items[:drill_down_name]}'', ListDrillDownGetRowValue(this) ,''#{items[:list_id]}''#{items[:extra_js_func_params]});#{items[:extra_function]}">"' #{WidgetList::List::concat_string(items[:primary_database])}#{items[:column_to_show]}#{WidgetList::List::concat_string(items[:primary_database])}'</a><script class="val-db" type="text">' #{WidgetList::List::concat_string(items[:primary_database])} #{items[:data_to_pass_from_view]} #{WidgetList::List::concat_string(items[:primary_database])}'</script>' #{WidgetList::List::is_sequel(items[:primary_database]) ? " as #{items[:column_alias]} " : ""}] else link = %[#{WidgetList::List::concat_inner(items[:primary_database])}"<a style='cursor:pointer;color:#{items[:link_color]};' class='#{items[:column_alias]}_drill#{items[:column_class]}' onclick='#{items[:js_function_name]}(#{WidgetList::List::double_quote(items[:primary_database])}#{items[:drill_down_name]}#{WidgetList::List::double_quote(items[:primary_database])}, ListDrillDownGetRowValue(this) ,#{WidgetList::List::double_quote(items[:primary_database])}#{items[:list_id]}#{WidgetList::List::double_quote(items[:primary_database])}#{items[:extra_js_func_params]});#{items[:extra_function]}'>"#{WidgetList::List::concat_string(items[:primary_database])}#{items[:column_to_show]}#{WidgetList::List::concat_string(items[:primary_database])}"</a><script class='val-db' type='text'>"#{WidgetList::List::concat_string(items[:primary_database])} #{items[:data_to_pass_from_view]} #{WidgetList::List::concat_string(items[:primary_database])}"</script>"#{WidgetList::List::concat_outer(items[:primary_database])} #{WidgetList::List::is_sequel(items[:primary_database]) ? " as #{items[:column_alias]} " : ""}] end end if $_REQUEST.key?('export_widget_list') link = "#{items[:column_to_show]} #{WidgetList::List::is_sequel(items[:primary_database]) ? " as #{items[:column_alias]} " : ""}" end return link end |
.build_list(list_parms) ⇒ Object
build_list controls a default AJAX/Export and full HTML return output in some cases you should copy and paste this logic for custom scenarios in your controller, but in most cases, this is okay
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 |
# File 'lib/widget_list.rb', line 3214 def self.build_list(list_parms) list = WidgetList::List.new(list_parms) ret = {} # # If AJAX, send back JSON # if $_REQUEST.key?('BUTTON_VALUE') && $_REQUEST['LIST_NAME'] == list_parms['name'] if $_REQUEST.key?('export_widget_list') return ['export',list.render()] end if $_REQUEST['list_action'] != 'ajax_widgetlist_checks' ret['list'] = list.render() ret['search_bar'] = list.get_header_pieces['searchBar'] ret['group_by_items'] = list.get_header_pieces['groupByItems'] ret['export_button'] = list.get_header_pieces['exportButton'] ret['list_id'] = list_parms['name'] ret['callback'] = 'ListSearchAheadResponse' end return ['json',WidgetList::Utils::json_encode(ret)] else # # Else assign to variable for view # if list. return list.render() else if $widget_list_conf.key?(:api_mode) && $widget_list_conf[:api_mode] ret['list'] = list.render() return ['json',WidgetList::Utils::json_encode(ret)] else return ['html', list.render() ] end end end end |
.build_search_button_click(list_parms) ⇒ Object
2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 |
# File 'lib/widget_list.rb', line 2859 def self.(list_parms) extra_get_vars = '' extra_func = '' filterParameters = {} if list_parms.key?('ajaxFunctionAll') extra_func = list_parms['ajaxFunctionAll'] end if list_parms.key?('carryOverRequsts') list_parms['carryOverRequsts'].each { |value| if $_REQUEST.key?(value) filterParameters[value] = $_REQUEST[value] end } extra_get_vars = WidgetList::Utils::build_query_string(filterParameters) end "ListJumpMin(jQuery('##{list_parms['name']}_jump_url').val() + '&advanced_search=1&' + jQuery('#list_search_id_#{list_parms['name']}_results *').serialize() + '&#{extra_get_vars}', '#{list_parms['name']}');HideAdvancedSearch(this);" + extra_func end |
.checkbox_helper(list_parms, primary_key) ⇒ Object
checkbox_helper just builds the proper Hashes to setup a checkbox widget row it assumes you have a fake column called ” AS checkbox to fill in with the widget_check
3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 |
# File 'lib/widget_list.rb', line 3309 def self.checkbox_helper(list_parms,primary_key) list_parms.deep_merge!({'inputs' => {'checkbox'=> {'type' => 'checkbox' } } }) list_parms.deep_merge!({'inputs' => {'checkbox'=> {'items' => { 'name' => list_parms['name'] + '_visible_checks[]', 'value' => primary_key, #the value should be a column name mapping 'class_handle' => list_parms['name'] + '_info_tables', } } } }) list_parms.deep_merge!({'inputs' => {'checkbox_header'=> {'type' => 'checkbox' } } }) list_parms.deep_merge!({'inputs' => {'checkbox_header'=> {'items' => { 'check_all' => true, 'id' => list_parms['name'] + '_info_tables_check_all', 'class_handle' => list_parms['name'] + '_info_tables', } } } }) return list_parms end |
.clear_check_box_session(name = '') ⇒ Object
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 |
# File 'lib/widget_list.rb', line 2212 def self.clear_check_box_session(name='') if $_SESSION.key?('DRILL_DOWN_FILTERS') $_SESSION.delete('DRILL_DOWN_FILTERS') end if $_SESSION.key?('DRILL_DOWNS') $_SESSION.delete('DRILL_DOWNS') end $_SESSION['list_checks'].keys.each { |key| if key.include?(name) $_SESSION['list_checks'].delete(key) end } if $_SESSION.key?('list_checks') && !$_SESSION['list_checks'].nil? && !$_SESSION['list_checks'].empty? end |
.concat_inner(primary) ⇒ Object
3469 3470 3471 3472 3473 3474 3475 3476 |
# File 'lib/widget_list.rb', line 3469 def self.concat_inner(primary) case WidgetList::List.get_db_type(primary) when 'mysql' 'CONCAT(' else '' end end |
.concat_outer(primary) ⇒ Object
3460 3461 3462 3463 3464 3465 3466 3467 |
# File 'lib/widget_list.rb', line 3460 def self.concat_outer(primary) case WidgetList::List.get_db_type(primary) when 'mysql' ')' else '' end end |
.concat_string(primary) ⇒ Object
3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 |
# File 'lib/widget_list.rb', line 3437 def self.concat_string(primary) case WidgetList::List.get_db_type(primary) when 'mysql' ' , ' when 'oracle','sqlite','postgres' ' || ' else ',' end end |
.determine_db_type(db_type) ⇒ Object
4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 |
# File 'lib/widget_list.rb', line 4456 def self.determine_db_type(db_type) if db_type.include?('://') the_type, void = db_type.split("://") if the_type == 'sqlite:/' the_type = 'sqlite' end return the_type.downcase else begin WidgetList::List::() if $is_mongo return 'mongo' else if $widget_list_db_conf.key?(db_type) if $widget_list_db_conf[db_type]['adapter'].include?('mysql') return 'mysql' elsif $widget_list_db_conf[db_type]['adapter'].include?('postgres') return 'postgres' elsif $widget_list_db_conf[db_type]['adapter'].include?('oracle') return 'oracle' elsif $widget_list_db_conf[db_type]['adapter'].include?('sqlite') return 'sqlite' elsif $widget_list_db_conf[db_type]['adapter'].include?('sqlserver') return 'sqlserver' elsif $widget_list_db_conf[db_type]['adapter'].include?('ibm') return 'db2' end end end rescue return '' end end end |
.double_quote(primary) ⇒ Object
3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 |
# File 'lib/widget_list.rb', line 3449 def self.double_quote(primary) case WidgetList::List.get_db_type(primary) when 'mysql' '\\"' when 'oracle','sqlite' '""' else '"' end end |
.drill_down_back(list_name = '') ⇒ Object
3386 3387 3388 |
# File 'lib/widget_list.rb', line 3386 def self.drill_down_back(list_name='') '<div class="goback" onclick="ListHome(\'' + list_name + '\');" title="Go Back"></div>' end |
.get_db_type(primary = true) ⇒ Object
4514 4515 4516 4517 4518 4519 4520 4521 4522 |
# File 'lib/widget_list.rb', line 4514 def self.get_db_type(primary=true) WidgetList::List::() if primary database_conn = $widget_list_conf[:primary] else database_conn = $widget_list_conf[:secondary] end WidgetList::List::determine_db_type(database_conn) end |
.get_defaults ⇒ Object
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 |
# File 'lib/widget_list.rb', line 1916 def self.get_defaults() { 'errors' => [], 'name' => ([*('A'..'Z'),*('0'..'9')]-%w(0 1 I O)).sample(16).join, 'database' => 'primary', # 'title' => '', 'listDescription' => '', 'pageId' => $_SERVER['SCRIPT_NAME'] + $_SERVER['PATH_INFO'], 'view' => '', 'data' => {}, 'bindVars' => [], 'bindVarsLegacy' => {}, 'links' => {}, 'buttons' => {}, 'inputs' => {}, 'filter' => [], 'predicate' => [], 'groupBy' => '', 'rowStart' => 0, 'rowLimit' => 10, 'orderBy' => '', 'allowHTML' => true, 'showPagination' => true, # # carryOverRequests will allow you to post custom things from request to all sort/paging URLS for each ajax # 'carryOverRequsts' => ['switch_grouping','group_row_id','q'], # # Head/Foot # 'customFooter' => '', 'customHeader' => '', # # Ajax # 'ajaxFunctionAll' => '', 'ajaxFunction' => 'ListJumpMin', # # Search # 'showSearch' => true, 'searchOnkeyup' => "SearchWidgetList('<!--URL-->', '<!--TARGET-->', this);", 'searchIdCol' => ($is_mongo) ? '_id' : 'id', 'searchTitle' => 'Search by Id or CSV of Ids and more', 'searchFieldsIn' => {}, 'searchClear' => false, 'searchClearAll' => false, 'searchSession' => true, 'searchFieldsOut' => {($is_mongo) ? '_id' : 'id'=>true}, 'templateFilter' => '', # # Export # 'showExport' => true, 'exportButtonTitle' => 'Export CSV', # # Group By Box # 'groupByItems' => [], 'groupBySelected' => false, 'groupByLabel' => 'Group By', 'groupByClick' => '', 'groupByClickDefault' => "ListChangeGrouping('<!--NAME-->', this);", # # Advanced searching # 'listSearchForm' => '', 'ransackSearch' => false, # # Column Specific # 'colClass' => '', 'colAlign' => 'center', 'fields' => {}, 'fieldsHidden' => [], 'columnStyle' => {}, 'columnClass' => {}, 'columnPopupTitle' => {}, 'columnSort' => {}, 'columnWidth' => {}, 'columnNoSort' => {}, # # Column Border (on right of each column) # 'borderedColumns' => false, 'borderColumnStyle' => '1px solid #CCCCCC', # # Row Border (on top of each row) # 'borderedRows' => true, 'borderRowStyle' => '1px solid #CCCCCC', # # Head/Foot border # 'borderHeadFoot' => false, 'headFootBorderStyle' => '1px solid #CCCCCC', 'bordersEverywhere?' => false, 'borderEverywhere' => '1px solid #CCCCCC', # # Buttons # 'defaultButtonClass' => 'info', # # Font # 'fontFamily' => false, #'"Times New Roman", Times, serif', 'headerFooterFontSize' => '14px', 'dataFontSize' => '14px', 'titleFontSize' => '24px', # # Table Colors # 'footerBGColor' => '#ECECEC', 'headerBGColor' => '#ECECEC', 'footerFontColor' => '#494949', 'headerFontColor' => '#494949', 'tableBorder' => '1', 'cornerRadius' => 15, 'useBoxShadow' => true, 'shadowInset' => 10, 'shadowSpread' => 20, 'shadowColor' => '#888888', # # Row specifics # 'rowClass' => '', 'rowFontColor' => 'black', 'rowColorByStatus' => {}, 'rowStylesByStatus' => {}, 'rowOffsets' => ['#FFFFFF','#FFFFFF'], 'class' => 'listContainerPassive', 'tableclass' => 'tableBlowOutPreventer', 'noDataMessage' => 'Currently no data.', 'useSort' => true, 'headerClass' => {}, 'fieldFunction' => {}, 'buttonVal' => 'templateListJump', 'linkFunction' => 'ButtonLinkPost', 'template' => '', 'LIST_COL_SORT_ORDER' => 'ASC', 'LIST_COL_SORT' => '', 'LIST_FILTER_ALL' => '', 'ROW_LIMIT' => '', 'LIST_SEQUENCE' => 1, 'NEW_SEARCH' => false, # # Checkbox # 'checkedClass' => 'widgetlist-checkbox', 'checkedFlag' => {}, 'storeSessionChecks' => false, # # Summary Row # 'totalRow' => {}, 'totalRowFirstCol' => '<strong>Total:</strong>', 'totalRowMethod' => {}, 'totalRowPrefix' => {}, 'totalRowSuffix' => {}, 'totalRowSeparator' => '.', 'totalRowDelimiter' => ',', 'totalRowDefault' => 'N/A', # # Hooks # 'columnHooks' => {}, 'rowHooks' => {} } end |
.get_filter_and_drilldown(listId) ⇒ Object
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 |
# File 'lib/widget_list.rb', line 2294 def self.get_filter_and_drilldown(listId) filter = '' drillDown = '' if !$_REQUEST.key?('BUTTON_VALUE') # Initialize page load/Session stuff whe list first loads # WidgetList::List::clear_check_box_session(listId) end if $_REQUEST.key?('drill_down') && !$_REQUEST.key?('searchClear') drillDown = $_REQUEST['drill_down'] $_SESSION.deep_merge!({'DRILL_DOWNS' => { listId => drillDown} }) elsif $_SESSION.key?('DRILL_DOWNS') && $_SESSION['DRILL_DOWNS'].key?(listId) && !$_REQUEST.key?('searchClear') drillDown = $_SESSION['DRILL_DOWNS'][listId] else drillDown = 'default' end if $_REQUEST.key?('filter') && !$_REQUEST.key?('searchClear') filter = $_REQUEST['filter'] $_SESSION.deep_merge!({'DRILL_DOWN_FILTERS' => { listId => filter} }) elsif $_SESSION.key?('DRILL_DOWN_FILTERS') && $_SESSION['DRILL_DOWN_FILTERS'].key?(listId) && !$_REQUEST.key?('searchClear') filter = $_SESSION['DRILL_DOWN_FILTERS'][listId] end return drillDown, filter end |
.get_group_by_selection(list_parms) ⇒ Object
2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 |
# File 'lib/widget_list.rb', line 2321 def self.get_group_by_selection(list_parms) groupBy = '' if $_REQUEST.key?('switch_grouping') groupBy = $_REQUEST['switch_grouping'] $_SESSION.deep_merge!({'CURRENT_GROUPING' => { list_parms['name'] => groupBy} }) elsif $_SESSION.key?('CURRENT_GROUPING') && !$_SESSION['CURRENT_GROUPING'].nil? && $_SESSION['CURRENT_GROUPING'].key?(list_parms['name']) groupBy = $_SESSION['CURRENT_GROUPING'][list_parms['name']] list_parms['groupBySelected'] = groupBy else groupBy = '' end return groupBy end |
.get_sequel(primary = true) ⇒ Object
4654 4655 4656 4657 4658 4659 4660 4661 |
# File 'lib/widget_list.rb', line 4654 def self.get_sequel(primary=true) WidgetList::List::() if primary Sequel.connect($widget_list_conf[:primary]) else Sequel.connect($widget_list_conf[:secondary]) end end |
.group_by_max_each_field(list_parms, group_by_filter) ⇒ Object
3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 |
# File 'lib/widget_list.rb', line 3352 def self.group_by_max_each_field(list_parms,group_by_filter) # # Oracle needs MAX on most fields when grouping in order to shy away from 'not a GROUP BY expression' errors # if group_by_filter != 'none' if list_parms.key?('fieldFunction') && !list_parms['fieldFunction'].empty? list_parms['fieldFunction'].each { |k, v| if !k.include?('_linked') && k != 'cnt' list_parms['fieldFunction'][k] = "MAX(#{v})" end } end if list_parms.key?('fieldsHidden') && !list_parms['fieldsHidden'].empty? list_parms['fieldsHidden'].each { |k| if (list_parms.key?('fieldFunction') && !list_parms['fieldFunction'].empty? && !list_parms['fieldFunction'].key?(k)) || list_parms['fieldFunction'].empty? list_parms['fieldFunction'][k] = "MAX(#{k})" end } end list_parms['fields'].each { |k| if !k.include?('_linked') && k != 'cnt' if (list_parms.key?('fieldFunction') && !list_parms['fieldFunction'].empty? && !list_parms['fieldFunction'].key?(k)) || list_parms['fieldFunction'].empty? list_parms['fieldFunction'][k] = "MAX(#{k})" end end } end return list_parms end |
.init_config ⇒ Object
2109 2110 2111 2112 2113 2114 2115 2116 2117 |
# File 'lib/widget_list.rb', line 2109 def self.init_config() list_parms = {} WidgetList::List::get_defaults.each { |k,v| if (v.is_a?(Array) || v.is_a?(Hash)) && v.empty? list_parms[k] = v end } return list_parms end |
.is_sequel(primary) ⇒ Object
4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 |
# File 'lib/widget_list.rb', line 4640 def self.is_sequel(primary) WidgetList::List::() if primary database_conn = $widget_list_conf[:primary] else database_conn = $widget_list_conf[:secondary] end is_sequel = true if database_conn != false && ! database_conn.include?('://') is_sequel = false end return is_sequel end |
.load_widget_list_database_yml ⇒ Object
4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 |
# File 'lib/widget_list.rb', line 4502 def self. if $widget_list_db_conf.nil? if Rails.root.join("config", "mongoid.yml").file? $is_mongo = true $widget_list_db_conf = YAML.load(ERB.new(File.new(Rails.root.join("config", "mongoid.yml")).read).result) else $is_mongo = false $widget_list_db_conf = YAML.load(ERB.new(File.new(Rails.root.join("config", "database.yml")).read).result) end end end |
.load_widget_list_yml ⇒ Object
4493 4494 4495 4496 4497 4498 4499 4500 |
# File 'lib/widget_list.rb', line 4493 def self. if $widget_list_conf.nil? $widget_list_conf = YAML.load(ERB.new(File.new(Rails.root.join("config", "widget-list.yml")).read).result)[Rails.env] if Rails.root.join("app/helpers", "widget_list_helper.rb").file? require Rails.root.join("app/helpers", "widget_list_helper.rb") end end end |
.mysql_to_mongo_predicate(predicate = '=', value = '', build_mongo_expression_hash = false) ⇒ Object
4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 |
# File 'lib/widget_list.rb', line 4317 def self.mysql_to_mongo_predicate(predicate='=',value='',build_mongo_expression_hash=false) functioncall = '' case predicate when '>','gt' functioncall = 'gt' when 'in','in' functioncall = 'in' when '>=','gte' functioncall = 'gte' when '<','lt' functioncall = 'lt' when '<=','lte' functioncall = 'lte' when '!=','ne' functioncall = 'ne' else functioncall = '' end if build_mongo_expression_hash if functioncall.empty? #when using the aggregation framework in mongoid, you do not pass {$eq => 'val'}, you pass just the value associated with the column return value else return {'$' + functioncall => value} end else return functioncall end end |
.parse_inputs_for_mongo_predicates(active_record_model, field, predicate, value_original) ⇒ Object
3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 |
# File 'lib/widget_list.rb', line 3257 def self.parse_inputs_for_mongo_predicates(active_record_model, field, predicate, value_original) if active_record_model.respond_to?(:serializers) && !active_record_model.serializers.key?(field) throw "field #{field} doesnt seem to exist in active record object here are the fields in the model class ==>>>> " + active_record_model.serializers.keys.inspect end is_int = (active_record_model.respond_to?(:serializers) && active_record_model.serializers[field].type.to_s == 'Integer') if predicate == '$in' #caste CSV string into proper array values = value_original.to_i if is_int values = value_original unless is_int if value_original.include?(',') #It is either a CSV or a comma inside the search string # values = [] value_original.split_it(',').each { |val| values << val.to_i if is_int values << val.strip unless is_int } else values = [values] end return values else if value_original.class.name == 'Hash' the_value = value_original[value_original.keys.first] else the_value = value_original end if the_value.include?(',') values = [] the_value.split_it(',').each { |val| values << val.strip } if value_original.class.name == 'Hash' final_value = {value_original.keys.first => values} else final_value = values end else final_value = value_original end return final_value end end |
.where(list_parms, field, value, predicate = '=') ⇒ Object
4347 4348 4349 4350 4351 4352 4353 4354 |
# File 'lib/widget_list.rb', line 4347 def self.where(list_parms,field,value,predicate='=') if $is_mongo list_parms['predicate'] << WidgetList::List.mysql_to_mongo_predicate(predicate,value,false) end list_parms['filter'] << field list_parms['bindVars'] << value return list_parms end |
Instance Method Details
#ajax_maintain_checks ⇒ Object
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 |
# File 'lib/widget_list.rb', line 2151 def ajax_maintain_checks() if !$_SESSION.key?('list_checks') $_SESSION['list_checks'] = {} end # # A list must be provided # if $_REQUEST.key?('LIST_NAME') listName = $_REQUEST['LIST_NAME'] sqlHash = $_REQUEST['SQL_HASH'] sequence = $_REQUEST['LIST_SEQUENCE'].to_s # # The placeholder is created when the list initially forms. This validates it and makes it so # not just anything can be injected into the session via this method. # # # For each posted check box # $_REQUEST.each { |value, checked| if checked.to_s == '1' # # Set it as checked # $_SESSION.deep_merge!({'list_checks' => { listName + sqlHash + value => true } }) else # # Unset if it exists and is unchecked # if $_SESSION['list_checks'].key?(listName + sqlHash + value) $_SESSION['list_checks'].delete(listName + sqlHash + value) end end } # # Check All # if $_REQUEST.key?('checked_all') && $_REQUEST['checked_all'] == '1' if $_SESSION.key?('list_checks') if $_SESSION['list_checks'].key?('check_all_' + sqlHash + listName + sequence) if $_REQUEST['checked_all'].empty? $_SESSION['list_checks'].delete('check_all_' + sqlHash + listName + sequence) else $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + listName + sequence => true } }) end else if ! $_REQUEST['checked_all'].empty? $_SESSION.deep_merge!({'list_checks' => { 'check_all_' + sqlHash + listName + $_REQUEST['LIST_SEQUENCE'] => true } }) end end end end end end |
#auto_column_name(name = '') ⇒ Object
4313 4314 4315 |
# File 'lib/widget_list.rb', line 4313 def auto_column_name(name='') name.gsub(/\_/,' ').gsub(/\-/,' ').capitalize end |
#build_column_button(column, j) ⇒ Object
3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 |
# File 'lib/widget_list.rb', line 3478 def (column,j) = @items['buttons'][column] btnOut = [] strCnt = 0 nameId = '' .each { |,| function = @items['linkFunction'] parameters = '' renderButton = true page = '' if .key?('page') page = ['page'].dup end if .key?('tags') = ['tags'].dup all_wildcard = false if ['tags'].first[0] == 'all' all_wildcard = true = {} @results.keys.each { |tag| [tag.downcase] = tag.downcase } end .each { | tagName , tag | if @results.key?(tag.upcase) && @results[tag.upcase][j] # # Data exists, lets check to see if page has any lowercase tags for restful URLs # if .key?('page') && ['page'].include?(tag.downcase) page.gsub!(tag.downcase,@results[tag.upcase][j]) else # # Will build ?tagname=XXXX based on your hash passed to your page # .deep_merge!({ 'args' => { tagName => @results[tag.upcase][j] } }) end else # # User is passing hard coded tags such as 'tags' => {'my_static_var' => '1234'} # Just fill in normally wherever anything is matched # if .key?('page') && ['page'].include?(tag.downcase) page.gsub!(tagName,tag) else .deep_merge!({ 'args' => { tagName => tag } }) end end } end nameId = .to_s + '_' + j.to_s ['name'] = nameId ['id'] = nameId if .key?('hide_if') && input['hide_if'].class.name == 'Proc' row_tmp = {} @results.map { |column| column }.each { |col| row_tmp[ col[0] ] = col[1][row] } if ['hide_if'].call(row_tmp) renderButton = false end end if (renderButton) strCnt += (['text'].length * 15) attributes = .dup attributes['page'] = page attributes['innerClass'] = @items['defaultButtonClass'] if !attributes.key?('innerClass') btnOut << WidgetList::Widgets::(['text'], attributes , true) end } #BS width algorithm. HACK/TWEAK/OMG Get it working. # colWidth = ((strCnt + (btnOut.count * 35)) / 2) + 10 width = '' center = '' if @items['colAlign'] == 'center' center = 'text-align:center;' width = 'width:' + colWidth.to_s + 'px' end return '<div style="border:0px solid black;white-space:nowrap;margin:auto;' + center + width + '"><div style="margin:auto;display:inline-block">' + btnOut.join('') + '</div></div>' end |
#build_column_input(column, row = '') ⇒ Object
3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 |
# File 'lib/widget_list.rb', line 3091 def build_column_input(column, row='') content = '' inputManager = @items['inputs'][column] case inputManager['type'] when "checkbox" input = {} input['name'] = 'widget_check_name' input['id'] = 'widget_check_id' input['check_all'] = false input['value'] = '' input['checked'] = '' input['onclick'] = '' input['input_class'] = 'widgetlist-checkbox-input' input['class_handle'] = '' input = WidgetList::Widgets::populate_items(inputManager['items'],input) onClick = [] checkAllId = '' # # Get a value. Assumes it is a column initially. # # @note headers are ignored and would fail as row would be null # if @results.key?(input['value'].upcase) && !@results[input['value'].upcase][row].to_s.empty? input['value'] = @results[ input['value'].upcase ][row] end if input.key?('disabled_if') && input['disabled_if'].class.name == 'Proc' row_tmp = {} @results.map { |column| column }.each { |col| row_tmp[ col[0] ] = col[1][row] } if input['disabled_if'].call(row_tmp) input['disabled'] = true end end # # Append class handle # input['input_class'] = "#{input['input_class']} #{input['class_handle']}" if input['check_all'] checkAllId = input['id'] if $_SESSION.key?('list_checks') && !$_SESSION['list_checks'].nil? && $_SESSION['list_checks'].key?('check_all_' + @sqlHash.to_s + @items['name'].to_s + @sequence.to_s) input['checked'] = true end # # Set header class # if @items['headerClass'].class.name == 'Array' && @items['headerClass'].key?('checkbox') if $_SESSION['list_checks'].key?('check_all_' + @sqlHash.to_s + @items['name'].to_s + @sequence.to_s) input['checked'] = true end end else input['input_class'] = "#{input['input_class']} #{input['class_handle']} #{input['class_handle']}_list" end # # Setup onclick action # if input['onclick'].empty? listJumpUrl = {} listJumpUrl['BUTTON_VALUE'] = @items['buttonVal'] listJumpUrl['LIST_COL_SORT'] = @items['LIST_COL_SORT'] listJumpUrl['LIST_COL_SORT_ORDER'] = @items['LIST_COL_SORT_ORDER'] listJumpUrl['LIST_FILTER_ALL'] = @items['LIST_FILTER_ALL'] listJumpUrl['ROW_LIMIT'] = @items['ROW_LIMIT'] listJumpUrl['LIST_SEQUENCE'] = @sequence listJumpUrl['LIST_NAME'] = @items['name'] listJumpUrl['SQL_HASH'] = @sqlHash listJumpUrl['list_action'] = 'ajax_widgetlist_checks' onClick << "AjaxMaintainChecks(this, '#{input['class_handle']}', '#{@items['name']}', '" + WidgetList::Utils::build_url(@items['pageId'],listJumpUrl,(!$_REQUEST.key?('BUTTON_VALUE'))) + "', '#{checkAllId}');" end input['onclick'] = onClick.join(' ') # # Checkbox is checked or not per query value # if ! @items['checkedFlag'].empty? if @items['checkedFlag'].key?(column) input['checked'] = !!@results[ @items['checkedFlag'][column].upcase ][row] end end # # Checkbox is checked or not per session (overwrites query) # if $_SESSION.key?('list_checks') && !$_SESSION['list_checks'].nil? && $_SESSION['list_checks'].key?(@items['name'] + @sqlHash + input['value'].to_s) input['checked'] = true end content = WidgetList::Widgets::(input) #todo never implemented when "text" a=1 #content = WidgetInput() when "select" a=1 #content = WidgetSelect() end return content end |
#build_column_link(column, j) ⇒ Object
3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 |
# File 'lib/widget_list.rb', line 3571 def build_column_link(column,j) links = @items['links'][column].dup if links.key?('page') page = links['page'].dup end url = {'PAGE_ID' => @items['pageId']} function = @items['linkFunction'] parameters = [] if links.key?('tags') = links['tags'].dup all_wildcard = false if links['tags'].first[0] == 'all' all_wildcard = true = {} @results.keys.each { |tag| [tag.downcase] = tag.downcase } end .each { | tagName, tag | if links.key?('page') && links['page'].include?(tag.downcase) && @results.key?(tag.upcase) page.gsub!(tag.downcase,@results[tag.upcase][j]) else if @results[tag.upcase][j] url[tagName] = @results[tag.upcase][j] else url[tagName] = tag end end } end if links.key?('onclick') function = links['onclick'] if links.key?('tags') .each { | tagName, tag | if @results.key?(tag.upcase) parameters << "'" + @results[tag.upcase][j].gsub(/'/,"\\\\'") + "'" end } end end if links.key?('page') linkUrl = page return "#{function}('#{linkUrl}')" else url['SQL_HASH'] = @sqlHash linkUrl = WidgetList::Utils::build_url(@items['pageId'], url, (!$_REQUEST.key?('BUTTON_VALUE'))) if !parameters.empty? return "#{function}(#{parameters.join(',')})" else return "#{function}('#{linkUrl}')" end end end |
#build_headers ⇒ Object
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 |
# File 'lib/widget_list.rb', line 2880 def build_headers() headers = [] ii = 0 @items['fields'].each { |field, fieldTitle| colWidthStyle = ''; colClass = ''; popupTitle = ''; templateIdx = 'templateNoSortColumn' #Column class # if ! @items['headerClass'].empty? if @items['headerClass'].key?(field.downcase) colClass = @items['headerClass'][field.downcase] end end #Column width # if ! @items['columnWidth'].empty? if @items['columnWidth'].key?(field.downcase) colWidthStyle = "width:" + @items['columnWidth'][field.downcase] + ";" end end if @items['borderedColumns'] colWidthStyle += 'border-right: ' + @items['borderColumnStyle'] + ';' end colWidthStyle += @items['borderHeadFoot'] ? 'border-bottom:' + @items['headFootBorderStyle'] + ';' : '' $_SESSION.deep_merge!({'LIST_SEQUENCE' => { @sqlHash => @sequence} }) #Hover Title # if @items['columnPopupTitle'].key?(field.downcase) popupTitle = @items['columnPopupTitle'][field.downcase] end # # Column is an input # if @items['inputs'].key?(fieldTitle) && @items['inputs'][fieldTitle].class.name == 'Hash' # # Default checkbox hover to "Select All" # # Do specific input type functions # case @items['inputs'][fieldTitle]['type'] when 'checkbox' if popupTitle.empty? && @items['inputs'][fieldTitle]['items']['check_all'] popupTitle = 'Select All' end # # No sort on this column # if ! @items['columnNoSort'].key?(fieldTitle) @items['columnNoSort'][field] = field end if colClass.empty? @items['headerClass'] = { fieldTitle => 'widgetlist-checkbox-header'} colClass = @items['headerClass'][fieldTitle] end end # # Build the input # fieldTitle = build_column_input(fieldTitle) else if $_REQUEST.key?('export_widget_list') && !skip_column(field) @csv[0] << fieldTitle end end #Add in radius if ii == @items['fields'].length - 1 && @items['listDescription'] == '' colWidthStyle += '-moz-border-radius-topright:' + get_radius_value() + ';-webkit-border-top-right-radius:' + get_radius_value() + ';border-top-right-radius:' + get_radius_value() + ';' end if ii == 0 && @items['listDescription'] == '' colWidthStyle += '-moz-border-radius-topleft:' + get_radius_value() + ';-webkit-border-top-left-radius:' + get_radius_value() + ';border-top-left-radius:' + get_radius_value() + ';' end if (@items['useSort'] && (@items['columnSort'].include?(field) || (@items['columnSort'].key?(field)) && !@items['columnNoSort'].include?(field)) || (@items['columnSort'].empty? && !@items['columnNoSort'].include?(field))) templateIdx = 'templateSortColumn' colSort = {} #Assign the column to be sorted # if !@items['columnSort'].empty? && @items['columnSort'].key?(field) colSort['LIST_COL_SORT'] = @items['columnSort'][field] elsif (!@items['columnSort'].empty? && @items['columnSort'].include?(field)) || @items['columnSort'].empty? colSort['LIST_COL_SORT'] = field end colSort['PAGE_ID'] = @items['pageId'] colSort['LIST_NAME'] = @items['name'] colSort['BUTTON_VALUE'] = @items['buttonVal'] colSort['LIST_COL_SORT_ORDER'] = @listSortNext colSort['LIST_FILTER_ALL'] = @items['LIST_FILTER_ALL'] colSort['ROW_LIMIT'] = @items['ROW_LIMIT'] colSort['LIST_SEQUENCE'] = @sequence icon = "" if ( ( (@items.key?('LIST_COL_SORT') && !@items['LIST_COL_SORT'].empty?) && @items['LIST_COL_SORT'] == colSort['LIST_COL_SORT']) || ( $_SESSION.key?('LIST_COL_SORT') && !$_SESSION['LIST_COL_SORT'].nil? && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) && $_SESSION['LIST_COL_SORT'][@sqlHash].key?(field)) ) changedSession = false if @items.key?('LIST_COL_SORT') && !@items['LIST_COL_SORT'].empty? changedSession = ( $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) && ! $_SESSION['LIST_COL_SORT'][@sqlHash].key?(@items['LIST_COL_SORT']) ) if $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) $_SESSION['LIST_COL_SORT'].delete(@sqlHash) end $_SESSION.deep_merge!({'LIST_COL_SORT' => { @sqlHash => {@items['LIST_COL_SORT']=> @items['LIST_COL_SORT_ORDER'] } } }) end if !changedSession && @items.key?('LIST_COL_SORT') && ! @items['LIST_COL_SORT'].empty? if @items['LIST_COL_SORT_ORDER'] == 'DESC' icon = "↑" else icon = "↓" end elsif !changedSession && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) #load sort from session $_SESSION['LIST_COL_SORT'][@sqlHash].each_with_index { |order,void| if order[1] == 'DESC' colSort['LIST_COL_SORT_ORDER'] = "ASC" icon = "↑" else colSort['LIST_COL_SORT_ORDER'] = "DESC" icon = "↓" end } end end #Carry over any search criteria on a sort to SORT URL # if $_REQUEST.key?('search_filter') && ! $_REQUEST['search_filter'].empty? if $_REQUEST['search_filter'].empty? colSort['search_filter'] = $_REQUEST['search_filter'] end end @items['carryOverRequsts'].each { |value| if $_REQUEST.key?(value) colSort[value] = $_REQUEST[value] end } colSort['SQL_HASH'] = @sqlHash pieces = { '<!--COLSORTURL-->' => WidgetList::Utils::build_url(@items['pageId'],colSort,(!$_REQUEST.key?('BUTTON_VALUE'))), '<!--NAME-->' => @items['name'], '<!--COLSORTICON->' => icon, '<!--COL_HEADER_ID-->' => (field).gsub(/\s/,'_'), '<!--INLINE_STYLE-->' => colWidthStyle, '<!--TITLE_POPUP-->' => popupTitle, '<!--ALIGN-->' => @items['colAlign'], '<!--COL_HEADER_CLASS-->' => colClass, '<!--TITLE-->' => fieldTitle, '<!--FUNCTION-->' => @items['ajaxFunction'], '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'], } headers << WidgetList::Utils::fill(pieces, @items[templateIdx]) else pieces = { '<!--TITLE-->' => fieldTitle, '<!--INLINE_STYLE-->' => colWidthStyle, '<!--ALIGN-->' => @items['colAlign'], '<!--TITLE_POPUP-->' => popupTitle, '<!--COL_HEADER_CLASS-->' => colClass, '<!--COL_HEADER_ID-->' => (field).gsub(/\s/,'_') } headers << WidgetList::Utils::fill(pieces, @items[templateIdx]) end ii = ii + 1 } @templateFill['<!--COLSPAN_FULL-->'] = headers.count() @templateFill['<!--PAGINATION_LIST-->'] = build_pagination() @templateFill['<!--HEADERS-->'] = headers.join('') if ! @items['listDescription'].empty? fillDesc = {} fillDesc['<!--COLSPAN-->'] = headers.count() fillDesc['<!--LIST_DESCRIPTION-->'] = @items['listDescription'] fillDesc['<!--LIST_NAME-->'] = @items['name'] @templateFill['<!--LIST_TITLE-->'] = WidgetList::Utils::fill(fillDesc,@items['list_description']) else @templateFill['<!--LIST_TITLE-->'] = '' end end |
#build_pagination ⇒ Object
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 |
# File 'lib/widget_list.rb', line 2656 def build_pagination() pageRange = 3 pageNext = 1 pagePrev = 1 showPrev = false showNext = true prevUrl = '' nextUrl = '' = '' urlTags = {} templates = {} urlTags['SQL_HASH'] = @sqlHash urlTags['PAGE_ID'] = @items['pageId'] urlTags['LIST_NAME'] = @items['name'] urlTags['BUTTON_VALUE'] = @items['buttonVal'] urlTags['LIST_FILTER_ALL'] = @items['LIST_FILTER_ALL'] templates['btn_previous'] = @items['template_pagination_previous_disabled'] templates['btn_next'] = @items['template_pagination_next_active'] if $_REQUEST.key?('search_filter') && ! $_REQUEST['search_filter'].empty? urlTags['search_filter'] = $_REQUEST['search_filter'] end if @items['LIST_COL_SORT'].empty? urlTags['LIST_COL_SORT'] = @items['LIST_COL_SORT'] urlTags['LIST_COL_SORT_ORDER'] = @items['LIST_COL_SORT_ORDER'] urlTags['ROW_LIMIT'] = @items['ROW_LIMIT'] end if @items['links'].key?('paginate') && @items['links']['paginate'].class.name == 'Hash' @items['links']['paginate'].each { |tagName, tag| urlTags[tagName] = tag } end @items['carryOverRequsts'].each { |value| if $_REQUEST.key?(value) urlTags[value] = $_REQUEST[value] end } if (@sequence == @totalPages || ! (@totalPages > 0)) showNext = false else urlTags['LIST_SEQUENCE'] = @sequence + 1 nextUrl = WidgetList::Utils::build_url(@items['pageId'],urlTags,(!$_REQUEST.key?('BUTTON_VALUE'))) end if @sequence > 1 pagePrev = @sequence - 1 urlTags['LIST_SEQUENCE'] = pagePrev prevUrl = WidgetList::Utils::build_url(@items['pageId'],urlTags,(!$_REQUEST.key?('BUTTON_VALUE'))) showPrev = true end if !showNext templates['btn_next'] = @items['template_pagination_next_disabled'] end if showPrev templates['btn_previous'] = @items['template_pagination_previous_active'] end #Assemble navigation buttons # pieces = { '<!--NEXT_URL-->' => nextUrl, '<!--LIST_NAME-->' => @items['name'], '<!--PREVIOUS_URL-->' => prevUrl, '<!--FUNCTION-->' => @items['ajaxFunction'], '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'], } templates['btn_next'] = WidgetList::Utils::fill(pieces,templates['btn_next']) templates['btn_previous'] = WidgetList::Utils::fill(pieces,templates['btn_previous']) # # Sequence Range Drop Down # # Show x per page # urlTags['LIST_SEQUENCE'] = @sequence urlTags['ROW_LIMIT'] = 10 @items['carryOverRequsts'].each { |value| if $_REQUEST.key?(value) urlTags[value] = $_REQUEST[value] end } # Automate select box and rules # rowLimitSelect = [10,20,50,100,500,1000] rowLimitSelectData = {} rowLimitSelectConfigs = {} #Set a default of 10 # urlTags['ROW_LIMIT'] = 10 = '' rowLimitSelect.each_with_index { |jumpCount, key| if (@totalRows >= jumpCount || @totalRows > rowLimitSelect[key-1]) urlTags['ROW_LIMIT'] = jumpCount rowLimitUrl = WidgetList::Utils::build_url(@items['pageId'],urlTags,(!$_REQUEST.key?('BUTTON_VALUE'))) selected = '' if (@items['rowLimit'] == jumpCount) selected = 'selected' end += "<option value='#{rowLimitUrl}' #{selected}>#{jumpCount}</option> " end } # WidgetSelect( todo) pageSelect = <<-EOD <select id="<!--LIST_NAME-->_per_page" onchange="#{@items['ajaxFunction']}(this.value,'#{@items['name']}');#{@items['ajaxFunctionAll']}" style="width:58px"> #{} </select> EOD #Ensure the range does not exceed the actual number of pages # if @totalPages < pageRange pageRange = @totalPages end ### # Create a range of x or less numbers. # # Take 2 off and add 2 or as much as possible either way ### startingPoint = @sequence vkill = pageRange while vkill > 0 do vkill = vkill - 1 if startingPoint <= 1 break else startingPoint = startingPoint-1 end end endPoint = @sequence vkill = pageRange while vkill > 0 do vkill = vkill - 1 if endPoint <= 1 endPoint = endPoint+1 else break end end jumpSection = [] #Builds jump section previous 4 5 6 7 next # for page in startingPoint..endPoint urlTags['LIST_SEQUENCE'] = page urlTags['SQL_HASH'] = @sqlHash jumpTemplate = '' jumpUrl = '' jumpUrl = WidgetList::Utils::build_url(@items['pageId'], urlTags, (!$_REQUEST.key?('BUTTON_VALUE'))) if page == @sequence jumpTemplate = @items['template_pagination_jump_active'] else jumpTemplate = @items['template_pagination_jump_unactive'] end jumpSection << WidgetList::Utils::fill({ '<!--SEQUENCE-->' => page, '<!--JUMP_URL-->' => jumpUrl, '<!--LIST_NAME-->' => @items['name'], '<!--FUNCTION-->' => @items['ajaxFunction'], '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll'], }, jumpTemplate) end pieces = { '<!--PREVIOUS_BUTTON-->' => templates['btn_previous'], '<!--SEQUENCE-->' => @sequence, '<!--NEXT_BUTTON-->' => templates['btn_next'], '<!--TOTAL_PAGES-->' => @totalPages, '<!--TOTAL_ROWS-->' => @totalRows, '<!--PAGE_SEQUENCE_JUMP_LIST-->' => pageSelect, '<!--JUMP-->' => jumpSection.join(''), '<!--LIST_NAME-->' => @items['name'], } paginationOutput = WidgetList::Utils::fill(pieces,@items['template_pagination_wrapper']) if (@items['showPagination']) return paginationOutput else return '' end end |
#build_rows ⇒ Object
3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 |
# File 'lib/widget_list.rb', line 3632 def build_rows() sql = build_statement() if @totalResultCount > 0 if @items['data'].empty? #Run the actual statement # #code flow forces me to merge the sort array here if !@group_match.nil? @group_match = @group_match.merge({"sort" => { "$sort" => @mongo_sort } }) if !@mongo_sort.empty? @group_match = @group_match.merge({"skip" => { "$skip" => @mongo_skip } }) @group_match = @group_match.merge({"limit" => { "$limit" => @mongo_limit } }) @group_match = @group_match.merge({"match" => @mongo_match }) end @totalRowCount = get_database._select(sql , @items['bindVars'], @items['bindVarsLegacy'], @active_record_model, @group_match) end if @totalRowCount > 0 if @items['data'].empty? @results = get_database.final_results else @results = @items['data'] end #Build each row # max = @totalRowCount-1 rows = [] j = 0 for j in j..max columns = [] row_values = [] customRowColor = '' customRowStyle = '' # # For each column (field) in this row # changedFontColor = false @items['fields'].each { |column , fieldTitle| column = strip_aliases(column) colPieces = {} colClasses = [] theStyle = '' colData = '' colClass = '' onClick = '' colWidthStyle = '' content = '' contentTitle = '' #todo unit test build_column_link # # Column is a Link # if @items['links'].key?(column) && @items['links'][column].class.name == 'Hash' onClick = build_column_link(column,j) end # # Column is a Button # if @items['buttons'].key?(column) && @items['buttons'][column].class.name == 'Hash' content = (column, j) # # Column is an input # elsif @items['inputs'].key?(column) && @items['inputs'][column].class.name == 'Hash' colClasses << @items['checkedClass'] content = build_column_input(column, j) # # Column is text # else unless @results.key?(column.upcase) throw "Are you sure that the column #{column} exists in your fields array? The resultset does not have this field returned from the database" end cleanData = (@results[column.upcase][j].to_s) row_values << cleanData # # For now disable length parser # if false && cleanData.length > @items['strlength'] content = @results[column.upcase][j].to_s[ 0, @items['strlength'] ] + '...' else content = @results[column.upcase][j].to_s end # #Strip HTML # if !@items['allowHTML'] content = (content) end content = get_database._bind(content, @items['bindVarsLegacy']) # Column color # if ! @items['columnStyle'].empty? if @items['columnStyle'].key?(column.downcase) colHeader = @items['columnStyle'][column.downcase] if @results.key?(colHeader.upcase) theStyle = @results[colHeader.upcase][j] else theStyle = colHeader end end end # Column width # if ! @items['columnWidth'].empty? if @items['columnWidth'].key?(column.downcase) colWidthStyle = "width:" + @items['columnWidth'][column.downcase] + ";" end end # Column Class # if !@items['columnClass'].empty? if @items['columnClass'].key?(column.downcase) colClasses << @items['columnClass'][column.downcase] end end end # # Setup any column classes # colClasses << @items['colClass'] colClass = colClasses.join(' ') # # Row Color # if !@items['rowColorByStatus'].empty? && @items['rowColorByStatus'].key?(column) && !@items['rowColorByStatus'][column].empty? @items['rowColorByStatus'][column].each { |status,color| if status === content customRowColor = color end } end # # Row Style # if !@items['rowStylesByStatus'].empty? && @items['rowStylesByStatus'].key?(column) && !@items['rowStylesByStatus'][column].empty? @items['rowStylesByStatus'][column].each { |status,inlineStyle| if status === content customRowStyle = inlineStyle if inlineStyle.include?('color:') || inlineStyle.include?('color :') changedFontColor = true end end } end # # Set up Column Pieces # colPieces['<!--CLASS-->'] = colClass colPieces['<!--ALIGN-->'] = @items['colAlign'] colPieces['<!--STYLE-->'] = colWidthStyle if @items['borderedColumns'] colPieces['<!--STYLE-->'] += 'border-right: ' + @items['borderColumnStyle'] + ';' end if @items['borderedRows'] colPieces['<!--STYLE-->'] += 'border-top: ' + @items['borderRowStyle'] + ';' end colPieces['<!--ONCLICK-->'] = onClick if !onClick.empty? colPieces['<!--SPAN_STYLE-->'] = 'cursor:pointer;' + theStyle else colPieces['<!--SPAN_STYLE-->'] = '' + theStyle end colPieces['<!--TITLE-->'] = contentTitle #todo htmlentities needed ? colPieces['<!--CONTENT-->'] = content # # Assemble the Column # columns << WidgetList::Utils::fill(colPieces, @items['col']) } if $_REQUEST.key?('export_widget_list') @csv << row_values end #Draw the row # pieces = {'<!--CONTENT-->' => columns.join('') } if @items['rowColorByStatus'].empty? && @items['rowStylesByStatus'].empty? #Set the row color # if( j % 2 ==0) rowColor = @items['rowOffsets'][1] else rowColor = @items['rowOffsets'][0] end #Draw default color # pieces['<!--BGCOLOR-->'] = rowColor pieces['<!--ROWSTYLE-->'] = '' pieces['<!--ROWCLASS-->'] = @items['rowClass'] else pieces['<!--BGCOLOR-->'] = !customRowColor.empty? ? customRowColor : @items['rowColor'] pieces['<!--ROWSTYLE-->'] = !customRowStyle.empty? ? customRowStyle : '' pieces['<!--ROWCLASS-->'] = @items['rowClass'] end pieces['<!--ROWSTYLE-->'] += 'font-size:' + @items['dataFontSize'] + ';' if !changedFontColor pieces['<!--ROWSTYLE-->'] += 'color:' + @items['rowFontColor'] + ';' end rows << WidgetList::Utils::fill(pieces, @items['row']) end @templateFill['<!--DATA-->'] = rows.join('') else = (get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage'] @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output() + + '</div></td></tr>' end else = (get_database.errors) ? @items['noDataMessage'] + ' <span style="color:red">(An error occurred)</span>' : @items['noDataMessage'] @templateFill['<!--DATA-->'] = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output() + + '</div></td></tr>' end end |
#build_statement ⇒ Object
4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 |
# File 'lib/widget_list.rb', line 4114 def build_statement() @mongo_sort = {} statement = '' @fieldList = [] @fieldListPlain = [] pieces = { '<!--FIELDS_PLAIN-->' => '', '<!--FIELDS-->' => '', '<!--SOURCE-->' => '', '<!--WHERE-->' => '', '<!--GROUPBY-->' => '', '<!--ORDERBY-->' => '', '<!--LIMIT-->' => ''} #Build out a list of columns to select from # @items['fields'].each { |column, fieldTitle| @fieldListPlain << strip_aliases(column) if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty? # fieldFunction's should not have an alias, just the database functions column = @items['fieldFunction'][column] + " " + column end @fieldList << column } if get_database.db_type == 'oracle' if !@items['groupBy'].empty? @fieldList << 'MAX(rn) as rn' else @fieldList << 'rn' end @fieldListPlain << 'rn' end if @items['fieldsHidden'].class.name == 'Array' @items['fieldsHidden'].each { |column| if !@items['fields'].key?(column) @fieldListPlain << strip_aliases(column) if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty? # fieldFunction's should not have an alias, just the database functions column = @items['fieldFunction'][column] + " " + column end @fieldList << column end } elsif @items['fieldsHidden'].class.name == 'Hash' @items['fieldsHidden'].each { |column| col = column[0] if !@items['fields'].key?(col) @fieldListPlain << strip_aliases(col) if @items['fieldFunction'].key?(column[0]) && !@items['fieldFunction'][column[0]].empty? # fieldFunction's should not have an alias, just the database functions col = @items['fieldFunction'][column[0]] + " " + column[0] end @fieldList << col end } end viewPieces = {} viewPieces['<!--FIELDS_PLAIN-->'] = @fieldListPlain.join(',') viewPieces['<!--FIELDS-->'] = @fieldList.join(',') viewPieces['<!--SOURCE-->'] = get_view() statement = WidgetList::Utils::fill(viewPieces, @items['statement']['select']['view']) @sqlHash = Digest::SHA2.hexdigest( WidgetList::Utils::fill(pieces, statement) ) if @items['searchClear'] || @items['searchClearAll'] clear_sql_session(@items.key?('searchClearAll')) end if !$_REQUEST.key?('BUTTON_VALUE') && !$_SESSION['LIST_SEQUENCE'].nil? && $_SESSION.key?('LIST_SEQUENCE') && $_SESSION['LIST_SEQUENCE'].key?(@sqlHash) && $_SESSION['LIST_SEQUENCE'][@sqlHash] > 0 @sequence = $_SESSION['LIST_SEQUENCE'][@sqlHash] generate_limits end if !@filter.empty? pieces['<!--WHERE-->'] = ' WHERE ' + @filter end if !@items['groupBy'].empty? pieces['<!--GROUPBY-->'] = ' GROUP BY ' + @items['groupBy'] else pieces['<!--GROUPBY-->'] = '' end if !@items['LIST_COL_SORT'].empty? || ($_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash)) pieces['<!--ORDERBY-->'] += ' ORDER BY ' foundColumn = false if ! @items['LIST_COL_SORT'].empty? foundColumn = true @mongo_sort[(( @items['LIST_COL_SORT'] != 'cnt') ? '_id.' : '') + @items['LIST_COL_SORT']] = (@items['LIST_COL_SORT_ORDER'] == 'ASC') ? 1 : -1 if $is_mongo pieces['<!--ORDERBY-->'] += tick_field() + strip_aliases(@items['LIST_COL_SORT']) + tick_field() + " " + @items['LIST_COL_SORT_ORDER'] else $_SESSION['LIST_COL_SORT'][@sqlHash].each_with_index { |order,void| if @items['fields'].key?(order[0]) foundColumn = true @mongo_sort[((order[0] != 'cnt') ? '_id.' : '') + order[0]] = (order[1] == 'ASC') ? 1 : -1 if $is_mongo pieces['<!--ORDERBY-->'] += tick_field() + strip_aliases(order[0]) + tick_field() + " " + order[1] end } if $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].class.name == 'Hash' && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) end # Add base order by if ! @items['orderBy'].empty? pieces['<!--ORDERBY-->'] += ',' if foundColumn == true pieces['<!--ORDERBY-->'] += @items['orderBy'] if $is_mongo if @items['orderBy'].include?(',') criteriaTmp = @items['orderBy'].split_it(',') else criteriaTmp = [@items['orderBy']] end criteriaTmp.each { |value| @mongo_sort['_id.' + value.gsub(/ASC/,'').gsub(/DESC/,'').strip] = (value.include?('DESC')) ? -1 : 1 } end end elsif !@items['orderBy'].empty? pieces['<!--ORDERBY-->'] += ' ORDER BY ' + @items['orderBy'] end if get_database.db_type == 'oracle' && pieces['<!--ORDERBY-->'].empty? #oracle needs a field to perform the rank() over #if field is not an "inputs" or a "buttons" #if field is all NULL, then you better watch out as paging will NOT work tmp = @items['fields'].dup.reject { |val| if (!@items['inputs'].key?(val) && !@items['buttons'].key?(val)) false else true end } keys = tmp.keys pieces['<!--ORDERBY-->'] += ' ORDER BY ' + strip_aliases(keys[0]) + ' ASC' unless keys[0].nil? end case get_database.db_type when 'postgres' pieces['<!--LIMIT-->'] = ' LIMIT :HIGH OFFSET :LOW' when 'oracle' pieces['<!--LIMIT-->'] = ' WHERE ( rn >' + (@sequence > 1 ? '' : '=') + ' :LOW AND rn <= :HIGH ) ' else pieces['<!--LIMIT-->'] = ' LIMIT :LOW, :HIGH' end statement = WidgetList::Utils::fill(pieces, statement) if @items['rowLimit'].to_i >= @totalRows @items['bindVarsLegacy']['LOW'] = 0 @sequence = 1 end if $is_mongo # # Ordering in mongo object # columnordering = pieces['<!--ORDERBY-->'].gsub!(/ORDER BY/,'') pieces['<!--ORDERBY-->'] = columnordering.strip unless columnordering.nil? @active_record_model = @active_record_model.order_by(pieces['<!--ORDERBY-->']) unless columnordering.nil? # # Limits in mongo # @active_record_model = @active_record_model.skip(@items['bindVarsLegacy']['LOW'].to_i).limit(@items['rowLimit'].to_i) @mongo_skip = @items['bindVarsLegacy']['LOW'].to_i @mongo_limit = @items['rowLimit'].to_i end statement end |
#build_summary_row ⇒ Object
3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 |
# File 'lib/widget_list.rb', line 3899 def build_summary_row() if @totalResultCount > 0 && !@items['totalRow'].empty? if @totalRowCount > 0 columns = [] first_col = true @rawTotals = {} row_values = [] @items['fields'].each { |column , fieldTitle| column = strip_aliases(column) colPieces = {} colClasses = [] theStyle = '' colData = '' colClass = '' onClick = '' colWidthStyle = '' content = '' contentTitle = '' if first_col first_col = false content = @items['totalRowFirstCol'] @rawTotals[column] = (content) else if (@items['totalRow'].include?(column) || @items['totalRow'].key?(column) && @results.key?(column.upcase)) preg_max_precision = Regexp.new('\\' + @items['totalRowSeparator'] + '([0-9]+)') #/\.([0-9]+)/ preg_number_value = Regexp.new('[0-9|\\' + @items['totalRowSeparator'] + '0-9]+') #/[0-9|\.0-9]+/ preg_strip_commas = Regexp.new('\\' + @items['totalRowDelimiter']) content = 0 max_precision = [0] raw_value = 0.0 prefix = '' suffix = '' @results[column.upcase].each { |val| if val.include?("<script class='val-db'") val = val[0..val.index("<script class='val-db'")-1] end cleanData = (val.to_s) max_precision << cleanData.match(preg_max_precision)[1].length unless cleanData.match(preg_max_precision).nil? raw_value = cleanData.gsub(preg_strip_commas,'').match(preg_number_value)[0].to_f unless cleanData.gsub(preg_strip_commas,'').match(preg_number_value).nil? prefix, suffix = cleanData.gsub(preg_strip_commas,'').split(preg_number_value) prefix = '' if prefix.nil? suffix = '' if suffix.nil? content = content + raw_value } if @items['totalRowPrefix'].key?(column) prefix = @items['totalRowPrefix'][column] end if @items['totalRowSuffix'].key?(column) suffix = @items['totalRowSuffix'][column] end precision = max_precision.max if @items['totalRowMethod'].key?(column) case @items['totalRowMethod'][column] when 'average' content = (content/@totalRowCount).round(precision) end end @rawTotals[column] = content content = number_to_currency(content, :unit => prefix, :precision => precision, :separator => @items['totalRowSeparator'], :delimiter => @items['totalRowDelimiter']) + suffix else @rawTotals[column] = @items['totalRowDefault'] content = @items['totalRowDefault'] end row_values << content end content = get_database._bind(content, @items['bindVarsLegacy']) # Column color # if ! @items['columnStyle'].empty? if @items['columnStyle'].key?(column.downcase) colHeader = @items['columnStyle'][column.downcase] if @results.key?(colHeader.upcase) theStyle = @results[colHeader.upcase][j] else theStyle = colHeader end end end # Column width # if ! @items['columnWidth'].empty? if @items['columnWidth'].key?(column.downcase) colWidthStyle = "width:" + @items['columnWidth'][column.downcase] + ";" end end # Column Class # if !@items['columnClass'].empty? if @items['columnClass'].key?(column.downcase) colClasses << @items['columnClass'][column.downcase] end end # # Setup any column classes # colClasses << @items['colClass'] colClass = colClasses.join(' ') # # Set up Column Pieces # colPieces['<!--CLASS-->'] = colClass colPieces['<!--ALIGN-->'] = @items['colAlign'] colPieces['<!--STYLE-->'] = theStyle + colWidthStyle if @items['borderedColumns'] colPieces['<!--STYLE-->'] += 'border-right: ' + @items['borderColumnStyle'] + ';' end if @items['borderedRows'] colPieces['<!--STYLE-->'] += 'border-top: ' + @items['borderRowStyle'] + ';' end colPieces['<!--ONCLICK-->'] = onClick colPieces['<!--TITLE-->'] = contentTitle #todo htmlentities needed ? colPieces['<!--CONTENT-->'] = content colPieces['<!--SPAN_STYLE-->'] = '' # # Assemble the Column # columns << WidgetList::Utils::fill(colPieces, @items['col']) } if $_REQUEST.key?('export_widget_list') @csv << row_values end # # Draw the row # pieces = {'<!--CONTENT-->' => columns.join('') } pieces['<!--BGCOLOR-->'] = @items['rowOffsets'][@totalRowCount % 2] pieces['<!--ROWSTYLE-->'] = '' pieces['<!--ROWCLASS-->'] = @items['rowClass'] pieces['<!--ROWSTYLE-->'] += 'font-size:' + @items['dataFontSize'] + ';' @templateFill['<!--DATA-->'] += WidgetList::Utils::fill(pieces, @items['row']) end end end |
#cast_col ⇒ Object
2142 2143 2144 2145 2146 2147 2148 2149 |
# File 'lib/widget_list.rb', line 2142 def cast_col() case get_database.db_type when 'postgres' '::char(1000)' else '' end end |
#clear_search_session(all = false) ⇒ Object
2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 |
# File 'lib/widget_list.rb', line 2230 def clear_search_session(all=false) if $_SESSION.key?('SEARCH_FILTER') && $_SESSION['SEARCH_FILTER'].key?(@items['name']) $_SESSION['SEARCH_FILTER'].delete(@items['name']) end if $_SESSION.key?('ROW_LIMIT') && $_SESSION['ROW_LIMIT'].key?(@items['name']) $_SESSION['ROW_LIMIT'].delete(@items['name']) end if $_SESSION.key?('DRILL_DOWNS') && $_SESSION['DRILL_DOWNS'].key?(@items['name']) $_SESSION['DRILL_DOWNS'].delete(@items['name']) end if $_SESSION.key?('DRILL_DOWN_FILTERS') && $_SESSION['DRILL_DOWN_FILTERS'].key?(@items['name']) $_SESSION['DRILL_DOWN_FILTERS'].delete(@items['name']) end if all && $_SESSION.key?('SEARCH_FILTER') $_SESSION.delete('SEARCH_FILTER') end if all && $_SESSION.key?('ROW_LIMIT') $_SESSION.delete('ROW_LIMIT') end if $_REQUEST.key?('LIST_FILTER_ALL') $_REQUEST.delete('LIST_FILTER_ALL') end if $_REQUEST.key?('LIST_COL_SORT') $_REQUEST.delete('LIST_COL_SORT') end if $_REQUEST.key?('LIST_COL_SORT_ORDER') $_REQUEST.delete('LIST_COL_SORT_ORDER') end if $_REQUEST.key?('LIST_SEQUENCE') $_REQUEST.delete('LIST_SEQUENCE') end end |
#clear_sort_get_vars ⇒ Object
2337 2338 2339 2340 2341 2342 2343 2344 |
# File 'lib/widget_list.rb', line 2337 def clear_sort_get_vars() $_REQUEST.delete('LIST_FILTER_ALL') $_REQUEST.delete('ROW_LIMIT') $_REQUEST.delete('LIST_SEQUENCE') $_REQUEST.delete('LIST_COL_SORT_ORDER') $_REQUEST.delete('LIST_COL_SORT') $_REQUEST.delete('LIST_FILTER_ALL') end |
#clear_sql_session(all = false) ⇒ Object
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 |
# File 'lib/widget_list.rb', line 2274 def clear_sql_session(all=false) if $_SESSION.key?('LIST_SEQUENCE') && $_SESSION['LIST_SEQUENCE'].key?(@sqlHash) $_SESSION['LIST_SEQUENCE'].delete(@sqlHash) end if $_SESSION.key?('LIST_COL_SORT') && $_SESSION['LIST_COL_SORT'].key?(@sqlHash) $_SESSION['LIST_COL_SORT'].delete(@sqlHash) end if all && $_SESSION.key?('LIST_COL_SORT') $_SESSION.delete('LIST_COL_SORT') end if all && $_SESSION.key?('LIST_SEQUENCE') $_SESSION.delete('LIST_SEQUENCE') end end |
#connect ⇒ Object
4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 |
# File 'lib/widget_list.rb', line 4588 def connect @has_connected = true begin if Rails.root.join("config", "widget-list.yml").file? WidgetList::List::() if $widget_list_conf.nil? throw 'Configuration file widget-list.yml has no data. Check that (' + Rails.env + ') Rails.env matches the pointers in the file' end @primary_conn = $widget_list_conf[:primary] @secondary_conn = $widget_list_conf[:secondary] else throw 'widget-list.yml not found' end @is_primary_sequel = true @is_secondary_sequel = true if @primary_conn != false && ! @primary_conn.include?(':/') @is_primary_sequel = false end if @secondary_conn != false && !@secondary_conn.include?(':/') @is_secondary_sequel = false end if @primary_conn != false if @primary_conn.include?(':/') @widget_list_sequel_conn = Sequel.connect(@primary_conn) @widget_list_sequel_conn.db_type = WidgetList::List::determine_db_type(@primary_conn) else @widget_list_ar_conn = WidgetListActiveRecord.new @widget_list_ar_conn.db_type = WidgetList::List::determine_db_type(@primary_conn) end end if @secondary_conn != false if @secondary_conn.include?(':/') @widget_list_sequel_conn2 = Sequel.connect(@secondary_conn) @widget_list_sequel_conn2.db_type = WidgetList::List::determine_db_type(@secondary_conn) else @widget_list_ar_conn2 = WidgetListActiveRecord.new @widget_list_ar_conn2.db_type = WidgetList::List::determine_db_type(@secondary_conn) end end rescue Exception => e Rails.logger.info "widget-list.yml and connection to @widget_list_sequel_conn or @widget_list_sequel_conn2 failed. Please fix and try again (" + e.to_s + ")" end end |
#generate_error_output(ex = '') ⇒ Object
4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 |
# File 'lib/widget_list.rb', line 4078 def generate_error_output(ex='') sqlDebug = "" if !@items['errors'].empty? sqlDebug += "<br/><br/><strong style='color:red'>(" + @items['errors'].join(', ') + ")</strong>" end if Rails.env == 'development' sqlDebug += "<br/><br/><textarea style='width:100%;height:400px;'>" + get_database.last_sql.to_s + "</textarea>" end if Rails.env == 'development' && get_database.errors sqlDebug += "<br/><br/><strong style='color:red'>(" + get_database.last_error.to_s + ")</strong>" end if Rails.env == 'development' && ex != '' sqlDebug += "<br/><br/><strong style='color:red'>(" + ex.to_s + ") <pre>" + $!.backtrace.join("\n\n") + "</pre></strong>" end if Rails.env != 'development' if get_database.errors Rails.logger.info get_database.last_error.to_s end if ex != '' Rails.logger.info $!.backtrace.join("\n\n") end end Rails.logger.info sqlDebug sqlDebug end |
#generate_limits ⇒ Object
2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 |
# File 'lib/widget_list.rb', line 2346 def generate_limits() #Pagination # @items['bindVarsLegacy']['LOW'] = @items['rowStart'] @items['bindVarsLegacy']['HIGH'] = @items['rowLimit'] if @sequence.to_i > 1 && ! @items['NEW_SEARCH'] subtractLimit = 0 if get_database.db_type != 'oracle' subtractLimit = @items['rowLimit'] end @items['bindVarsLegacy']['LOW'] = (((@sequence * @items['rowLimit']) - subtractLimit)) if get_database.db_type == 'oracle' @items['bindVarsLegacy']['HIGH'] = ((((@sequence + 1) * @items['rowLimit']))) @items['bindVarsLegacy']['LOW'] = @items['bindVarsLegacy']['LOW'] - @items['rowLimit'] @items['bindVarsLegacy']['HIGH'] = @items['bindVarsLegacy']['HIGH'] - @items['rowLimit'] end end end |
#get_database ⇒ Object
4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 |
# File 'lib/widget_list.rb', line 4663 def get_database if @has_connected.nil? connect end if @is_primary_sequel && @widget_list_sequel_conn.class.name.to_s.split('::').first == 'Sequel' && @current_db_selection == 'primary' || @current_db_selection.nil? @widget_list_sequel_conn.test_connection end if @is_secondary_sequel && @widget_list_sequel_conn2.class.name.to_s.split('::').first == 'Sequel' && @current_db_selection == 'secondary' @widget_list_sequel_conn2.test_connection end case @current_db_selection when 'primary' return (@is_primary_sequel) ? @widget_list_sequel_conn : @widget_list_ar_conn when 'secondary' return (@is_secondary_sequel) ? @widget_list_sequel_conn2 : @widget_list_ar_conn2 else return (@is_primary_sequel) ? @widget_list_sequel_conn : @widget_list_ar_conn end end |
#get_db_type(primary = true) ⇒ Object
4524 4525 4526 |
# File 'lib/widget_list.rb', line 4524 def get_db_type(primary=true) WidgetList::List::get_db_type(primary) end |
#get_grouping_functions ⇒ Object
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 |
# File 'lib/widget_list.rb', line 1866 def get_grouping_functions() #http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions003.htm [ 'AVG(', 'COLLECT(', 'CORR(', 'COUNT(', 'COVAR_POP(', 'COVAR_SAMP(', 'CUME_DIST(', 'DENSE_RANK(', 'FIRST(', 'GROUP_ID(', 'GROUPING_ID(', 'LAST(', 'LISTAGG(', 'MAX(', 'MEDIAN(', 'MIN(', 'PERCENT_RANK(', 'PERCENTILE_CONT(', 'PERCENTILE_DISC(', 'RANK(', 'REGR_SLOPE(', 'REGR_INTERCEPT(', 'REGR_COUNT(', 'REGR_R2(', 'REGR_AVGX(', 'REGR_AVGY(', 'REGR_SXX(', 'REGR_SYY(', 'REGR_SXY(', 'STATS_MINOMIAL_TEST(', 'STATS_CROSSTAB(', 'STATS_F_TEST(', 'STATS_KS_TEST(', 'STATS_MODE(', 'STATS_MW_TEST(', 'STDDEV(', 'STDDEV_POP(', 'STDDEV_SAMP(', 'SUM(', 'SYS_XMLAGG(', 'VAR_POP(', 'VAR_SAMP(', 'VARIANCE(', 'XMLAGG(', ] end |
#get_header_pieces ⇒ Object
2652 2653 2654 |
# File 'lib/widget_list.rb', line 2652 def get_header_pieces() @headerPieces end |
#get_header_px_value ⇒ Object
2648 2649 2650 |
# File 'lib/widget_list.rb', line 2648 def get_header_px_value() @items['titleFontSize'].to_s.include?('px') ? @items['titleFontSize'].to_s : @items['titleFontSize'].to_s + 'px' end |
#get_radius_value ⇒ Object
2636 2637 2638 |
# File 'lib/widget_list.rb', line 2636 def get_radius_value() @items['cornerRadius'].to_s.include?('px') ? @items['cornerRadius'].to_s : @items['cornerRadius'].to_s + 'px' end |
#get_shadow_inset_value ⇒ Object
2640 2641 2642 |
# File 'lib/widget_list.rb', line 2640 def get_shadow_inset_value() @items['shadowInset'].to_s.include?('px') ? @items['shadowInset'].to_s : @items['shadowInset'].to_s + 'px' end |
#get_shadow_spread_value ⇒ Object
2644 2645 2646 |
# File 'lib/widget_list.rb', line 2644 def get_shadow_spread_value() @items['shadowSpread'].to_s.include?('px') ? @items['shadowSpread'].to_s : @items['shadowSpread'].to_s + 'px' end |
#get_total_records ⇒ Object
4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 |
# File 'lib/widget_list.rb', line 4356 def get_total_records() filter = '' fields = {} sql = '' hashed = false if !get_view().empty? sql = WidgetList::Utils::fill({'<!--VIEW-->' => get_view(),'<!--GROUPBY-->' => !@items['groupBy'].empty? ? ' GROUP BY ' + @items['groupBy'] : '' }, @items['statement']['count']['view']) end if $is_mongo @active_record_model = @active_record_model.skip(0) #turn object into Mongoid::Criteria which has all the column definitions needed in _select # # List filters # @mongo_match = [] @items['filter'].each_with_index { |value, key| field = value.to_sym predicate = '' if @items.key?('predicate') && !@items['predicate'][key].nil? && !@items['predicate'][key].empty? && value.to_sym.respond_to?(@items['predicate'][key]) field = field.send(@items['predicate'][key]) predicate = '$' + @items['predicate'][key] end @active_record_model = @active_record_model.where('$and' => [{ field => WidgetList::List.parse_inputs_for_mongo_predicates(@active_record_model, value, predicate, @items['bindVars'][key]) }]) if @items['groupBy'].empty? @mongo_match << { value => WidgetList::List.mysql_to_mongo_predicate(@items['predicate'][key],@items['bindVars'][key],true) } if @items['fields'].key?(value) } if @items.key?('filter') && !@items['filter'].empty? if !@items['groupBy'].empty? if @items['groupBy'].include?(',') criteriaTmp = @items['groupBy'].split_it(',') else criteriaTmp = [@items['groupBy']] end map_groups = {} criteriaTmp.each { |value| map_groups[value] = "$#{value}" } # @group_match = { "group" => {"$group" => { "_id" => map_groups , "cnt" => { "$sum" => 1 } } }, } end else if ! @filter.empty? filter = ' WHERE ' + @filter end sql = WidgetList::Utils::fill({'<!--WHERE-->' => filter}, sql) end if ! sql.empty? || $is_mongo if @items['showPagination'] tmp_match = @group_match if $is_mongo if !tmp_match.nil? tmp_match = @group_match.dup tmp_match = tmp_match.merge({"match" => @mongo_match }) end end cnt = get_database._select( $is_mongo ? 'count' : sql, @items['bindVars'], @items['bindVarsLegacy'], @active_record_model, tmp_match) if cnt > 0 if cnt > get_database.final_results['TOTAL'][0].to_i #sometimes databases and queries run do not count(1) and group properly and instead rows = cnt else rows = get_database.final_results['TOTAL'][0].to_i end else rows = 0 end if rows > 0 @totalRows = rows.to_i end else rows = 1 end else rows = 0 end if @totalRows > 0 @totalPages = (@totalRows.to_f / @items['rowLimit'].to_f).ceil() end rows end |
#get_view ⇒ Object
4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 |
# File 'lib/widget_list.rb', line 4528 def get_view initializing = false if @active_record_model.nil? initializing = true @active_record_model = false end if (@is_primary_sequel && @items['database'] == 'primary') || (@is_secondary_sequel && @items['database'] == 'secondary') return @items['view'] elsif $is_mongo || (@items['view'].respond_to?('scoped') && @items['view'].scoped.respond_to?('to_sql')) @active_record_model = @items['view'].name.constantize if initializing new_columns = [] @items['fields'].each { |column, fieldTitle| if @items['fieldFunction'].key?(column) && !@items['fieldFunction'][column].empty? # fieldFunction's should not have an alias, just the database functions column = @items['fieldFunction'][column] + " " + column end new_columns << column } if @items['fieldsHidden'].class.name == 'Array' && !@items['fieldsHidden'].empty? @items['fieldsHidden'].each { |columnPivot| if !@items['fields'].key?(columnPivot) if @items['fieldFunction'].key?(columnPivot) && !@items['fieldFunction'][columnPivot].empty? # fieldFunction's should not have an alias, just the database functions columnPivot = @items['fieldFunction'][columnPivot] + " " + columnPivot end new_columns << columnPivot end } elsif @items['fieldsHidden'].class.name == 'Hash' && !@items['fieldsHidden'].empty? @items['fieldsHidden'].each { |columnPivot| if !@items['fields'].key?(columnPivot[0]) if @items['fieldFunction'].key?(columnPivot[0]) && !@items['fieldFunction'][columnPivot[0]].empty? # fieldFunction's should not have an alias, just the database functions columnPivot[0] = @items['fieldFunction'][columnPivot[0]] + " " + columnPivot[0] end new_columns << columnPivot[0] end } end if $is_mongo return '' else view = @items['view'].scoped.to_sql sql_from = view[view.index(/FROM/),view.length] view = "SELECT #{new_columns.join(',')} " + sql_from where = '' if !@items['groupBy'].empty? where = '<!--WHERE-->' end return "( #{view} #{where} <!--GROUPBY--> ) a" end else return "" end end |
#render(results = {}) ⇒ Object
pass results of $DATABASE.final_results after running a _select query
2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 |
# File 'lib/widget_list.rb', line 2369 def render(results={}) if @isAdministrating if $_REQUEST.key?('name') return WidgetList::Administration.new.save_and_show_code() elsif $_REQUEST.key?('ajax') && $_REQUEST.key?('model') return WidgetList::Administration.new.ajax_get_field_json($_REQUEST['model']) elsif $_REQUEST.key?('ajax') && $_REQUEST.key?('save') return WidgetList::Administration.new.save_and_show_code() else return WidgetList::Administration.new.show_interface() end end begin if !results.empty? @items['data'] = results end #Get total records for statement validation and pagination # @items['data'].keys.each { |column| @items['fields'][column.downcase] = auto_column_name(column) } if !@items['data'].empty? && @items['fields'].empty? if @items['data'].empty? # Generate count() from database # @totalResultCount = get_total_records() else # Count the items in the passed data # @items['data'].keys.each { |column| @totalResultCount = @items['data'][column].count @totalRowCount = @totalResultCount @totalRows = @totalResultCount break } end build_rows() build_summary_row() build_headers() listJumpUrl = {} listJumpUrl['PAGE_ID'] = @items['pageId'] listJumpUrl['ACTION'] = 'AJAX' listJumpUrl['BUTTON_VALUE'] = @items['buttonVal'] listJumpUrl['LIST_COL_SORT'] = @items['LIST_COL_SORT'] listJumpUrl['LIST_COL_SORT_ORDER'] = @items['LIST_COL_SORT_ORDER'] listJumpUrl['LIST_FILTER_ALL'] = @items['LIST_FILTER_ALL'] listJumpUrl['ROW_LIMIT'] = @items['ROW_LIMIT'] listJumpUrl['LIST_SEQUENCE'] = @sequence listJumpUrl['LIST_NAME'] = @items['name'] listJumpUrl['SQL_HASH'] = @sqlHash if $_REQUEST.key?('switch_grouping') listJumpUrl['switch_grouping'] = $_REQUEST['switch_grouping'] end @templateFill['<!--CORNER_RADIUS-->'] = get_radius_value() @templateFill['<!--BOX_SHADOW-->'] = @items['useBoxShadow'] ? 'box-shadow: <!--SHADOW_INSET--> <!--SHADOW_INSET--> <!--SHADOW_SPREAD--> <!--SHADOW_COLOR-->;' : '' @templateFill['<!--SHADOW_INSET-->'] = get_shadow_inset_value() @templateFill['<!--SHADOW_SPREAD-->'] = get_shadow_spread_value() @templateFill['<!--SHADOW_COLOR-->'] = @items['shadowColor'] @templateFill['<!--BORDER_HEAD_FOOT_TOP-->'] = @items['borderHeadFoot'] ? 'border-top:' + @items['headFootBorderStyle'] + ';' : '' if @items['fontFamily'] @templateFill['<!--FONT-->'] = 'font-family:' + @items['fontFamily'] + ';' end @templateFill['<!--FONT_HEADER-->'] = @items['headerFooterFontSize'] @templateFill['<!--CUSTOM_CONTENT_BOTTOM-->']= @items['customFooter'] @templateFill['<!--CUSTOM_CONTENT_TOP-->'] = @items['customHeader'] @templateFill['<!--WRAP_START-->'] = '' @templateFill['<!--WRAP_END-->'] = '' if !$_REQUEST.key?('BUTTON_VALUE') @templateFill['<!--WRAP_START-->'] = '<div class="widget_list_outer"> <input type="hidden" id="<!--NAME-->_jump_url_original" value="<!--JUMP_URL-->"/>' @templateFill['<!--WRAP_END-->'] = '</div>' end @templateFill['<!--HEADER-->'] = @items['templateHeader'] @templateFill['<!--TABLE_BORDER-->'] = @items['tableBorder'] @templateFill['<!--HEADER_COLOR-->'] = @items['headerBGColor'] @templateFill['<!--FOOTER_COLOR-->'] = @items['footerBGColor'] @templateFill['<!--HEADER_TXT_COLOR-->'] = @items['headerFontColor'] @templateFill['<!--FOOTER_TXT_COLOR-->'] = @items['footerFontColor'] @templateFill['<!--TITLE-->'] = @items['title'] @templateFill['<!--CLASS-->'] = @items['class'] if @totalRowCount > 0 @templateFill['<!--INLINE_STYLE-->'] = '' @templateFill['<!--TABLE_CLASS-->'] = @items['tableclass'] else @templateFill['<!--INLINE_STYLE-->'] = 'table-layout:auto;' end #Filter form # if @items['showSearch'] === true if ! @items['templateFilter'].empty? @templateFill['<!--FILTER_HEADER-->'] = @items['templateFilter'] else @templateFill['<!--FILTER_HEADER-->'] = '' if !$_REQUEST.key?('search_filter') && !@isJumpingList #Search page url # searchUrl = '' searchVal = '' if ! @items['buttonVal'].empty? searchVal = @items['buttonVal'] else searchVal = @items['name'] end filterParameters = {} filterParameters['BUTTON_VALUE'] = searchVal filterParameters['PAGE_ID'] = @items['pageId'] filterParameters['LIST_NAME'] = @items['name'] filterParameters['SQL_HASH'] = @sqlHash @items['carryOverRequsts'].each { |value| if $_REQUEST.key?(value) filterParameters[value] = $_REQUEST[value] end } searchUrl = WidgetList::Utils::build_url(@items['pageId'], filterParameters, (!$_REQUEST.key?('BUTTON_VALUE'))) list_search = {} # # Search value # list_search['value'] = '' if @items['searchSession'] if $_SESSION.key?('SEARCH_FILTER') && !$_SESSION['SEARCH_FILTER'].nil? && $_SESSION['SEARCH_FILTER'].key?(@items['name']) list_search['value'] = $_SESSION['SEARCH_FILTER'][@items['name']] end end # # Search Input Field # list_search['list-search'] = true list_search['width'] = '500' list_search['input_class'] = 'info-input' list_search['title'] = @items['searchTitle'] list_search['id'] = 'list_search_id_' + @items['name'] list_search['name'] = 'list_search_name_' + @items['name'] list_search['class'] = 'inputOuter widget-search-outer ' + @items['name'].downcase + '-search' list_search['search_ahead'] = { 'url' => searchUrl, 'skip_queue' => false, 'target' => @items['name'], 'search_form' => @items['listSearchForm'], 'onkeyup' => (! @items['searchOnkeyup'].empty?) ? WidgetList::Utils::fill({'<!--URL-->'=>searchUrl, '<!--TARGET-->' => @items['name'], '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll']}, @items['searchOnkeyup'] + '<!--FUNCTION_ALL-->') : '' } fillRansack = {} if @items['ransackSearch'] != false fillRansack['<!--RANSACK-->'] = ActionController::Base.new.render_to_string(:partial => 'widget_list/ransack_fields', :locals => { 'search_object' => @items['ransackSearch'], 'url' => '--JUMP_URL--'}) end @headerPieces['searchBar'] = WidgetList::Utils::fill(fillRansack,WidgetList::Widgets::(list_search)) @templateFill['<!--FILTER_HEADER-->'] = @headerPieces['searchBar'] end # # Grouping box # if ! @items['groupByItems'].empty? list_group = {} list_group['arrow_action'] = 'var stub;' list_group['readonly'] = true if @items['groupBySelected'] list_group['value'] = @items['groupBySelected'] elsif $_REQUEST.key?('group_row_id') tmp = $_REQUEST['group_row_id'].gsub(@items['name'] + '_row_','') if Float(tmp.to_i) != nil list_group['value'] = @items['groupByItems'][tmp.to_i - 1] end else list_group['value'] = @items['groupByItems'][0] end list_group['style'] = 'cursor:pointer;margin-left:5px;' list_group['input_style'] = 'cursor:pointer;' list_group['outer_onclick'] = 'ToggleAdvancedSearch(this);SelectBoxResetSelectedRow(\'' + @items['name'] + '\');' list_group['list-search'] = false list_group['width'] = '200' #hard code for now. needs to be dynamic based on max str length if this caller is made into a "WidgetFakeSelect" list_group['id'] = 'list_group_id_' + @items['name'] list_group['name'] = 'list_group_name_' + @items['name'] list_group['class'] = 'inputOuter widget-search-outer ' + @items['name'].downcase + '-group' className = '' groupRows = [] if !@items['groupBySelected'] className = 'widget-search-results-row-selected' end num = 1 @items['groupByItems'].each { |grouping| if @items['groupBySelected'] && @items['groupBySelected'] === grouping className = 'widget-search-results-row-selected' end groupRows << '<div class="widget-search-results-row ' + className + '" id="' + @items['name'] + '_row_' + num.to_s + '" title="' + grouping + '" onmouseover="jQuery(\'.widget-search-results-row\').removeClass(\'widget-search-results-row-selected\')" onclick="SelectBoxSetValue(\'' + grouping + '\',\'' + @items['name'] + '\');' + @items['groupByClick'] + '">' + grouping + '</div>' className = '' num = num + 1 } list_group['search_ahead'] = { 'skip_queue' => false, 'search_form'=> ' <div id="advanced-search-container" style="height:100% !important;"> ' + groupRows.join("\n") + ' </div>' } if !@templateFill.key?('<!--FILTER_HEADER-->') @templateFill['<!--FILTER_HEADER-->'] = '' end @headerPieces['groupByItems'] = '<div class="fake-select ' + @items['name'] + '-group-by"><div class="label">' + @items['groupByLabel'] + ':</div> ' + WidgetList::Widgets::(list_group) + '</div>' @templateFill['<!--FILTER_HEADER-->'] += @headerPieces['groupByItems'] end if @items['showExport'] @headerPieces['exportButton'] = '<span class="' + @items['name'] + '-export">' + WidgetList::Widgets::(@items['exportButtonTitle'], { 'onclick' => 'ListExport(\'' + @items['name'] + '\');' , 'innerClass' => @items['defaultButtonClass'] }, true) + '</span>' @templateFill['<!--FILTER_HEADER-->'] += @headerPieces['exportButton'] end end end @templateFill['<!--NAME-->'] = @items['name'] @templateFill['<!--JUMP_URL-->'] = WidgetList::Utils::build_url(@items['pageId'],listJumpUrl,(!$_REQUEST.key?('BUTTON_VALUE'))) @templateFill['--JUMP_URL--'] = @templateFill['<!--JUMP_URL-->'] @templateFill['<!--JUMP_URL_NAME-->'] = @items['name'] + '_jump_url' rescue Exception => e out = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output(e) + @items['noDataMessage'] + '</div></td></tr>' if !@templateFill.key?('<!--DATA-->') @templateFill['<!--DATA-->'] = out else @templateFill['<!--DATA-->'] += out end end if $_REQUEST.key?('export_widget_list') csv = '' @csv.each{ |v| csv += v.to_csv } return csv else return WidgetList::Utils::fill(@templateFill, @items['template']) end end |
#skip_column(fieldName) ⇒ Object
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 |
# File 'lib/widget_list.rb', line 2119 def skip_column(fieldName) skip = false (@items['inputs']||{}).each { |k,v| if fieldName == k skip = true end } if @items['buttons'].key?(fieldName) skip = true end return skip end |
#strip_aliases(name = '') ⇒ Object
4308 4309 4310 4311 |
# File 'lib/widget_list.rb', line 4308 def strip_aliases(name='') name = (name.include?(' ') ? name.split(' ').last : name) ((name.include?('.')) ? name.split('.').last.gsub(/'||"/,'') : name.gsub(/'||"/,'')) end |
#tick_field ⇒ Object
2133 2134 2135 2136 2137 2138 2139 2140 |
# File 'lib/widget_list.rb', line 2133 def tick_field() case get_database.db_type when 'postgres','mongo','oracle' '' else '`' end end |