glimmer-dsl-opal 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2989fcd48ddac2b782271cebca14b5a7615926251c14f2aef3fe878d177f7e41
4
- data.tar.gz: 7001fa83285f8e16bf5ba5a86004963324f271a5a795c6c45b0aa71c5fd53a3c
3
+ metadata.gz: 15339e6707f761011f074d030dc58a41733c3ea249da444745c1c6696ab90468
4
+ data.tar.gz: 440722c63a85a92c02dac9a0955bcb5b26d620be1338727521674d63a3d5c9b6
5
5
  SHA512:
6
- metadata.gz: e24b36f65ca89e2e4880b81ae6ac6fba81c4a1ae2c832a87e43a6401ee6f90b2014a223cac2c218374dc895cfece65c5c145ed9a637256310f1b3a7fac9e3e2b
7
- data.tar.gz: d0f249102835911d3eb48f15ac87303376c935b54f17dd4f94ff5ab4db0d8ac6f780ea49ed8cd3c98e52d11c5dbad6975f34635f33f9064f26adca1dee47166e
6
+ metadata.gz: 7daddcebb68f6d612c011f2d99c3af01073f3740a3fb82bd9a4a1bd96c748db358c61c6d3ad1502aa23f5061fb8041921c680a729bf39d0fa971cfa55059e4d7
7
+ data.tar.gz: 15cea650eacfb8dbb05dc4892754b160cd0ad5ec0d5e5c0a5c87636e1fbc69f43d9a3fcc250edd3c9febc2bae1ab0a3ecf9fe47f295363de9b13cc47e86debc3
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.7.0
4
+
5
+ - Hello, Table! Sample
6
+ - `table` :editable style to enable auto-editing
7
+ - `table` `header_visible` property to hide header when false
8
+ - `table` `item_count` property to set minimum item count (fill empty rows when below in table items)
9
+ - `table` selection data-binding
10
+ - `table` built-in sorting support
11
+ - `table_column` left text alignment and padding of 5px by default
12
+ - `table` sort property and direction in GUI
13
+ - `table_column` sort_property
14
+ - `table_column` sort_by block
15
+ - `table_column` sort block
16
+ - `table` default sort via property, compare block, and property block
17
+ - `table` additional sort properties
18
+ - Prevent `table` unnecessary updates by comparing data to previous data and not updating when it's the same
19
+ - Contact Manager sample support for on_key_pressed in text widgets upon hitting ENTER
20
+ - Fix issue with edit table item error on sorting table
21
+
3
22
  ## 0.6.1
4
23
 
