aboutsummaryrefslogtreecommitdiff
path: root/module/calp/html/view/calendar/week.scm
blob: 9911b162fc88c7107832abe0cd9cc722775a9f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
(define-module (calp html view calendar week)
  :use-module (calp util)
  :use-module (srfi srfi-1)
  :use-module (srfi srfi-41)
  :use-module (datetime)
  :use-module (calp html view calendar shared)
  :use-module (calp html config)
  :use-module (calp html util)
  :use-module (vcomponent)
  :use-module ((vcomponent datetime)
               :select (long-event?
                        event-length/day
                        event-zero-length?
                        events-between))
  :use-module ((calp html vcomponent)
               :select (make-block) )
  :use-module ((calp html components)
               :select (btn tabset #; #; form with-label
                            ))
  :use-module ((vcomponent group)
               :select (group-stream get-groups-between))
  )


(define*-public (render-calendar key: calendars events start-date end-date #:allow-other-keys)
  (let* ((long-events short-events (partition long-event? (stream->list (events-between start-date end-date events))))
         (range (date-range start-date end-date)))
    `((script "const VIEW='week';")
      (div (@ (class "calendar"))
           (div (@ (class "days"))
                ;; Top left area
                (div (@ (class "week-indicator"))
                     (span (@ (style "font-size: 50%")) "v.")  ; figure out if we want this...
                     ,@(->> (week-number start-date)
                            number->string string->list
                            (map (lambda (c) `(span ,(string c))))))
                ,@(time-marker-div)
                (div (@ (class "longevents event-container")
                        (data-start ,(date->string start-date) )
                        (data-end ,(date->string (add-day end-date)) )
                        (style "grid-column-end: span " ,(days-in-interval start-date end-date)))
                     ,@(lay-out-long-events start-date end-date long-events))
                ,@(map (lambda (day-date)
                         `(div (@ (class "meta"))
                               (span (@ (class "daydate"))
                                     ,(date->string day-date "~Y-~m-~d"))
                               (span (@ (class "dayname"))
                                     ,(string-titlecase (date->string day-date "~a")))))
                       range)
                ,@(stream->list
                   (stream-map
                    lay-out-day
                    (get-groups-between (group-stream (list->stream short-events))
                                        start-date end-date)))

                ,@(for event in (stream->list
                                 (events-between start-date end-date events))
                       `(popup-element
                         ;; TODO
                         (@ (class "vevent")
                            (data-uid ,(prop event 'UID)))
                         )
                       #;
                       ((@ (calp html vcomponent ) popup) ;
                       event (string-append "popup" (html-id event))))

                ))

      ;; description in sidebar / tab of popup
      (template (@ (id "vevent-description"))
                ,(description-template)
                )

      ;; edit tab of popup
      (template (@ (id "vevent-edit"))
                ,((@ (calp html vcomponent) edit-template)
                  calendars
                  ))

      ;; "physical" block
      (template (@ (id "vevent-block"))
                ,(block-template)
                )

      ;; Based on popup:s output
      (template
       (@ (id "popup-template"))
       (div (@ ; (id ,id)
             (class "popup-container CAL_"
               #; 
               ,(html-attr (or (prop (parent ev) 'NAME) ;
               "unknown")))
             (onclick "event.stopPropagation()"))
            (div (@ (class "popup"))
                 (nav (@ (class "popup-control"))
                      ,(btn "×"
                            title: "Stäng"
                            onclick: ""
                            ;; onclick: "close_popup(document.getElementById(this.closest('.popup-container').id))"
                            class: '("close-tooltip")))

                 ,(tabset
                   `(("📅" title: "Översikt"
                      (vevent-description
                       (@ (class "vevent populate-with-uid")))
                      )

                     ,@(when (edit-mode)
                         `(("📅" title: "Redigera"
                            (vevent-edit (@ (class "populate-with-uid"))))))

                     )))))

      )))

