Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"victory-core": "^36.6.8",
"victory-scatter": "^36.6.8",
"victory-tooltip": "^36.6.8"
},
"overrides": {
"lodash": "4.17.23"
}
}
26 changes: 26 additions & 0 deletions src/com/yetanalytics/lrs_admin_ui/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@
(s/def ::csv-download-properties
(s/keys :req-un [::csvd/property-paths]))

(s/def ::statements-file-upload-xapi-version
(s/nilable string?))

(s/def ::statements-file-upload-statements-count
(s/nilable integer?))

(s/def ::statements-file-upload-file-upload-file
(s/nilable #(instance? js/File %)))

(s/def :event-log/code {:good :bad})
(s/def :event-log/event string?)
(s/def :event-log/duration int?)
(s/def :event-log/timestamp int?)

(s/def ::statements-file-upload-event-log
(s/nilable
(s/coll-of
(s/keys :req-un [:event-log/code
:event-log/event
:event-log/timestamp]
:opt-un [:event-log/duration]))))

(s/def ::dialog-ref any?)

(s/def :dialog-choice/label string?)
Expand Down Expand Up @@ -243,6 +265,10 @@
::editing-reaction-template-errors
::editing-reaction-template-json
::csv-download-properties
::statements-file-upload-xapi-version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no db entry for event log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

::statements-file-upload-file-upload-file
::statements-file-upload-statements-count
::statements-file-upload-event-log
::dialog-ref
::dialog-data
::no-val?
Expand Down
4 changes: 4 additions & 0 deletions src/com/yetanalytics/lrs_admin_ui/functions/time.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
(defn timeline-until-default
[]
(.toISOString (js/Date.)))

(defn ms->local [ms]
(let [date (js/Date. ms)]
(format "%s, %s" (.toLocaleDateString date) (.toLocaleTimeString date))))
118 changes: 117 additions & 1 deletion src/com/yetanalytics/lrs_admin_ui/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
::db/reactions []
::db/last-interaction-time (.now js/Date)
::db/supported-versions db/supported-versions-set
::db/reaction-version "2.0.0"}
::db/reaction-version "2.0.0"
::db/statements-file-upload-event-log []}
:fx [[:dispatch [:db/verify-login]]
[:dispatch [:db/get-env]]]}))

