Skip to content

Commit

Permalink
WHISTLE-593: this view should have been moved to cf_attributes not re…
Browse files Browse the repository at this point in the history
…moved
  • Loading branch information
k-anderson committed Sep 15, 2011
1 parent 5cebbca commit 1d120ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
3 changes: 3 additions & 0 deletions whistle_apps/apps/callflow/priv/couchdb/views/attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
},
"hotdesk_id": {
"map": "function(doc) { if (!doc.hotdesk || doc.pvt_deleted) return; emit(doc.hotdesk.id, {'owner_id':doc._id, 'hotdesk':doc.hotdesk}); }"
},
"temporal_rules": {
"map": "function(doc) { if (doc.pvt_type != 'temporal_rule' || doc.pvt_deleted) return; emit(doc._id, null); }"
}
}
}
16 changes: 16 additions & 0 deletions whistle_apps/apps/callflow/src/cf_attributes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
-export([callee_id/4]).
-export([caller_id_options/4]).
-export([owner_id/2, owned_by/2, owned_by/3]).
-export([temporal_rules/1]).

%%-----------------------------------------------------------------------------
%% @public
%% @doc
%% @end
%%-----------------------------------------------------------------------------
-spec temporal_rules/1 :: (Call) -> undefined | json_object() when
Call :: #cf_call{}.
temporal_rules(#cf_call{account_db=Db}) ->
case couch_mgr:get_results(Db, {<<"cf_attributes">>, <<"temporal_rules">>}, [{<<"include_docs">>, true}]) of
{ok, JObj} ->
JObj;
{error, _} ->
[]
end.

%%-----------------------------------------------------------------------------
%% @public
Expand Down
71 changes: 30 additions & 41 deletions whistle_apps/apps/callflow/src/module/cf_temporal_route.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
,last_day_of_the_month/2, gregorian_days_to_date/1
]).

-define(FIND_RULES, <<"temporal_route/listing_by_next_occurrence">>).
-define(FIND_RULES, <<"">>).

-type improper_month() :: non_neg_integer().
-type improper_day() :: non_neg_integer().
Expand Down Expand Up @@ -148,46 +148,35 @@ process_rules(#temporal{local_sec=LSec, local_date={Y, M, D}}=T,
%% @end
%%--------------------------------------------------------------------
-spec(get_temporal_rules/2 :: (Temporal :: #temporal{}, Call :: #cf_call{}) -> list()).
get_temporal_rules(#temporal{local_sec=LSec, routes=Routes}
,#cf_call{account_db=Db}) ->
case couch_mgr:get_results(Db, ?FIND_RULES, [{<<"startkey">>, null}
,{<<"endkey">>, LSec}
,{<<"include_docs">>, true}]) of
{ok, JObj} ->
Default=#rule{},
[#rule{id =
wh_json:get_value(<<"id">>, R)
,enabled =
wh_json:get_binary_boolean([<<"doc">>, <<"enabled">>], R)
,name =
wh_json:get_value([<<"doc">>, <<"name">>], R, Default#rule.name)
,cycle =
wh_json:get_value([<<"doc">>, <<"cycle">>], R, Default#rule.cycle)
,interval =
wh_util:to_integer(
wh_json:get_value([<<"doc">>, <<"interval">>], R, Default#rule.interval))
,days =
wh_json:get_value([<<"doc">>, <<"days">>], R, Default#rule.days)
,wdays =
wh_json:get_value([<<"doc">>, <<"wdays">>], R, Default#rule.wdays)
,ordinal =
wh_json:get_value([<<"doc">>, <<"ordinal">>], R, Default#rule.ordinal)
,month =
wh_json:get_value([<<"doc">>, <<"month">>], R, Default#rule.month)
,start_date =
get_date(wh_json:get_value([<<"doc">>, <<"start_date">>], R, LSec))
,wtime_start =
wh_util:to_integer(
wh_json:get_value([<<"doc">>, <<"time_window_start">>], R, Default#rule.wtime_start))
,wtime_stop =
wh_util:to_integer(
wh_json:get_value([<<"doc">>, <<"time_window_stop">>], R, Default#rule.wtime_stop))
}
|| R <- JObj,
lists:member(wh_json:get_value(<<"id">>, R), Routes)];
{error, _} ->
[]
end.
get_temporal_rules(#temporal{local_sec=LSec, routes=Routes}, Call) ->
Default=#rule{},
[#rule{id =
wh_json:get_value(<<"id">>, R)
,enabled =
wh_json:get_binary_boolean([<<"doc">>, <<"enabled">>], R)
,name =
wh_json:get_value([<<"doc">>, <<"name">>], R, Default#rule.name)
,cycle =
wh_json:get_value([<<"doc">>, <<"cycle">>], R, Default#rule.cycle)
,interval =
wh_json:get_integer_value([<<"doc">>, <<"interval">>], R, Default#rule.interval)
,days =
wh_json:get_value([<<"doc">>, <<"days">>], R, Default#rule.days)
,wdays =
wh_json:get_value([<<"doc">>, <<"wdays">>], R, Default#rule.wdays)
,ordinal =
wh_json:get_value([<<"doc">>, <<"ordinal">>], R, Default#rule.ordinal)
,month =
wh_json:get_value([<<"doc">>, <<"month">>], R, Default#rule.month)
,start_date =
get_date(wh_json:get_integer_value([<<"doc">>, <<"start_date">>], R, LSec))
,wtime_start =
wh_json:get_integer_value([<<"doc">>, <<"time_window_start">>], R, Default#rule.wtime_start)
,wtime_stop =
wh_json:get_integer_value([<<"doc">>, <<"time_window_stop">>], R, Default#rule.wtime_stop)
}
|| R <- cf_attributes:temporal_rules(Call),
lists:member(wh_json:get_value(<<"id">>, R), Routes)].

%%--------------------------------------------------------------------
%% @private
Expand Down

0 comments on commit 1d120ea

Please sign in to comment.