-
Notifications
You must be signed in to change notification settings - Fork 1
json-upload #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json-upload #113
Changes from all commits
beeb0e9
3700b0b
c88e6ea
6fd719f
6db843e
dd396a1
55ce511
8886cb3
61127f8
5adfac7
bd33998
09d80e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]]]})) | ||
|
|
||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not seeing all of these specced out in db
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added