;; based on the output of fmt-single-event
(define (description-template)
  '(div (@ (class " vevent eventtext summary-tab " ()))
        (h3 ((span (@ (class "repeating")) ; "↺"
                   )
             (span (@ (class "bind summary")
                      (data-property "summary")))))
        (div (div (time (@ (class "bind dtstart")
                           (data-property "dtstart")
                           (data-fmt "~L~H:~M")
                           (datetime ; "2021-09-29T19:56:46"
                            ))
                        ; "19:56"
                        )
                  "\xa0\xa0"
                  (time (@ (class "bind dtend")
                           (data-property "dtend")
                           (data-fmt "~L~H:~M")
                           (datetime ; "2021-09-29T19:56:46"
                            ))
                        ; "20:56"
                        ))
             (div (@ (class "fields"))
                  (div (b "Plats: ")
                       (div (@ (class "bind location")
                               (data-property "location"))
                            ; "Alsättersgatan 13"
                            ))
                  (div (@ (class "bind description")
                          (data-property "description"))
                       ; "With a description"
                       )
                  ;; (div (@ (class "categories"))
                  ;;      (a (@ (class "category")
                  ;;            (href "/search/?"
                  ;;                  "q=%28member%20%22test%22%20%28or%20%28prop%20event%20%28quote%20CATEGORIES%29%29%20%28quote%20%28%29%29%29%29"))
                  ;;         test))
                  ;; (div (@ (class "rrule"))
                  ;;      "Upprepas "
                  ;;      "varje vecka"
                  ;;      ".")
                  (div (@ (class "last-modified"))
                       "Senast ändrad -"
                       ; "2021-09-29 19:56"
                       )))))

(define (block-template)
  `(div (@ ; (id ,(html-id ev))
           (data-calendar "unknown")
           (class "event CAL_unknown"
             ;; ,(when (and (prop ev 'PARTSTAT)
             ;;             (eq? 'TENTATIVE (prop ev 'PARTSTAT)))
             ;;    " tentative")
             ;; ,(when (and (prop ev 'TRANSP)
             ;;             (eq? 'TRANSPARENT (prop ev 'TRANSP)))
             ;;    " transparent")
             )
           (onclick "toggle_popup('popup' + this.id)")
           )
        ;; Inner div to prevent overflow. Previously "overflow: none"
        ;; was set on the surounding div, but the popup /needs/ to
        ;; overflow (for the tabs?).
        (div (@ (class "event-body"))
             `(span (@ (class "repeating")) ; "↺"
                    )
             (span (@ (class "bind summary")
                      (data-property "summary"))
                   ; ,(format-summary  ev (prop ev 'SUMMARY))
                   )
             `(span (@ (class "bind location")
                       (data-property "location")))
             ;; Document symbol when we have text
             `(span (@ (class "description"))
                    ; "🗎"
                    ))
        ) )


(define (time-marker-div)
  `((div (@ (class "sideclock"))
         ,@(map (lambda (time)
                  `(div (@ (class "clock clock-" ,time))
                        (span (@ (class "clocktext"))
                              ,time ":00")))
                (iota 12 0 2)))))

;; Lay out complete day (graphical)
;; (date . (events)) -> sxml
(define (lay-out-day day)
  (let* (((day-date . events) day)
         (time-obj (datetime date: day-date))
         (short-events (stream->list events))
         #;
         (zero-length-events short-events
                             (partition event-zero-length? (stream->list events))))

    (fix-event-widths!
     short-events
     event-length-key: (lambda (e)
                         (if (event-zero-length? e)
                             (time hour: 1)
                             (event-length/day day-date e))))

    `(div (@ (class "events event-container") (id ,(date-link day-date))
             (data-start ,(date->string day-date))
             (data-end ,(date->string (add-day day-date)) ))
          ,@(map (lambda (time)
                   `(div (@ (class "clock clock-" ,time))))
                 (iota 12 0 2))
          #;
          (div (@ (class "zero-width-events"))
               ,(map make-block zero-length-events))
          ,@(map (lambda (e) (create-block day-date e)) short-events))))



;; Format single event for graphical display
;; This is extremely simmilar to create-top-block, which currently recides in ./shared
(define (create-block date ev)
  ;; (define time (date->time-utc day))

  (define left  (* 100 (x-pos ev)))
  (define width* (* 100 (width ev)))
  (define top (if (date= date (as-date (prop ev 'DTSTART)))
                  (* 100/24
                     (time->decimal-hour
                      (as-time (prop ev 'DTSTART))))
                  0))
  (define height (* 100/24 (time->decimal-hour (event-length/day date ev))))


  (define style
    ;; The calc's here is to enable an "edit-mode".
    ;; Setting --editmode ≈ 0.8 gives some whitespace to the right
    ;; of the events, alowing draging there for creating new events.
    (if (edit-mode)
        (format #f "left:calc(var(--editmode)*~,3f%);width:calc(var(--editmode)*~,3f%);top:~,3f%;height:~,3f%;"

                left width* top height)
        (format #f "left:~,3f%;width:~,3f%;top:~,3f%;height:~,3f%;"
                left width* top height)))

  (make-block
   ev `((class
          ,(when (event-zero-length? ev)
             " zero-length")
          ,(when (date<? (as-date (prop ev 'DTSTART)) date)
             " continued")
          ,(when (and (prop ev 'DTEND) (date<? date (as-date (prop ev 'DTEND))))
             " continuing"))
        (style ,style))))