Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ulysses-front/src/cljs/ulysses/db.cljs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
116 lines (85 sloc)
3.43 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ulysses.db | |
(:require-macros [cljs.test :refer [deftest testing are is]]) | |
(:require [ulysses.utils :refer [document-size window-size window-scroll-position]])) | |
(def default-db | |
{;; ------------------------------------------------------------------------- | |
;; general | |
;; ------------------------------------------------------------------------- | |
; current active page | |
:active-page :home | |
; current route arguments | |
:route-args {} | |
; progress trackers | |
:progress {} | |
; next progress ids (gets incremented eagerly) | |
:next-progress-id 1 | |
; current document size | |
:document-size (document-size) | |
; current window size | |
:window-size (window-size) | |
; current window scroll position | |
:window-scroll-position (window-scroll-position) | |
;; ------------------------------------------------------------------------- | |
;; user | |
;; ------------------------------------------------------------------------- | |
:user nil | |
;; ------------------------------------------------------------------------- | |
;; data | |
;; ------------------------------------------------------------------------- | |
;; general ---- | |
; grant ops (bare-bones, for listings) | |
:grant-ops [] | |
; workspaces (bare-bones) | |
:workspaces [] | |
; faculties (extended, with keywords) [builder] | |
:faculties {} | |
; faculty titles [builder] | |
:faculty-titles [] | |
;; builder ---- | |
; builder: current grant op (extended) | |
:builder-grant-op nil | |
; builder: current faculty pool results given filters (with metrics) | |
:builder-faculties-pool [] | |
; builder: current workspace, OR nil for default | |
:builder-workspace nil | |
;; ------------------------------------------------------------------------- | |
;; user data | |
;; ------------------------------------------------------------------------- | |
; pagination: generic current page | |
:page-current 1 | |
; pagination: generic max page | |
:page-last 1 | |
; home page grant op filters and sort options | |
:home-filters {:search "" | |
:mechanisms {:nih true | |
:nsf true | |
:ncbi true} | |
:sort "posted_date" | |
:sort-direction "desc"} | |
; builder pool filters | |
:builder-filters {:faculty-title-set #{"director"} | |
:faculty-years-uconn 0 | |
:metrics {:publicationCount 0 | |
:grantCount 0 | |
:grantFunds 0 | |
:recentGrantCount 0 | |
:recentGrantFunds 0}} | |
; user workspace-faculty hover (id) | |
:builder-workspace-faculty-hover nil | |
;; ------------------------------------------------------------------------- | |
;; interface | |
;; ------------------------------------------------------------------------- | |
; modal: {:title Hiccup | String, :action-label String :on-action Function :children Hiccup | String} | |
:modal nil}) | |
(defn refresh-keys | |
"given a db, set the given keys to their original state" | |
[db keys] | |
(merge db (select-keys default-db keys))) | |
;; ---------------------------------------------------------------------------- | |
;; tests | |
;; ---------------------------------------------------------------------------- | |
(deftest test-refresh-keys | |
(testing "refresh-keys" | |
(are [keys db] (= default-db (refresh-keys db keys)) | |
[:active-page] (assoc default-db :active-page :builder) | |
[:page-current] (assoc default-db :page-current 2)))) |