5
24
  - Fix issue with rendering date_time without a block
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal (Auto-Webify Desktop Apps)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.7.0 (Pure Ruby Web GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-opal.svg)](http://badge.fury.io/rb/glimmer-dsl-opal)
3
3
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
5
5
  ### You can finally live in pure Ruby land on the web!
6
6
 
7
- [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Opal](https://opalrb.com/) is an experimental proof-of-concept web GUI adapter for [Glimmer](https://github.com/AndyObtiva/glimmer) desktop apps (i.e. apps built with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)). It webifies them via [Rails](https://rubyonrails.org/), allowing Ruby desktop apps to run on the web via [Opal Ruby](https://opalrb.com/) without changing a line of code. Apps may then be custom-styled by web designers for the web with standard CSS.
7
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Opal](https://opalrb.com/) is an alpha [gem](https://rubygems.org/gems/glimmer-dsl-opal) that enables building web GUI in pure Ruby via [Opal](https://opalrb.com/) on [Rails](https://rubyonrails.org/).
8
+
9
+ Use in one of two ways:
10
+ - **Direct:** build the GUI of web apps with the same friendly desktop GUI Ruby syntax as [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt), thus requiring a lot less code than web technologies that is in pure Ruby and avoiding opaque web concepts like 'render' and 'reactive'. No HTML/JS/CSS skills are even required. Web designers may be involved with CSS styling only if needed.
11
+ - **Adapter:** Auto-webify [Glimmer](https://github.com/AndyObtiva/glimmer) desktop apps (i.e. apps built with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)) via [Opal](https://opalrb.com/) on [Rails](https://rubyonrails.org/) without changing a line of code. Apps may then be custom-styled by web designers for the web with standard CSS.
8
12
 
9
13
  Glimmer DSL for Opal successfully reuses the entire [Glimmer](https://github.com/AndyObtiva/glimmer) core DSL engine in [Opal Ruby](https://opalrb.com/) inside a web browser, and as such inherits the full range of powerful Glimmer desktop [data-binding](https://github.com/AndyObtiva/glimmer#data-binding) capabilities for the web.
10
14
 
11
- NOTE: Alpha Version 0.6.1 only supports bare-minimum capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
15
+ NOTE: Alpha Version 0.7.0 only supports bare-minimum capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
12
16
 
13
17
  Hello:
14
18
 
@@ -27,6 +31,7 @@ Hello:
27
31
  - [Hello, Checkbox!](#hello-checkbox)
28
32
  - [Hello, Checkbox Group!](#hello-checkbox-group)
29
33
  - [Hello, Date Time!](#hello-date-time)
34
+ - [Hello, Table!](#hello-table)
30
35
 
31
36
  Elaborate:
32
37
 
@@ -46,12 +51,14 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
46
51
 
47
52
  ## Background
48
53
 
49
- The idea behind Glimmer DSL for Opal is that you start by having a [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) desktop app that communicates with a Rails API for any web/cloud concerns. The GUI DSL is very simple in Glimmer DSL for SWT. Once the app is built. You simply embed it in a Rails app as a one line require statement after adding the Glimmer DSL for Opal gem, and BOOM, it just works on the web inside a web browser with the same server/client communication you had in the desktop app (I am working on adding minimal support for net/http in Opal so that desktop apps that use it continue to work in a web browser).
54
+ The original idea behind Glimmer DSL for Opal was that you start by having a [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) desktop app that communicates with a Rails API for any web/cloud concerns. The GUI DSL is very simple in Glimmer DSL for SWT. Once the app is built. You simply embed it in a Rails app as a one line require statement after adding the Glimmer DSL for Opal gem, and BOOM, it just works on the web inside a web browser with the same server/client communication you had in the desktop app (I am working on adding minimal support for net/http in Opal so that desktop apps that use it continue to work in a web browser).
50
55
 
51
56
  Part of the idea is that web browsers just render GUI widgets similar to those of a desktop app (after all a web browser is a desktop app), so whether you run your GUI on the desktop or on the web should just be a low-level concern, hopefully automated completely with Glimmer DSL for Opal.
52
57
 
53
58
  Last but not least, you would likely want some special branding on the web, so you can push that off to a web designer who would be more than happy to do the web graphic design and customize the look and feel with pure CSS (no need for programming with Ruby or JavaScript). This enables a clean separation of concerns and distribution of tasks among developers and designers, let alone saving effort on the web GUI by reusing the desktop GUI as a base right off the bat.
54
59
 
60
+ Alternatively, web developers may directly use [Glimmer DSL for Opal](https://rubygems.org/gems/glimmer-dsl-opal) to build the GUI of web apps since it is as simple as desktop development, thus requiring a lot less code that is in pure Ruby only (as demonstrated in examples below) and avoiding opaque web concepts like 'render' and 'reactive' due to treating GUI as persistent just like desktop apps do. No HTML/JS/CSS skills are even required. Still, web designers may be involved with CSS only if needed, thanks to the clean semantic markup [Glimmer DSL for Opal](https://rubygems.org/gems/glimmer-dsl-opal) produces.
61
+
55
62
  ## Supported Glimmer DSL Keywords
56
63
 
57
64
  The following keywords from [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) have partial support in Opal:
@@ -126,7 +133,7 @@ Add the following to `Gemfile`:
126
133
  gem 'opal-rails', '~> 1.1.2'
127
134
  gem 'opal-async', '~> 1.2.0'
128
135
  gem 'opal-jquery', '~> 0.4.4'
129
- gem 'glimmer-dsl-opal', '~> 0.6.1'
136
+ gem 'glimmer-dsl-opal', '~> 0.7.0'
130
137
  gem 'glimmer-dsl-xml', '~> 1.1.0', require: false
131
138
  gem 'glimmer-dsl-css', '~> 1.1.0', require: false
132
139
 
@@ -1482,6 +1489,285 @@ You should see "Hello, Date Time!"
1482
1489
 
1483
1490
  ![Glimmer DSL for Opal Hello Date Time](images/glimmer-dsl-opal-hello-date-time.png)
1484
1491
 
1492
+ #### Hello, Table!
1493
+
1494
+ Note: This [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) sample has near-complete support, but is missing table context menus and table editing at the moment.
1495
+
1496
+ Add the following require statement to `app/assets/javascripts/application.rb`
1497
+
1498
+ ```ruby
1499
+ require 'glimmer-dsl-opal/samples/hello/hello_table'
1500
+ ```
1501
+
1502
+ Or add the Glimmer code directly if you prefer to play around with it:
1503
+
1504
+ ```ruby
1505
+ class HelloTable
1506
+ class BaseballGame
1507
+ class << self
1508
+ attr_accessor :selected_game
1509
+
1510
+ def all_playoff_games
1511
+ @all_playoff_games ||= {
1512
+ 'NLDS' => [
1513
+ new(Time.new(2037, 10, 6, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers', 'Free Bobblehead'),
1514
+ new(Time.new(2037, 10, 7, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers'),
1515
+ new(Time.new(2037, 10, 8, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
1516
+ new(Time.new(2037, 10, 9, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
1517
+ new(Time.new(2037, 10, 10, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 'Free Umbrella'),
1518
+ new(Time.new(2037, 10, 6, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals', 'Free Bobblehead'),
1519
+ new(Time.new(2037, 10, 7, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals'),
1520
+ new(Time.new(2037, 10, 8, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
1521
+ new(Time.new(2037, 10, 9, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
1522
+ new(Time.new(2037, 10, 10, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds', 'Free Umbrella'),
1523
+ ],
1524
+ 'ALDS' => [
1525
+ new(Time.new(2037, 10, 6, 12, 0), 'New York Yankees', 'Boston Red Sox', 'Free Bobblehead'),
1526
+ new(Time.new(2037, 10, 7, 12, 0), 'New York Yankees', 'Boston Red Sox'),
1527
+ new(Time.new(2037, 10, 8, 12, 0), 'Boston Red Sox', 'New York Yankees'),
1528
+ new(Time.new(2037, 10, 9, 12, 0), 'Boston Red Sox', 'New York Yankees'),
1529
+ new(Time.new(2037, 10, 10, 12, 0), 'Boston Red Sox', 'New York Yankees', 'Free Umbrella'),
1530
+ new(Time.new(2037, 10, 6, 18, 0), 'Houston Astros', 'Cleveland Indians', 'Free Bobblehead'),
1531
+ new(Time.new(2037, 10, 7, 18, 0), 'Houston Astros', 'Cleveland Indians'),
1532
+ new(Time.new(2037, 10, 8, 18, 0), 'Cleveland Indians', 'Houston Astros'),
1533
+ new(Time.new(2037, 10, 9, 18, 0), 'Cleveland Indians', 'Houston Astros'),
1534
+ new(Time.new(2037, 10, 10, 18, 0), 'Cleveland Indians', 'Houston Astros', 'Free Umbrella'),
1535
+ ],
1536
+ 'NLCS' => [
1537
+ new(Time.new(2037, 10, 12, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Towel'),
1538
+ new(Time.new(2037, 10, 13, 12, 0), 'Chicago Cubs', 'Cincinnati Reds'),
1539
+ new(Time.new(2037, 10, 14, 12, 0), 'Cincinnati Reds', 'Chicago Cubs'),
1540
+ new(Time.new(2037, 10, 15, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
1541
+ new(Time.new(2037, 10, 16, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
1542
+ new(Time.new(2037, 10, 17, 18, 0), 'Chicago Cubs', 'Cincinnati Reds'),
1543
+ new(Time.new(2037, 10, 18, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Poncho'),
1544
+ ],
1545
+ 'ALCS' => [
1546
+ new(Time.new(2037, 10, 12, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Towel'),
1547
+ new(Time.new(2037, 10, 13, 12, 0), 'Houston Astros', 'Boston Red Sox'),
1548
+ new(Time.new(2037, 10, 14, 12, 0), 'Boston Red Sox', 'Houston Astros'),
1549
+ new(Time.new(2037, 10, 15, 18, 0), 'Boston Red Sox', 'Houston Astros'),
1550
+ new(Time.new(2037, 10, 16, 18, 0), 'Boston Red Sox', 'Houston Astros'),
1551
+ new(Time.new(2037, 10, 17, 18, 0), 'Houston Astros', 'Boston Red Sox'),
1552
+ new(Time.new(2037, 10, 18, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Poncho'),
1553
+ ],
1554
+ 'World Series' => [
1555
+ new(Time.new(2037, 10, 20, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free Baseball Cap'),
1556
+ new(Time.new(2037, 10, 21, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
1557
+ new(Time.new(2037, 10, 22, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
1558
+ new(Time.new(2037, 10, 23, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
1559
+ new(Time.new(2037, 10, 24, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
1560
+ new(Time.new(2037, 10, 25, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
1561
+ new(Time.new(2037, 10, 26, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free World Series Polo'),
1562
+ ]
1563
+ }
1564
+ end
1565
+
1566
+ def playoff_type
1567
+ @playoff_type ||= 'World Series'
1568
+ end
1569
+
1570
+ def playoff_type=(new_playoff_type)
1571
+ @playoff_type = new_playoff_type
1572
+ self.schedule=(all_playoff_games[@playoff_type])
1573
+ end
1574
+
1575
+ def playoff_type_options
1576
+ all_playoff_games.keys
1577
+ end
1578
+
1579
+ def schedule
1580
+ @schedule ||= all_playoff_games[playoff_type]
1581
+ end
1582
+
1583
+ def schedule=(new_schedule)
1584
+ @schedule = new_schedule
1585
+ end
1586
+ end
1587
+
1588
+ include Glimmer
1589
+ include Glimmer::DataBinding::ObservableModel
1590
+
1591
+ TEAM_BALLPARKS = {
1592
+ 'Boston Red Sox' => 'Fenway Park',
1593
+ 'Chicago Cubs' => 'Wrigley Field',
1594
+ 'Cincinnati Reds' => 'Great American Ball Park',
1595
+ 'Cleveland Indians' => 'Progressive Field',
1596
+ 'Houston Astros' => 'Minute Maid Park',
1597
+ 'Milwaukee Brewers' => 'Miller Park',
1598
+ 'New York Yankees' => 'Yankee Stadium',
1599
+ 'St Louis Cardinals' => 'Busch Stadium',
1600
+ }
1601
+
1602
+ attr_accessor :date_time, :home_team, :away_team, :ballpark, :promotion
1603
+
1604
+ def initialize(date_time, home_team, away_team, promotion = 'N/A')
1605
+ self.date_time = date_time
1606
+ self.home_team = home_team
1607
+ self.away_team = away_team
1608
+ self.promotion = promotion
1609
+ observe(self, :date_time) do |new_value|
1610
+ notify_observers(:game_date)
1611
+ notify_observers(:game_time)
1612
+ end
1613
+ end
1614
+
1615
+ def home_team=(home_team_value)
1616
+ if home_team_value != away_team
1617
+ @home_team = home_team_value
1618
+ self.ballpark = TEAM_BALLPARKS[@home_team]
1619
+ end
1620
+ end
1621
+
1622
+ def away_team=(away_team_value)
1623
+ if away_team_value != home_team
1624
+ @away_team = away_team_value
1625
+ end
1626
+ end
1627
+
1628
+ def date
1629
+ Date.new(date_time.year, date_time.month, date_time.day)
1630
+ end
1631
+
1632
+ def time
1633
+ Time.new(0, 1, 1, date_time.hour, date_time.min, date_time.sec, '+00:00')
1634
+ end
1635
+
1636
+ def game_date
1637
+ date_time.strftime("%m/%d/%Y")
1638
+ end
1639
+
1640
+ def game_time
1641
+ date_time.strftime("%I:%M %p")
1642
+ end
1643
+
1644
+ def home_team_options
1645
+ TEAM_BALLPARKS.keys
1646
+ end
1647
+
1648
+ def away_team_options
1649
+ TEAM_BALLPARKS.keys
1650
+ end
1651
+
1652
+ def ballpark_options
1653
+ [TEAM_BALLPARKS[@home_team], TEAM_BALLPARKS[@away_team]]
1654
+ end
1655
+
1656
+ def to_s
1657
+ "#{home_team} vs #{away_team} at #{ballpark} on #{game_date} #{game_time}"
1658
+ end
1659
+
1660
+ def book!
1661
+ "Thank you for booking #{to_s}"
1662
+ end
1663
+ end
1664
+
1665
+ include Glimmer
1666
+
1667
+ def launch
1668
+ shell {
1669
+ grid_layout
1670
+
1671
+ text 'Hello, Table!'
1672
+
1673
+ label {
1674
+ layout_data :center, :center, true, false
1675
+
1676
+ text 'Baseball Playoff Schedule'
1677
+ font height: 30, style: :bold
1678
+ }
1679
+
1680
+ combo(:read_only) {
1681
+ layout_data :center, :center, true, false
1682
+ selection bind(BaseballGame, :playoff_type)
1683
+ font height: 16
1684
+ }
1685
+
1686
+ table(:editable) { |table_proxy|
1687
+ layout_data :fill, :fill, true, true
1688
+
1689
+ table_column {
1690
+ text 'Game Date'
1691
+ width 150
1692
+ sort_property :date # ensure sorting by real date value (not `game_date` string specified in items below)
1693
+ }
1694
+ table_column {
1695
+ text 'Game Time'
1696
+ width 150
1697
+ sort_property :time # ensure sorting by real time value (not `game_time` string specified in items below)
1698
+ }
1699
+ table_column {
1700
+ text 'Ballpark'
1701
+ width 180
1702
+ }
1703
+ table_column {
1704
+ text 'Home Team'
1705
+ width 150
1706
+ }
1707
+ table_column {
1708
+ text 'Away Team'
1709
+ width 150
1710
+ }
1711
+ table_column {
1712
+ text 'Promotion'
1713
+ width 150
1714
+ # default text editor is used here
1715
+ }
1716
+
1717
+ # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
1718
+ items bind(BaseballGame, :schedule), column_properties(:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion)
1719
+
1720
+ # Data-bind table selection
1721
+ selection bind(BaseballGame, :selected_game)
1722
+
1723
+ # Default initial sort property
1724
+ sort_property :date
1725
+
1726
+ # Sort by these additional properties after handling sort by the column the user clicked
1727
+ additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
1728
+ }
1729
+
1730
+ button {
1731
+ text 'Book Selected Game'
1732
+ layout_data :center, :center, true, false
1733
+ font height: 16
1734
+ enabled bind(BaseballGame, :selected_game)
1735
+
1736
+ on_widget_selected {
1737
+ book_selected_game
1738
+ }
1739
+ }
1740
+ }.open
1741
+ end
1742
+
1743
+ def book_selected_game
1744
+ message_box {
1745
+ text 'Baseball Game Booked!'
1746
+ message BaseballGame.selected_game.book!
1747
+ }.open
1748
+ end
1749
+ end
1750
+
1751
+ HelloTable.new.launch
1752
+ ```
1753
+
1754
+ Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
1755
+
1756
+ ![Glimmer DSL for SWT Hello Table](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-hello-table.png)
1757
+
1758
+ Glimmer app on the web (using `glimmer-dsl-opal` gem):
1759
+
1760
+ Start the Rails server:
1761
+ ```
1762
+ rails s
1763
+ ```
1764
+
1765
+ Visit `http://localhost:3000`
1766
+
1767
+ You should see "Hello, Date Time!"
1768
+
1769
+ ![Glimmer DSL for Opal Hello Table](images/glimmer-dsl-opal-hello-table.png)
1770
+
1485
1771
  ### Elaborate Samples
1486
1772
 
1487
1773
  #### Login
@@ -2223,7 +2509,7 @@ Visit `http://localhost:3000`
2223
2509
 
2224
2510
  You should see "Glimmer Calculator"
2225
2511
 
2226
- ![Glimmer Calculator Opal](https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-calculator/master/glimmer-cs-calculator-screenshot-opal.png)
2512
+ [![Glimmer Calculator Opal](https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-calculator/master/glimmer-cs-calculator-screenshot-opal.png)](http://glimmer-cs-calculator-server.herokuapp.com)
2227
2513
 
2228
2514
  Here is an Apple Calculator CSS themed version (with [CSS only](https://github.com/AndyObtiva/glimmer-cs-calculator/blob/master/server/glimmer-cs-calculator-server/app/assets/stylesheets/welcomes_apple.scss), no app code changes):
2229
2515
 
@@ -2231,7 +2517,7 @@ Visit http://glimmer-cs-calculator-server.herokuapp.com/welcomes/apple
2231
2517
 
2232
2518
  You should see "Apple Calculator Theme"
2233
2519
 
2234
- ![Glimmer Calculator Opal Apple Calculator Theme](https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-calculator/master/glimmer-cs-calculator-screenshot-opal-apple.png)
2520
+ [![Glimmer Calculator Opal Apple Calculator Theme](https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-calculator/master/glimmer-cs-calculator-screenshot-opal-apple.png)](http://glimmer-cs-calculator-server.herokuapp.com/welcomes/apple)
2235
2521
 
2236
2522
  ## Help
2237
2523
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -10,7 +10,7 @@ if RUBY_ENGINE == 'opal'
10
10
 
11
11
  # $LOAD_PATH.unshift(GLIMMER_DSL_OPAL_MISSING) # missing Ruby classes/methods
12
12
  # TODO look into making append_path work (causing some trouble right now)
13
- # Opal.append_path pd File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
13
+ # Opal.append_path File.expand_path('../glimmer-dsl-opal/missing', __FILE__)
14
14
  # Opal.append_path GLIMMER_DSL_OPAL_MISSING
15
15
 
16
16
  require 'opal-parser'
@@ -41,7 +41,6 @@ if RUBY_ENGINE == 'opal'
41
41
  # end
42
42
 
43
43
  require 'glimmer/dsl/opal/dsl'
44
- require 'glimmer/data_binding/ext/observable_model'
45
44
 
46
45
  require 'glimmer-dsl-xml'
47
46
  require 'glimmer-dsl-css'
@@ -41,6 +41,17 @@ class Date
41
41
  end
42
42
 
43
43
  class Time
44
+ class << self
45
+ alias new_original new
46
+ def new(*args)
47
+ if args.size >= 7
48
+ puts "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!"
49
+ args = args[0...6]
50
+ end
51
+ new_original(*args)
52
+ end
53
+ end
54
+
44
55
  def to_datetime
45
56
  # TODO support timezone
46
57
  DateTime.new(year, month, day, hour, min, sec)
@@ -0,0 +1,283 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class HelloTable
23
+ class BaseballGame
24
+ class << self
25
+ attr_accessor :selected_game
26
+
27
+ def all_playoff_games
28
+ @all_playoff_games ||= {
29
+ 'NLDS' => [
30
+ new(Time.new(2037, 10, 6, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers', 'Free Bobblehead'),
31
+ new(Time.new(2037, 10, 7, 12, 0), 'Chicago Cubs', 'Milwaukee Brewers'),
32
+ new(Time.new(2037, 10, 8, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
33
+ new(Time.new(2037, 10, 9, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs'),
34
+ new(Time.new(2037, 10, 10, 12, 0), 'Milwaukee Brewers', 'Chicago Cubs', 'Free Umbrella'),
35
+ new(Time.new(2037, 10, 6, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals', 'Free Bobblehead'),
36
+ new(Time.new(2037, 10, 7, 18, 0), 'Cincinnati Reds', 'St Louis Cardinals'),
37
+ new(Time.new(2037, 10, 8, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
38
+ new(Time.new(2037, 10, 9, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds'),
39
+ new(Time.new(2037, 10, 10, 18, 0), 'St Louis Cardinals', 'Cincinnati Reds', 'Free Umbrella'),
40
+ ],
41
+ 'ALDS' => [
42
+ new(Time.new(2037, 10, 6, 12, 0), 'New York Yankees', 'Boston Red Sox', 'Free Bobblehead'),
43
+ new(Time.new(2037, 10, 7, 12, 0), 'New York Yankees', 'Boston Red Sox'),
44
+ new(Time.new(2037, 10, 8, 12, 0), 'Boston Red Sox', 'New York Yankees'),
45
+ new(Time.new(2037, 10, 9, 12, 0), 'Boston Red Sox', 'New York Yankees'),
46
+ new(Time.new(2037, 10, 10, 12, 0), 'Boston Red Sox', 'New York Yankees', 'Free Umbrella'),
47
+ new(Time.new(2037, 10, 6, 18, 0), 'Houston Astros', 'Cleveland Indians', 'Free Bobblehead'),
48
+ new(Time.new(2037, 10, 7, 18, 0), 'Houston Astros', 'Cleveland Indians'),
49
+ new(Time.new(2037, 10, 8, 18, 0), 'Cleveland Indians', 'Houston Astros'),
50
+ new(Time.new(2037, 10, 9, 18, 0), 'Cleveland Indians', 'Houston Astros'),
51
+ new(Time.new(2037, 10, 10, 18, 0), 'Cleveland Indians', 'Houston Astros', 'Free Umbrella'),
52
+ ],
53
+ 'NLCS' => [
54
+ new(Time.new(2037, 10, 12, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Towel'),
55
+ new(Time.new(2037, 10, 13, 12, 0), 'Chicago Cubs', 'Cincinnati Reds'),
56
+ new(Time.new(2037, 10, 14, 12, 0), 'Cincinnati Reds', 'Chicago Cubs'),
57
+ new(Time.new(2037, 10, 15, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
58
+ new(Time.new(2037, 10, 16, 18, 0), 'Cincinnati Reds', 'Chicago Cubs'),
59
+ new(Time.new(2037, 10, 17, 18, 0), 'Chicago Cubs', 'Cincinnati Reds'),
60
+ new(Time.new(2037, 10, 18, 12, 0), 'Chicago Cubs', 'Cincinnati Reds', 'Free Poncho'),
61
+ ],
62
+ 'ALCS' => [
63
+ new(Time.new(2037, 10, 12, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Towel'),
64
+ new(Time.new(2037, 10, 13, 12, 0), 'Houston Astros', 'Boston Red Sox'),
65
+ new(Time.new(2037, 10, 14, 12, 0), 'Boston Red Sox', 'Houston Astros'),
66
+ new(Time.new(2037, 10, 15, 18, 0), 'Boston Red Sox', 'Houston Astros'),
67
+ new(Time.new(2037, 10, 16, 18, 0), 'Boston Red Sox', 'Houston Astros'),
68
+ new(Time.new(2037, 10, 17, 18, 0), 'Houston Astros', 'Boston Red Sox'),
69
+ new(Time.new(2037, 10, 18, 12, 0), 'Houston Astros', 'Boston Red Sox', 'Free Poncho'),
70
+ ],
71
+ 'World Series' => [
72
+ new(Time.new(2037, 10, 20, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free Baseball Cap'),
73
+ new(Time.new(2037, 10, 21, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
74
+ new(Time.new(2037, 10, 22, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
75
+ new(Time.new(2037, 10, 23, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
76
+ new(Time.new(2037, 10, 24, 18, 0), 'Boston Red Sox', 'Chicago Cubs'),
77
+ new(Time.new(2037, 10, 25, 18, 0), 'Chicago Cubs', 'Boston Red Sox'),
78
+ new(Time.new(2037, 10, 26, 18, 0), 'Chicago Cubs', 'Boston Red Sox', 'Free World Series Polo'),
79
+ ]
80
+ }
81
+ end
82
+
83
+ def playoff_type
84
+ @playoff_type ||= 'World Series'
85
+ end
86
+
87
+ def playoff_type=(new_playoff_type)
88
+ @playoff_type = new_playoff_type
89
+ self.schedule=(all_playoff_games[@playoff_type])
90
+ end
91
+
92
+ def playoff_type_options
93
+ all_playoff_games.keys
94
+ end
95
+
96
+ def schedule
97
+ @schedule ||= all_playoff_games[playoff_type]
98
+ end
99
+
100
+ def schedule=(new_schedule)
101
+ @schedule = new_schedule
102
+ end
103
+ end
104
+
105
+ include Glimmer
106
+ include Glimmer::DataBinding::ObservableModel
107
+
108
+ TEAM_BALLPARKS = {
109
+ 'Boston Red Sox' => 'Fenway Park',
110
+ 'Chicago Cubs' => 'Wrigley Field',
111
+ 'Cincinnati Reds' => 'Great American Ball Park',
112
+ 'Cleveland Indians' => 'Progressive Field',
113
+ 'Houston Astros' => 'Minute Maid Park',
114
+ 'Milwaukee Brewers' => 'Miller Park',
115
+ 'New York Yankees' => 'Yankee Stadium',
116
+ 'St Louis Cardinals' => 'Busch Stadium',
117
+ }
118
+
119
+ attr_accessor :date_time, :home_team, :away_team, :ballpark, :promotion
120
+
121
+ def initialize(date_time, home_team, away_team, promotion = 'N/A')
122
+ self.date_time = date_time
123
+ self.home_team = home_team
124
+ self.away_team = away_team
125
+ self.promotion = promotion
126
+ observe(self, :date_time) do |new_value|
127
+ notify_observers(:game_date)
128
+ notify_observers(:game_time)
129
+ end
130
+ end
131
+
132
+ def home_team=(home_team_value)
133
+ if home_team_value != away_team
134
+ @home_team = home_team_value
135
+ self.ballpark = TEAM_BALLPARKS[@home_team]
136
+ end
137
+ end
138
+
139
+ def away_team=(away_team_value)
140
+ if away_team_value != home_team
141
+ @away_team = away_team_value
142
+ end
143
+ end
144
+
145
+ def date
146
+ Date.new(date_time.year, date_time.month, date_time.day)
147
+ end
148
+
149
+ def time
150
+ Time.new(0, 1, 1, date_time.hour, date_time.min, date_time.sec, '+00:00')
151
+ end
152
+
153
+ def game_date
154
+ date_time.strftime("%m/%d/%Y")
155
+ end
156
+
157
+ def game_time
158
+ date_time.strftime("%I:%M %p")
159
+ end
160
+
161
+ def home_team_options
162
+ TEAM_BALLPARKS.keys
163
+ end
164
+
165
+ def away_team_options
166
+ TEAM_BALLPARKS.keys
167
+ end
168
+
169
+ def ballpark_options
170
+ [TEAM_BALLPARKS[@home_team], TEAM_BALLPARKS[@away_team]]
171
+ end
172
+
173
+ def to_s
174
+ "#{home_team} vs #{away_team} at #{ballpark} on #{game_date} #{game_time}"
175
+ end
176
+
177
+ def book!
178
+ "Thank you for booking #{to_s}"
179
+ end
180
+ end
181
+
182
+ include Glimmer
183
+
184
+ def launch
185
+ shell {
186
+ grid_layout
187
+
188
+ text 'Hello, Table!'
189
+
190
+ label {
191
+ layout_data :center, :center, true, false
192
+
193
+ text 'Baseball Playoff Schedule'
194
+ font height: 30, style: :bold
195
+ }
196
+
197
+ combo(:read_only) {
198
+ layout_data :center, :center, true, false
199
+ selection bind(BaseballGame, :playoff_type)
200
+ font height: 16
201
+ }
202
+
203
+ table(:editable) { |table_proxy|
204
+ layout_data :fill, :fill, true, true
205
+
206
+ table_column {
207
+ text 'Game Date'
208
+ width 150
209
+ sort_property :date # ensure sorting by real date value (not `game_date` string specified in items below)
210
+ # editor :date_drop_down, property: :date_time
211
+ }
212
+ table_column {
213
+ text 'Game Time'
214
+ width 150
215
+ sort_property :time # ensure sorting by real time value (not `game_time` string specified in items below)
216
+ # editor :time, property: :date_time
217
+ }
218
+ table_column {
219
+ text 'Ballpark'
220
+ width 180
221
+ # editor :none
222
+ }
223
+ table_column {
224
+ text 'Home Team'
225
+ width 150
226
+ # editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
227
+ }
228
+ table_column {
229
+ text 'Away Team'
230
+ width 150
231
+ # editor :combo, :read_only # read_only is simply an SWT style passed to combo widget
232
+ }
233
+ table_column {
234
+ text 'Promotion'
235
+ width 150
236
+ # default text editor is used here
237
+ }
238
+
239
+ # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
240
+ items bind(BaseballGame, :schedule), column_properties(:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion)
241
+
242
+ # Data-bind table selection
243
+ selection bind(BaseballGame, :selected_game)
244
+
245
+ # Default initial sort property
246
+ sort_property :date
247
+
248
+ # Sort by these additional properties after handling sort by the column the user clicked
249
+ additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
250
+
251
+ # menu {
252
+ # menu_item {
253
+ # text 'Book'
254
+ #
255
+ # on_widget_selected {
256
+ # book_selected_game
257
+ # }
258
+ # }
259
+ # }
260
+ }
261
+
262
+ button {
263
+ text 'Book Selected Game'
264
+ layout_data :center, :center, true, false
265
+ font height: 16
266
+ enabled bind(BaseballGame, :selected_game)
267
+
268
+ on_widget_selected {
269
+ book_selected_game
270
+ }
271
+ }
272
+ }.open
273
+ end
274
+
275
+ def book_selected_game
276
+ message_box {
277
+ text 'Baseball Game Booked!'
278
+ message BaseballGame.selected_game.book!
279
+ }.open
280
+ end
281
+ end
282
+
283
+ HelloTable.new.launch