timestamper/web/.ide/vim-views/ts_common.erl.view

108 lines
2.5 KiB
Plaintext
Raw Normal View History

Changed Data Model ------------------ * Created the extended data table. This is a more generic version of the extended data field that was on ``ts_user``. Instead of arbitrary key-value pairs going in a list on the user record we will have an additional table, a one to many relationship between existing tables and the ``ts_ext_data`` table, each row being an extended value of the corresponding record. * Added support to the ``timestamper:create_tables/1`` and ``timestamper_dev:create_table/1`` functions for the new ``ts_ext_data`` table. Documentation ------------- * Added some general docs about the DB layer code. * Added two new issues, *D0020*: Entry exclusion filters and *D0021*: notes width. API Changes ----------- Necessitated by the change to the data model. * Updated ``ts_api`` data-retrieval functions to use extended data: * ``get_user_summary/2`` * ``list_timelines/2`` * ``list_entries/3`` * Updated ``ts_api:put_timeline/3`` to parse the extended data supplied by the caller. *FIXME* it is not actually saving this data. * TODO: Started updating ``ts_api:post_entry/3`` to handle extended data, need to finish. Database Layer -------------- Changes necessitated by the change to the model. * Added ``ts_common:do_set_ext_data/2`` which iterates through the extended data key-value pairs calling ``ts_ext_data:set_property/3``. It does not provide a transaction context. * Split ``ts_common:new/1`` and ``ts_common:update/1`` functions into multiple functions to prevent code-duplication: * ``do_{new,update}`` contains the code that performs integrity checks and the actual database write function. It does this assuming that it is being called from within the context of an mnesia transaction (uses ``mnesia:read`` and ``mnesia:write``). * ``{new,update}/1`` performs the same function as previously. The implementation changed from using mnesia ``dirty_*`` calls to prociding a transaction and calling ``do_{new,update}/1``. * ``{new,update}/2`` expect the record to update/create and the extended data to write atomically with the record. They provide a transaction context, call ``do_{new,update}/1``, then call ``do_set_ext_data/2``. * Similar to the refactoring of ``ts_common:{new,update}/1``, ``ts_entry:{new,update}/1`` have been refactored into multiple methods each to support extended data properties: * ``do_{new,update}/1`` perform the actual update assuming we have already established an mnesia transaction. * ``{new,update}/1`` behave the same as they used to, but now do so by creating an mnesia transaction and calling ``do_{new,update}/1``. * ``{new,update}/2`` create an mnesia transaction, call ``do_{new,update}/1``, and then call ``ts_common:do_set_ext_data/2``. * Again similar to the refactoring of ``ts_common:{new,update}/1``, ``ts_user:{new,update}/1`` have been refactored into multiple methods each to support extended data properties: * ``do_{new,update}/1`` perform the actual update assuming we have already established an mnesia transaction. * ``{new,update}/1`` behave the same as they used to, but now do so by creating an mnesia transaction and calling ``do_{new,update}/1``. * ``{new,update}/2`` create an mnesia transaction, call ``do_{new,update}/1``, and then call ``ts_common:do_set_ext_data/2``. * Created the ``ts_ext_data`` module as the interface to the extended data properties introduced in the data model: * ``create_table/1`` performs the same function as it does in the other db layer modules, creates the table with the appropriate structure given the more general table options desired (location, storage type, etc.). * ``set_property/3`` takes a record, a property key, and a property value as input and sets the property described by the property key on the record to the given value, assuming this is a valid property for the record to have. For example, currently the ``ts_user`` record can have an associated property, ``last_timeline``, which represents the last timeline the user was working with. Trying to pass this property with a ``ts_entry`` record would result in an exception. This function uses ``ts_ext_data:do_set_property/3`` as its underlying implementation. * ``get_property/2`` takes a record and a property key and returns the value of that property for the given record, or ``not_set`` if the property has not been set on that record. This method creates its own mnesia transaction. * ``get_properties/1`` takes a record and returns a list of key-value tuples representing all of the extended data properties set for the given record. This method creates its own mnesia transaction. * ``do_set_property/3`` takes a record reference (not the whole record), a a property key, and adds the property assignment to the ``ts_ext_data`` table. It creates its own mnesia transaction. * Added ``new/2`` and ``update/2`` to the ``ts_timeline`` module to support extended data properties. They delegate implementation to ``ts_common:{new,update}/2``. JSON Encoding/Decoding ---------------------- Changes necessitated by the change to the data model. The JSON objects now contain a potentially unlimited number of fields, as each extended data property is encoded as a seperate field, and looks no different from any of the required fields on the object. The intended explanation in API documentation is that each object type (``user``, ``timeline``, or ``entry``) now has both *required* fields that *MUST* be present in every message in either direction and *optional* fields that may or may not be present in any communication with the API. There should be a clear distinction between which fields are required and which are optional. It might also be a good idea to provide a suggested default for optional values when they are not present. * Updated documentation about JSON record structures to reflect the fact that there are now potentially many optional attributes in addition to the required attributes for each record. * ``record_to_ejson/1`` refactored to ``record_to_ejson/2`` which also takes the extended data attributes and appends them as additional attributes to the end of the record structure. * Created ``ext_data_to_ejson/{1,2}`` to provide a mechanism for reformatting extended data properties whose internal representations are not immediately translatable into JSON. Currently only the ``entry_exclusions`` property, which is a list of strings, needs to be treated this way (changing from ``[val, val]`` to ``{array, [val, val]}`` as needed by ``json:encode/1``. ``ext_data_to_ejson/1`` acts as a more user-friendly facade to ``ext_data_to_ejson/2``. * Rewrote ``ejson_to_record/{2,3}`` and ``ejson_to_record_strict/{2,3}`` to handle extended data. They now use a common method, ``construct_record/3`` to create the actual record object and extended data key-value list. ``ejson_to_record_strict/{2,3}`` only differs in that it checks for the presence of each required field of the record after the record is constructed. The three-parameter versions of these functions also take in the intended reference for the constructed record, replacing anything that is in the EJSON body as the record reference (useful when the body does not have the record ids). These methods now return a tuple: ``{Record, ExtData}`` instead of just the record. * Created ``construct_record/3`` takes a record and the EJSON fields from the input object. The third parameter is an accumulator for the extended data properties found when constructing the record. This method works by iterating over the list of input fields. It recognizes any required fields and updates the record being built with the value. Any fields it does not recognize it assumes are extended data properties and adds to its list. When all input fields have been visited it returns the record and list it has constructed. * ``ejson_to_ext_data/{1,2}`` is the inverse of ``ext_data_to_ejson/{1,2}``. *TODO*: this method is not actually being used by the ``ejson_to_record*`` methods.
2011-06-14 15:24:57 -05:00
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
argglobal
edit ~/projects/jdb-labs/timestamper/web-app/src/ts_common.erl
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal balloonexpr=
setlocal nobinary
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal completefunc=
setlocal nocopyindent
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'erlang'
setlocal filetype=erlang
endif
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=0
setlocal foldmarker={{{,}}}
setlocal foldmethod=manual
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal grepprg=
setlocal iminsert=2
setlocal imsearch=2
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal nolist
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal nomodeline
setlocal modifiable
setlocal nrformats=octal,hex
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=4
setlocal noshortname
setlocal nosmartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'erlang'
setlocal syntax=erlang
endif
setlocal tabstop=4
setlocal tags=
setlocal textwidth=80
setlocal thesaurus=
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
silent! normal! zE
let s:l = 16 - ((14 * winheight(0) + 23) / 46)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
16
normal! 034l
let &so = s:so_save | let &siso = s:siso_save
doautoall SessionLoadPost
" vim: set ft=vim :
syntax on