diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 68486c2..2e1657f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,6 +3,6 @@ class HomeController < ApplicationController def index Time.zone = 'Pacific Time (US & Canada)' @year = params['year'].nil? ? Date.today.year : params['year'].to_i - @events = [Event.new] + @events = CalendarService.new.events + CalendarService.new.vacations end end diff --git a/app/models/calendar_service.rb b/app/models/calendar_service.rb new file mode 100644 index 0000000..5a9c23d --- /dev/null +++ b/app/models/calendar_service.rb @@ -0,0 +1,52 @@ +require 'http' + +class CalendarService + + def vacations + Rails.cache.fetch("vacations", expires_in: 5.minutes) do + entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/593FC5A0-746B-48C7-A57B-3A0315976412/?export", "ff00ff") + end + end + + def events + Rails.cache.fetch("events", expires_in: 5.minutes) do + entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/774BE10B-AEAD-4D20-BF09-9C0FFD135E56/?export", "0000ff") + end + end + + def sports + entries("https://static.nocoda.io/remote.php/dav/calendars").map do |entry| + + end + end + + def entries(url, color) + # + a = HTTP.basic_auth(user: 'pkamin', pass: 'QDH*@8fhWekxwWjeX8MQ3H').get(url).body.to_s + # a = File.read('/Users/pkamin/Desktop/vacation.vcalendar') + + b = a.split("\r\n") + + events = [] + e = nil + + b.each do |line| + if line == "BEGIN:VEVENT" + e = Event.new + e.color = color + elsif line == "END:VEVENT" + events << e unless e.nil? + elsif line.start_with?("DTSTART") && ! e.nil? + e.begin_at = DateTime.parse(line.split(":").last) + elsif line.start_with?("DTEND") && ! e.nil? + e.end_at = DateTime.parse(line.split(":").last) + e.end_at = e.end_at - 1.minute + elsif line.start_with?("SUMMARY") && ! e.nil? + e.name = line.split(":").last + end + end + + events + end +end + diff --git a/app/models/event.rb b/app/models/event.rb index 3842a33..64d5d2c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,12 +1,16 @@ class Event - attr_reader :begin_at, :end_at + attr_accessor :begin_at, :end_at, :name, :color - def initialize - @begin_at = DateTime.now.beginning_of_day - @end_at = DateTime.now + 1.day + def initialize(begin_at = DateTime.now.beginning_of_day, end_at = DateTime.now.end_of_day) + @begin_at = begin_at + @end_at = end_at end def during?(d) self.begin_at <= d && d <= self.end_at end + + def first_day?(d) + self.begin_at.beginning_of_day <= d && d <= self.begin_at.end_of_day + end end \ No newline at end of file diff --git a/app/views/home/_month.erb b/app/views/home/_month.erb index 5782b97..7f7a88a 100644 --- a/app/views/home/_month.erb +++ b/app/views/home/_month.erb @@ -11,7 +11,12 @@
<% todays_events.each do |event| %> -
+
+ <% event.name if event.first_day?(day)%> +
+
+ +
<% end %>
diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity new file mode 100644 index 0000000..eaf8b05 --- /dev/null +++ b/node_modules/.yarn-integrity @@ -0,0 +1,16 @@ +{ + "systemParams": "darwin-x64-111", + "modulesFolders": [ + "node_modules" + ], + "flags": [], + "linkedModules": [], + "topLevelPatterns": [ + "stimulus-popover@^6.2.0" + ], + "lockfileEntries": { + "stimulus-popover@^6.2.0": "https://registry.yarnpkg.com/stimulus-popover/-/stimulus-popover-6.2.0.tgz#67bcf725d9077f213869905e7b5c80212a92d802" + }, + "files": [], + "artifacts": {} +} \ No newline at end of file diff --git a/node_modules/stimulus-popover/.eslintignore b/node_modules/stimulus-popover/.eslintignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/node_modules/stimulus-popover/.eslintignore @@ -0,0 +1 @@ +dist diff --git a/node_modules/stimulus-popover/.prettierrc b/node_modules/stimulus-popover/.prettierrc new file mode 100644 index 0000000..963354f --- /dev/null +++ b/node_modules/stimulus-popover/.prettierrc @@ -0,0 +1,3 @@ +{ + "printWidth": 120 +} diff --git a/node_modules/stimulus-popover/CHANGELOG.md b/node_modules/stimulus-popover/CHANGELOG.md new file mode 100644 index 0000000..0b582d5 --- /dev/null +++ b/node_modules/stimulus-popover/CHANGELOG.md @@ -0,0 +1,98 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [6.2.0] - 2022-12-23 + +### Added + +- Adding `name` in library export to use the package with CDN, Sprockets and `import-maps`. + +### Chore + +- Bump dependencies. +- Upgrading to Vite `4.x`. +- Docs new UI. + +## [6.1.0] - 2022-08-12 + +### Chore + +- Using `mouseenter` and `mouseleave` events +- Fix error when target is null + +## [6.0.0] - 2022-08-12 + +### Chore + +- **Breaking** Upgrading Stimulus to `3.x` and change namespace from `stimulus` to `@hotwired/stimulus`. +- Upgrading dependencies +- Upgrading Node to 16 +- Updating Workflows + +## [5.0.1] - 2021-06-14 + +### Fixed + +- Using `currentTarget` instead of `target` to select the element. + +## [5.0.0] - 2021-06-02 + +### Chore + +- Moving from [Snowpack](https://www.snowpack.dev/) to [Vite](https://vitejs.dev/) +- Using stimulus as external library reducing bundle size from `40.66kb` to `0.61kb`. +- Moving to [TypeScript](https://www.typescriptlang.org/). +- Upgrading Node to 14.17.0 + +## [4.0.0] - 2020-12-05 + +### Added + +- Support for Stimulus 2.0 +- Prevent error if the url is empty when using remote card. + +### Changed + +- **Breaking** Using the new `values` static property + +```diff +-
++
+``` + +- **Breaking** Using the new syntax for `targets`. + +```diff +-
++
+``` + +## [3.0.0] - 2020-11-18 + +### Changed +**Breaking** - Removing Tippy as dependency. +**Breaking** - Rename `mouseOver` to `show`. + +### Added +- Add `hide` action. + +## [2.0.0] - 2020-11-10 +### Added +- Adding `tippyOptions` getter to simply override default options. +- `tippy` instance is now a singleton. +- Destroy `tippy` instance on disconnect. + +### Changed +**Breaking** - Removing `mouseOut` action. +**Breaking** - `popover` action does not return a new `tippy` instance. + +## [1.0.0] - 2020-10-20 + +### Added + +- Adding controller diff --git a/node_modules/stimulus-popover/LICENSE b/node_modules/stimulus-popover/LICENSE new file mode 100644 index 0000000..d0ded37 --- /dev/null +++ b/node_modules/stimulus-popover/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Guillaume Briday + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/stimulus-popover/README.md b/node_modules/stimulus-popover/README.md new file mode 100644 index 0000000..a749be9 --- /dev/null +++ b/node_modules/stimulus-popover/README.md @@ -0,0 +1,22 @@ +# Stimulus Popover + +[![](https://img.shields.io/npm/dt/stimulus-popover.svg)](https://www.npmjs.com/package/stimulus-popover) +[![](https://img.shields.io/npm/v/stimulus-popover.svg)](https://www.npmjs.com/package/stimulus-popover) +[![](https://github.com/stimulus-components/stimulus-popover/workflows/Lint/badge.svg)](https://github.com/stimulus-components/stimulus-popover) +[![](https://img.shields.io/github/license/stimulus-components/stimulus-popover.svg)](https://github.com/stimulus-components/stimulus-popover) + +## Getting started + +A Stimulus controller to deal with HTML popover. + +## 📚 Documentation + +See [stimulus-popover documentation](https://www.stimulus-components.com/docs/stimulus-popover/). + +## 👷‍♂️ Contributing + +Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome. + +## 📝 License + +This project is released under the [MIT](http://opensource.org/licenses/MIT) license. diff --git a/node_modules/stimulus-popover/card.html b/node_modules/stimulus-popover/card.html new file mode 100644 index 0000000..3731902 --- /dev/null +++ b/node_modules/stimulus-popover/card.html @@ -0,0 +1,18 @@ +
+
+ + +
+
Guillaume Briday
+

This content is loaded with AJAX.

+
+
+
diff --git a/node_modules/stimulus-popover/dist/stimulus-popover.mjs b/node_modules/stimulus-popover/dist/stimulus-popover.mjs new file mode 100644 index 0000000..87f8da1 --- /dev/null +++ b/node_modules/stimulus-popover/dist/stimulus-popover.mjs @@ -0,0 +1,32 @@ +import { Controller as o } from "@hotwired/stimulus"; +class r extends o { + async show(e) { + const n = e.currentTarget; + let t = null; + if (this.hasContentTarget ? t = this.contentTarget.innerHTML : t = await this.fetch(), !t) + return; + const a = document.createRange().createContextualFragment(t); + n.appendChild(a); + } + hide() { + this.hasCardTarget && this.cardTarget.remove(); + } + async fetch() { + if (!this.remoteContent) { + if (!this.hasUrlValue) { + console.error("[stimulus-popover] You need to pass an url to fetch the popover content."); + return; + } + const e = await fetch(this.urlValue); + this.remoteContent = await e.text(); + } + return this.remoteContent; + } +} +r.targets = ["card", "content"]; +r.values = { + url: String +}; +export { + r as default +}; diff --git a/node_modules/stimulus-popover/dist/stimulus-popover.umd.js b/node_modules/stimulus-popover/dist/stimulus-popover.umd.js new file mode 100644 index 0000000..3e26c03 --- /dev/null +++ b/node_modules/stimulus-popover/dist/stimulus-popover.umd.js @@ -0,0 +1 @@ +(function(t,e){typeof exports=="object"&&typeof module<"u"?module.exports=e(require("@hotwired/stimulus")):typeof define=="function"&&define.amd?define(["@hotwired/stimulus"],e):(t=typeof globalThis<"u"?globalThis:t||self,t.StimulusPopover=e(t.Stimulus))})(this,function(t){"use strict";class e extends t.Controller{async show(r){const s=r.currentTarget;let n=null;if(this.hasContentTarget?n=this.contentTarget.innerHTML:n=await this.fetch(),!n)return;const o=document.createRange().createContextualFragment(n);s.appendChild(o)}hide(){this.hasCardTarget&&this.cardTarget.remove()}async fetch(){if(!this.remoteContent){if(!this.hasUrlValue){console.error("[stimulus-popover] You need to pass an url to fetch the popover content.");return}const r=await fetch(this.urlValue);this.remoteContent=await r.text()}return this.remoteContent}}return e.targets=["card","content"],e.values={url:String},e}); diff --git a/node_modules/stimulus-popover/package.json b/node_modules/stimulus-popover/package.json new file mode 100644 index 0000000..72fa445 --- /dev/null +++ b/node_modules/stimulus-popover/package.json @@ -0,0 +1,47 @@ +{ + "name": "stimulus-popover", + "version": "6.2.0", + "description": "A Stimulus controller to deal with HTML popover.", + "keywords": [ + "stimulus", + "stimulusjs", + "stimulus controller", + "popover" + ], + "repository": "git@github.com:stimulus-components/stimulus-popover.git", + "bugs": { + "url": "https://github.com/stimulus-components/stimulus-popover/issues" + }, + "author": "Guillaume Briday ", + "license": "MIT", + "homepage": "https://github.com/stimulus-components/stimulus-popover", + "private": false, + "main": "dist/stimulus-popover.umd.js", + "module": "dist/stimulus-popover.mjs", + "scripts": { + "format": "prettier-standard '**/*.{ts,css,html}' --format", + "lint": "prettier-standard '**/*.{ts,css,html}' --lint", + "dev": "vite", + "prod": "vite build --mode netlify", + "build": "tsc --noEmit && vite build", + "version": "yarn build", + "np": "np --no-2fa --no-test" + }, + "devDependencies": { + "@babel/core": "7.20.7", + "@babel/plugin-syntax-class-properties": "7.12.13", + "@babel/preset-env": "^7.20.2", + "@babel/preset-typescript": "^7.18.6", + "@hotwired/stimulus": "^3.2.1", + "autoprefixer": "^10.4.13", + "np": "^7.6.2", + "postcss": "^8.4.20", + "prettier-standard": "16.4.1", + "tailwindcss": "^3.2.4", + "typescript": "^4.9.4", + "vite": "^4.0.3" + }, + "peerDependencies": { + "@hotwired/stimulus": "^3.1.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f3699f2 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "stimulus-popover": "^6.2.0" + } +} diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..3c2b702 --- /dev/null +++ b/test.rb @@ -0,0 +1,33 @@ +require 'http' + +# url = "https://static.nocoda.io/remote.php/dav/calendars/pkamin/774BE10B-AEAD-4D20-BF09-9C0FFD135E56/?export" +# a = HTTP.basic_auth(user: 'pkamin', pass: 'QDH*@8fhWekxwWjeX8MQ3H').get(url).body.to_s + +# File.write('/Users/pkamin/Desktop/vacation.vcalendar', a) + +a = File.read('/Users/pkamin/Desktop/vacation.vcalendar') + +b = a.split("\r\n") + +events = [] +e = nil + +puts a.length +b.each do |line| + puts line + if line == "BEGIN:VEVENT" + puts "new e" + e = Struct.new(:begin_at, :end_at) + elsif line == "END:VEVENT" + puts "end" + events << e unless e.nil? + elsif line.start_with?("DTSTART") + puts "begin" + e.begin_at = DateTime.parse(line.split(":")[1]) unless e.nil? + elsif line.start_with?("DTEND") + puts 'end' + e.end_at = DateTime.parse(line.split(":")[1]) unless e.nil? + end +end + +puts events diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..ac7e57b --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +stimulus-popover@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/stimulus-popover/-/stimulus-popover-6.2.0.tgz#67bcf725d9077f213869905e7b5c80212a92d802" + integrity sha512-QJqGXA842qS9s+c0Si6JUKDHDZVnkClvgZPfl2KbHcT6G9BMrEK+21na00SVNpWmmzdc6E1qQrq/oVY7gGaf3w==