Expand Down Expand Up @@ -677,6 +678,121 @@
(fn [[edn-data edn-data-name]]
(download/download-edn edn-data edn-data-name)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Uploads
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(re-frame/reg-event-fx
:statements-file-upload/file-change
(fn [{:keys [db]} [_ file text]]
(let [parsed (try (.parse js/JSON text)
(catch :default _e :unparseable))]
(case parsed
:unparseable
{:fx [[:dispatch [:notification/notify true "File not valid JSON"]]]
:db (-> db
(update
::db/statements-file-upload-event-log conj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it kinda seems like you have an object format for the logs. I would recommend speccing that out as well in db.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specced

{:code :bad
:event (str "File " (.-name file) " not valid JSON, not loaded")
:timestamp (.now js/Date)})
(assoc ::db/statements-file-upload-file
nil
::db/statements-file-upload-file-text
nil
::db/statements-file-upload-file-name
nil
::db/statements-file-upload-statements-count
0))}
{:db (assoc db
::db/statements-file-upload-file
file
::db/statements-file-upload-file-text
text
::db/statements-file-upload-file-name
(.-name file)
::db/statements-file-upload-statements-count
(if (.isArray js/Array parsed)
(.-length parsed)
1))}))))

(re-frame/reg-event-fx
:statements-file-upload/upload-click
(fn [{{[credential] ::db/credentials
:as db} :db :as _cofx} [_event-name]]
(if credential
{:fx [[:dispatch [:statements-file-upload/upload (db ::db/statements-file-upload-file-text)] ]]}
{:fx [[:dispatch [:notification/notify true
"Please select a credential"]]]})))

(re-frame/reg-event-fx
:statements-file-upload/upload
(fn [{{{credential :credential} ::db/browser
server-host ::db/server-host
proxy-path ::db/proxy-path
xapi-version ::db/statements-file-upload-xapi-version
:as _db} :db} [_ file-text]]
(let [xapi-version (or xapi-version "1.0.3")
start-ts (.now js/Date)]
{:http-xhrio
(httpfn/req-xapi
{:method :post
:headers {"Authorization" (format "Basic %s"
(httpfn/make-basic-auth credential))
"Content-Type" "application/json"}
:uri (httpfn/serv-uri
server-host
"/xapi/statements"
proxy-path)
:response-format (ajax/json-response-format {:keywords? true})
:body file-text
:interceptors [(httpfn/xapi-version-interceptor xapi-version) ]
:on-success [:statements-file-upload/success-handler xapi-version start-ts]
:on-failure [:statements-file-upload/error-handler]})})))

(re-frame/reg-event-fx
:statements-file-upload/success-handler
(fn [{{file ::db/statements-file-upload-file
c ::db/statements-file-upload-statements-count
:as db} :db}
[_ xapi-version start-ts _result]]

(let [filename (.-name file)
duration (- (.now js/Date)
start-ts)]
{:fx [[:dispatch [:notification/notify true "Upload Successful!"]]]
:db (update db ::db/statements-file-upload-event-log conj
{:code :good
:event (str "Successfully uploaded " c " statements from " filename " under XAPI version " xapi-version)
:duration duration
:timestamp (.now js/Date)})})))

(re-frame/reg-event-fx
:statements-file-upload/error-handler
(fn [{{file ::db/statements-file-upload-file
:as db} :db}
[_ result]]
(let [filename (.-name file)
precursor (str "Failed to upload " filename ": ")
msg (cond (#{0 -1} (:status result))
"Couldn't reach server"
:else
(get-in result [:response :error :message]))]

{:fx [[:dispatch [:notification/notify true msg]]]
:db (update db ::db/statements-file-upload-event-log conj
{:code :bad
:event (str precursor msg)
:timestamp (.now js/Date)})})))

(re-frame/reg-event-db
:statements-file-upload/set-xapi-version
(fn [db [_ version]]
(assoc db ::db/statements-file-upload-xapi-version
version)))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Browser
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
6 changes: 6 additions & 0 deletions src/com/yetanalytics/lrs_admin_ui/language.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
:csv.property-paths.add {:en-US "Add CSV Column "}
:csv.property-paths.instructions {:en-US "To export your data, select the xAPI statement property paths as CSV columns below."}
:csv.filters {:en-US "Filters:"}
;;JSON File Upload
:statements.file-upload.title {:en-US "Upload Statements"}
:statements.file-upload.button {:en-US "Upload"}
:statements.file-upload.choose-file-button {:en-US "Choose file"}
:statements.file-upload.xapi-version {:en-US "XAPI Version"}
:statements.file-upload.key-note {:en-US "Please Choose an API Key Above to Upload Statements File"}
;;Monitor
:monitor.title {:en-US "LRS Monitor"}
:monitor.no-data {:en-US "No Statement Data"}
Expand Down
29 changes: 29 additions & 0 deletions src/com/yetanalytics/lrs_admin_ui/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,35 @@
(fn [property-paths _]
(s/valid? :validation/property-paths property-paths)))

;; Upload JSON file
(reg-sub
:statements-file-upload/xapi-version
(fn [db _]
(or (get db ::db/statements-file-upload-xapi-version)
"1.0.3")))

(reg-sub
:statements-file-upload/file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not seeing all of these specced out in db

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

(fn [db _]
(get db ::db/statements-file-upload-file)))

(reg-sub
:statements-file-upload/filename
(fn [_qv]
[(subscribe [:statements-file-upload/file])])
(fn [[file] _qv]
(.-name file)))

(reg-sub
:statements-file-upload/statement-count
(fn [db _]
(get db ::db/statements-file-upload-statements-count)))

(reg-sub
:statements-file-upload/event-log
(fn [db _]
(::db/statements-file-upload-event-log db)))

;; OIDC State
(reg-sub
:oidc/login-available?
Expand Down
Loading
Loading