forked from Simon-Initiative/oli-torus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Simon-Initiative:master' into master
- Loading branch information
Showing
15 changed files
with
416 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
defmodule Oli.Delivery.Gating.ConditionTypes.Progress do | ||
@moduledoc """ | ||
The progress strategy provides a condition that requires a practice page type source resource to have a | ||
certain percentage of progress in its content. | ||
""" | ||
|
||
alias Oli.Delivery.Gating.GatingCondition | ||
alias Oli.Delivery.Gating.GatingConditionData | ||
alias Oli.Delivery.Gating.ConditionTypes.ConditionContext | ||
alias Oli.Delivery.Sections | ||
alias Oli.Publishing.DeliveryResolver | ||
|
||
@behaviour Oli.Delivery.Gating.ConditionTypes.ConditionType | ||
|
||
def type do | ||
:progress | ||
end | ||
|
||
def evaluate( | ||
%GatingCondition{ | ||
data: %GatingConditionData{ | ||
resource_id: resource_id, | ||
minimum_percentage: minimum_percentage | ||
} | ||
}, | ||
%ConditionContext{} = context | ||
) do | ||
{resource_accesses, context} = ConditionContext.resource_accesses(context) | ||
|
||
result = | ||
case Map.get(resource_accesses, resource_id) do | ||
nil -> | ||
false | ||
|
||
%{resource_attempts_count: 0} -> | ||
false | ||
|
||
%{progress: progress} -> | ||
case minimum_percentage do | ||
nil -> true | ||
min -> progress >= min | ||
end | ||
end | ||
|
||
{result, context} | ||
end | ||
|
||
def details( | ||
%GatingCondition{ | ||
section_id: section_id, | ||
resource_id: resource_id, | ||
data: %GatingConditionData{ | ||
resource_id: source_id, | ||
minimum_percentage: minimum_percentage | ||
} | ||
}, | ||
_ \\ [] | ||
) do | ||
section = Sections.get_section!(section_id) | ||
|
||
[revision, revision_source] = | ||
DeliveryResolver.from_resource_id(section.slug, [resource_id, source_id]) | ||
|
||
case minimum_percentage do | ||
nil -> | ||
"#{revision.title} cannot be accessed until #{revision_source.title} is completed" | ||
|
||
min -> | ||
{percentage, _} = (min * 100) |> Float.to_string() |> Integer.parse() | ||
|
||
"#{revision.title} cannot be accessed until #{percentage}% of #{revision_source.title} activities have been completed" | ||
end | ||
end | ||
end |
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
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
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
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
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
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
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
Oops, something went wrong.