Skip to content

Commit

Permalink
Merge pull request #661 from artifactdev/master
Browse files Browse the repository at this point in the history
Color options for calendar and weather forecast
  • Loading branch information
MichMich authored Jan 30, 2017
2 parents 832505a + c3bfaa3 commit c47852c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Icelandic Translation.
- Add use a script to prevent when is run by SSH session set DISPLAY enviroment.
- Enable ability to set configuration file by the enviroment variable called MM_CONFIG_FILE.
- Option to give each calendar a different color
- Option for colored min-temp and max-temp
- Add test e2e helloworld
- Add test e2e enviroment

Expand Down
19 changes: 12 additions & 7 deletions modules/default/calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ The following properties can be configured:
### Calendar configuration

The `calendars` property contains an array of the configured calendars.
The `colored` property gives the option for an individual color for each calendar.

#### Default value:
````javascript
config: {
colored: false,
calendars: [
{
url: 'http://www.calendarlabs.com/templates/ical/US-Holidays.ics',
Expand All @@ -63,10 +65,13 @@ config: {


#### Calendar configuration options:
| Option | Description
| --------------------- | -----------
| `url` | The url of the calendar .ical. This property is required. <br><br> **Possible values:** Any public accessble .ical calendar.
| `symbol` | The symbol to show in front of an event. This property is optional. <br><br> **Possible values:** See [Font Awesome](http://fontawesome.io/icons/) website.
| `repeatingCountTitle` | The count title for yearly repating events in this calendar. <br><br> **Example:** `'Birthday'`
| `user` | The username for HTTP Basic authentication.
| `pass` | The password for HTTP Basic authentication.

-| Option | Description
-| --------------------- | -----------
-| `url` | The url of the calendar .ical. This property is required. <br><br> **Possible values:** Any public accessble .ical calendar.
-| `symbol` | The symbol to show in front of an event. This property is optional. <br><br> **Possible values:** See [Font Awesome](http://fontawesome.io/icons/) website.
-| `color` | The font color of an event from this calendar. This property should be set if the config is set to colored: true. <br><br> **Possible values:** HEX, RGB or RGBA values (#efefef, rgb(242,242,242), rgba(242,242,242,0.5)).
-| `repeatingCountTitle` | The count title for yearly repating events in this calendar. <br><br> **Example:** `'Birthday'`
-| `user` | The username for HTTP Basic authentication.
-| `pass` | The password for HTTP Basic authentication.

36 changes: 33 additions & 3 deletions modules/default/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Module.register("calendar", {
getRelative: 6,
fadePoint: 0.25, // Start on 1/4th of the list.
hidePrivate: false,
colored: false,
calendars: [
{
symbol: "calendar",
Expand Down Expand Up @@ -114,6 +115,11 @@ Module.register("calendar", {
var event = events[e];

var eventWrapper = document.createElement("tr");

if (this.config.colored) {
eventWrapper.style.cssText = "color:" + this.colorForUrl(event.url);
}

eventWrapper.className = "normal";

if (this.config.displaySymbol) {
Expand Down Expand Up @@ -142,7 +148,13 @@ Module.register("calendar", {
}

titleWrapper.innerHTML = this.titleTransform(event.title) + repeatingCountTitle;
titleWrapper.className = "title bright";

if (!this.config.colored) {
titleWrapper.className = "title bright";
} else {
titleWrapper.className = "title";
}

eventWrapper.appendChild(titleWrapper);

var timeWrapper = document.createElement("td");
Expand Down Expand Up @@ -273,8 +285,8 @@ Module.register("calendar", {
var event = calendar[e];
if(this.config.hidePrivate) {
if(event.class === "PRIVATE") {
// do not add the current event, skip it
continue;
// do not add the current event, skip it
continue;
}
}
event.url = c;
Expand Down Expand Up @@ -323,6 +335,24 @@ Module.register("calendar", {

return this.config.defaultSymbol;
},

/* colorForUrl(url)
* Retrieves the color for a specific url.
*
* argument url sting - Url to look for.
*
* return string - The Color
*/
colorForUrl: function (url) {
for (var c in this.config.calendars) {
var calendar = this.config.calendars[c];
if (calendar.url === url && typeof calendar.color === "string") {
return calendar.color;
}
}

return "#fff";
},
/* countTitleForUrl(url)
* Retrieves the name for a specific url.
*
Expand Down
1 change: 1 addition & 0 deletions modules/default/weatherforecast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following properties can be configured:
| `appendLocationNameToHeader` | If set to `true`, the returned location name will be appended to the header of the module, if the header is enabled. This is mainly intresting when using calender based weather. <br><br> **Default value:** `true`
| `calendarClass` | The class for the calender module to base the event based weather information on. <br><br> **Default value:** `'calendar'`
| `iconTable` | The conversion table to convert the weather conditions to weather-icons. <br><br> **Default value:** view table below
`colored` | If set 'colored' to true the min-temp get a blue tone and the max-temp get a red tone. <br><br> **Default value:** `'false'`

#### Default Icon Table
````javascript
Expand Down
8 changes: 8 additions & 0 deletions modules/default/weatherforecast/weatherforecast.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@
padding-left: 20px;
padding-right: 0;
}

.weatherforecast tr.colored .min-temp {
color: #BCDDFF;
}

.weatherforecast tr.colored .max-temp {
color: #FF8E99;
}
4 changes: 4 additions & 0 deletions modules/default/weatherforecast/weatherforecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Module.register("weatherforecast",{
lang: config.language,
fade: true,
fadePoint: 0.25, // Start on 1/4th of the list.
colored: false,

initialLoadDelay: 2500, // 2.5 seconds delay. This delay is used to keep the OpenWeather API happy.
retryDelay: 2500,
Expand Down Expand Up @@ -120,6 +121,9 @@ Module.register("weatherforecast",{
var forecast = this.forecast[f];

var row = document.createElement("tr");
if (this.config.colored) {
row.className = "colored";
}
table.appendChild(row);

var dayCell = document.createElement("td");
Expand Down

0 comments on commit c47852c

Please sign in to comment.