Packages
ami
0.2.0
0.3.9
0.3.8
retired
0.3.7
retired
0.3.6
retired
0.3.5
retired
0.3.4
retired
0.3.3
retired
0.3.2
retired
0.3.1
retired
0.3.0
retired
0.2.9
retired
0.2.8
retired
0.2.7
retired
0.2.6
retired
0.2.5
retired
0.2.3
retired
0.2.2
retired
0.2.1
retired
0.2.0
retired
0.1.9
retired
0.1.8
retired
0.1.7
retired
0.1.6
retired
0.1.5
retired
0.1.4
retired
Package containing all AMI Models shared between micro-services.
Retired package: Security issue - retiring
Current section
Files
Jump to
Current section
Files
lib/ami/tool.ex
defmodule Ami.Tool do
use Ecto.Schema
# import Ecto.{
# Query
# }
alias Ami.{
User,
Community,
Resource,
Like,
Share,
DownloadedTool,
# Repo,
SectionTool,
Video
}
schema "tools" do
@timestamps_opts [type: :naive_datetime_usec]
field(:title, :string)
field(:description, :string)
field(:available_to_other_community, :boolean)
field(:downloaded_tools_count, :integer)
field(:embedly_data, :string)
field(:url, :string)
field(:template, :integer)
field(:views_count, :integer)
field(:created_at, :utc_datetime_usec)
field(:updated_at, :utc_datetime_usec)
belongs_to(:community, Community)
belongs_to(:author, User, foreign_key: :user_id)
has_one(:resource, Resource, foreign_key: :resourceable_id)
has_one(:video, Video, foreign_key: :videoable_id, on_delete: :delete_all)
has_many(:likes, Like, foreign_key: :likeable_id)
has_many(:shares, Share, foreign_key: :shareable_id)
has_many(:downloaded_tools, DownloadedTool, on_delete: :delete_all)
has_many(:section_tools, SectionTool)
has_many(:section_tools_sections, through: [:section_tools, :section])
end
def preload_resource(tool), do: Resource.preload_resource(tool, "Tool")
def preload_likes(tool), do: Like.preload_likes(tool, "Tool")
def preload_video(tool), do: Video.preload_video(tool, "Tool")
def icon_url_for(%Ami.Tool{} = tool) do
case tool.template do
0 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/word-icon.png"
1 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/ppt-icon.png"
2 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/pdf-icon.png"
3 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/excel-icon.png"
4 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/mp3-icon.png"
5 ->
tool = Ami.Tool.preload_resource(tool)
Ami.Resource.file_url({tool.resource.id, tool.resource.file})
6 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/video-icon.png"
7 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/link-icon.png"
8 ->
"https://s3-us-west-2.amazonaws.com/ami-aws-s3/uploads/my_resources/word-icon.png"
end
end
def type_of(%Ami.Tool{} = tool) do
case tool.template do
0 ->
"Document: .docx"
1 ->
"Document: .ppt"
2 ->
"Document: .pdf"
3 ->
"Document: .xlsx"
4 ->
"Document: .mp3"
5 ->
tool = Ami.Tool.preload_resource(tool)
Ami.Resource.file_url({tool.resource.id, tool.resource.file})
7 ->
"Link"
8 ->
"Document: .docx"
6 ->
"Video"
end
end
def parsed_embedly_datas(tool) do
list =
cond do
length(String.split(tool.embedly_data, "\n:")) > 1 ->
String.split(tool.embedly_data, "\n:")
length(String.split(tool.embedly_data, "\n")) > 1 ->
String.split(tool.embedly_data, "\n")
end
List.delete_at(list, 0)
|> Enum.reject(fn e -> Regex.match?(~r{^\s+}, e) end)
|> Enum.flat_map(fn e -> String.split(e, ~r{:}, parts: 2) end)
|> Enum.chunk(2)
|> Enum.map(fn [a, b] -> {String.to_atom(a), b} end)
|> Map.new()
end
end