|
| 1 | +@using System |
| 2 | +@using System.Collections.Generic |
| 3 | +@using System.Dynamic |
| 4 | +@using System.Linq |
| 5 | +@using TNO.TemplateEngine |
| 6 | + |
| 7 | +@{ |
| 8 | + var items = Data as IEnumerable<dynamic>; |
| 9 | + |
| 10 | + if (items == null || !items.Any()) |
| 11 | + { |
| 12 | + <p>No results available.</p> |
| 13 | + return; |
| 14 | + } |
| 15 | + |
| 16 | + @functions { |
| 17 | + public string? FormatMetric(IDictionary<string, object> dict, string key, string label) |
| 18 | + { |
| 19 | + if (dict.ContainsKey(key) |
| 20 | + && !String.IsNullOrWhiteSpace(@dict[key] as string) |
| 21 | + && int.TryParse(@dict[key] as string, out int value) |
| 22 | + && value > 0) |
| 23 | + { |
| 24 | + return $"<span style=\"font-weight: 600;\">" + ReportExtensions.FormatInteger(dict[key] as String, true) + "</span> X Shares,"; |
| 25 | + } |
| 26 | + return null; |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +@if (items != null) |
| 32 | +{ |
| 33 | + <table style="border-collapse: collapse; width: 100%; margin: 0 auto; font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #333333;"> |
| 34 | + @foreach (var item in items) |
| 35 | + { |
| 36 | + var dict = item as IDictionary<string, object>; |
| 37 | + if (dict != null) |
| 38 | + { |
| 39 | + var sentimentStr = dict.ContainsKey("sentiment") ? dict["sentiment"] as String : null; |
| 40 | + int? sentiment = sentimentStr != null && int.TryParse(sentimentStr.Replace("'",""), out int sentimentValue) ? sentimentValue : null; |
| 41 | + var engagement = dict.ContainsKey("engagement") ? ReportExtensions.FormatInteger(dict["engagement"] as String, true) : null; |
| 42 | + var reach = dict.ContainsKey("reach") ? ReportExtensions.FormatInteger(dict["reach"] as String, true) : null; |
| 43 | + var author_image_url = dict.ContainsKey("extra_author_attributes.image_url") ? dict["extra_author_attributes.image_url"] as String : null; |
| 44 | + var title = dict.ContainsKey("title") ? dict["title"] as String : dict.ContainsKey("title_snippet") ? dict["title_snippet"] as String : null; |
| 45 | + var author_name = dict.ContainsKey("extra_author_attributes.name") ? dict["extra_author_attributes.name"] as String : null; |
| 46 | + var author_short_name = dict.ContainsKey("extra_author_attributes.short_name") ? dict["extra_author_attributes.short_name"] as String : null; |
| 47 | + var post_type = dict.ContainsKey("post_type") ? dict["post_type"] as String : null; |
| 48 | + var url = dict.ContainsKey("url") ? dict["url"] as String : null; |
| 49 | + var host_url = dict.ContainsKey("host_url") ? dict["host_url"] as String : null; |
| 50 | + var root_url = dict.ContainsKey("root_url") ? dict["root_url"] as String : null; |
| 51 | + var images_url = dict.ContainsKey("images.url") ? dict["images.url"] as String : null; |
| 52 | + var content = dict.ContainsKey("content") ? dict["content"] as String : null; |
| 53 | + var published = dict.ContainsKey("published") ? dict["published"] as String : null; |
| 54 | + var country = dict.ContainsKey("extra_source_attributes.world_data.country") ? dict["extra_source_attributes.world_data.country"] as String : null; |
| 55 | + var source_name = dict.ContainsKey("extra_source_attributes.name") ? dict["extra_source_attributes.name"] as String : null; |
| 56 | + |
| 57 | + <tr style="height: 100%; width: 100%; box-sizing: border-box;"> |
| 58 | + <td style="padding: 1rem; border-bottom: 1px solid #dddddd; width: 80px; height: 100%; box-sizing: border-box;"> |
| 59 | + @if (!string.IsNullOrWhiteSpace(author_image_url)) |
| 60 | + { |
| 61 | + <div style="width: 50px; height: 50px; border-radius: 50%; overflow: hidden; display: inline-block; text-align: center;"> |
| 62 | + <a href="@root_url"><img src="@author_image_url" style="width: 100%; height:100%; object-fit: cover; display: block;"/></a> |
| 63 | + </div> |
| 64 | + } |
| 65 | + </td> |
| 66 | + <td style="padding: 1rem; border-bottom: 1px solid #dddddd; max-width: 65%; height: 100%; box-sizing: border-box;"> |
| 67 | + <div style="width: 100%; height: 100%; box-sizing: border-box;"> |
| 68 | + <div> |
| 69 | + @if (!string.IsNullOrWhiteSpace(title)) |
| 70 | + { |
| 71 | + <span style="font-weight: 600; margin-right: 0.5rem;"><a href="@dict["url"]" style="color: rgb(52, 81, 153);">@title</a></span> |
| 72 | + } |
| 73 | + <span style="font-weight: 600; margin-right: 1rem; text-transform: capitalize;"><a href="@root_url" style="color: rgb(52, 81, 153);">@author_name</a></span> |
| 74 | + @if (!string.IsNullOrWhiteSpace(author_short_name)) |
| 75 | + { |
| 76 | + <span style="margin-right: 0.5rem;"><a href="@root_url" style="color: rgb(52, 81, 153);">@@@author_short_name</a></span> |
| 77 | + } |
| 78 | + <span style="text-transform: lowercase; font-size: 0.85rem;"> |
| 79 | + @if (post_type == "IMAGE") |
| 80 | + { |
| 81 | + @("shared an image") |
| 82 | + } |
| 83 | + else if (post_type == "LINK") |
| 84 | + { |
| 85 | + @("shared a link") |
| 86 | + } |
| 87 | + else if (post_type == "TEXT") |
| 88 | + { |
| 89 | + @("shared a post") |
| 90 | + } |
| 91 | + else |
| 92 | + { |
| 93 | + @("shared a " + post_type) |
| 94 | + } |
| 95 | + </span> |
| 96 | + </div> |
| 97 | + <div style="padding-top: 1rem;"> |
| 98 | + <table style="border-collapse: collapse;"> |
| 99 | + <tr> |
| 100 | + @if (!string.IsNullOrWhiteSpace(images_url)) |
| 101 | + { |
| 102 | + <td style="padding: 1rem;"><a href="@url"><img src="@images_url" style="max-width: 300px;" /></a></td> |
| 103 | + } |
| 104 | + <td><p>@content</p></td> |
| 105 | + </tr> |
| 106 | + </table> |
| 107 | + </div> |
| 108 | + <div style="font-size: 0.85rem; padding-top: 1rem;"> |
| 109 | + <a href="@url" style="color: rgb(52, 81, 153);">published on @published</a> | @country | <a href="@host_url">@source_name</a> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </td> |
| 113 | + <td style="padding: 1rem; border-bottom: 1px solid #dddddd; width: 35%; height: 100%; box-sizing: border-box;"> |
| 114 | + <div style="padding: 1rem; margin: 1rem; border-left: 1px solid #dddddd;"> |
| 115 | + <table style="border-collapse: collapse;"> |
| 116 | + <tr> |
| 117 | + <td style="padding-bottom: 1rem; text-align: center;"> |
| 118 | + <div>@ReportExtensions.GetSentimentIcon(sentiment)</div> |
| 119 | + </td> |
| 120 | + </tr> |
| 121 | + <tr> |
| 122 | + <td style="font-weight: 600; color: rgb(52, 81, 153); text-align: center; vertical-align: top;">METRICS</td> |
| 123 | + <td style="text-align: left; vertical-align: top; padding: 0 1rem;"> |
| 124 | + <div styles=""> |
| 125 | + <table style="border-collapse: collapse;"> |
| 126 | + <tr> |
| 127 | + <td> |
| 128 | + Engagement: <span style="font-weight: 600; color: rgb(52, 81, 153);">@engagement</span> |
| 129 | + </td> |
| 130 | + <td> |
| 131 | + Reach: <span style="font-weight: 600; color: rgb(52, 81, 153);">@reach</span> |
| 132 | + </td> |
| 133 | + </tr> |
| 134 | + </table> |
| 135 | + </div> |
| 136 | + <div style="font-size: 0.85rem; padding-top: 1rem;"> |
| 137 | + @FormatMetric(dict, "article_extended_attributes.twitter_shares", "X Shares") |
| 138 | + @FormatMetric(dict, "article_extended_attributes.twitter_retweets", "X Reposts") |
| 139 | + @FormatMetric(dict, "article_extended_attributes.twitter_quote_tweets", "X Quotes") |
| 140 | + @FormatMetric(dict, "article_extended_attributes.twitter_replies", "X Replies") |
| 141 | + @FormatMetric(dict, "article_extended_attributes.twitter_likes", "X Likes") |
| 142 | + @FormatMetric(dict, "article_extended_attributes.twitter_followers", "X Followers") |
| 143 | + @FormatMetric(dict, "article_extended_attributes.twitter_impressions", "X Impressions") |
| 144 | + @FormatMetric(dict, "article_extended_attributes.twitter_video_views", "X Video Views") |
| 145 | + |
| 146 | + @FormatMetric(dict, "article_extended_attributes.semrush_unique_visitors", "Semrush Traffic Rank") |
| 147 | + @FormatMetric(dict, "article_extended_attributes.semrush_pageviews", "Semrush Page Views") |
| 148 | + |
| 149 | + @FormatMetric(dict, "article_extended_attributes.alexa_unique_visitors", "Alexa Unique Visitors") |
| 150 | + @FormatMetric(dict, "article_extended_attributes.alexa_pageviews", "Alexa Page Views") |
| 151 | + |
| 152 | + @FormatMetric(dict, "article_extended_attributes.linkedin_shares", "LinkedIn Shares") |
| 153 | + @FormatMetric(dict, "article_extended_attributes.linkedin_impression", "LinkedIn Impressions") |
| 154 | + |
| 155 | + @FormatMetric(dict, "article_extended_attributes.facebook_shares", "Facebook Shares") |
| 156 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_total", "Facebook Reactions") |
| 157 | + @FormatMetric(dict, "article_extended_attributes.facebook_likes", "Facebook Likes") |
| 158 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_haha", "Facebook HaHa") |
| 159 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_angry", "Facebook Angry") |
| 160 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_sad", "Facebook Sad") |
| 161 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_love", "Facebook Love") |
| 162 | + @FormatMetric(dict, "article_extended_attributes.facebook_reactions_wow", "Facebook Wow") |
| 163 | + @FormatMetric(dict, "article_extended_attributes.facebook_followers", "Facebook Followers") |
| 164 | + @FormatMetric(dict, "article_extended_attributes.facebook_group_members", "Facebook Group Members") |
| 165 | + |
| 166 | + @FormatMetric(dict, "article_extended_attributes.pinterest_likes", "Pinterest Likes") |
| 167 | + @FormatMetric(dict, "article_extended_attributes.pinterest_pins", "Pinterest Pins") |
| 168 | + @FormatMetric(dict, "article_extended_attributes.pinterest_repins", "Pinterest Repins") |
| 169 | + @FormatMetric(dict, "article_extended_attributes.pinterest_followers", "Pinterest Followers") |
| 170 | + |
| 171 | + @FormatMetric(dict, "article_extended_attributes.youtube_views", "YouTube Views") |
| 172 | + @FormatMetric(dict, "article_extended_attributes.youtube_likes", "YouTube Likes") |
| 173 | + @FormatMetric(dict, "article_extended_attributes.youtube_dislikes", "YouTube Dislikes") |
| 174 | + |
| 175 | + @FormatMetric(dict, "article_extended_attributes.instagram_likes", "Instagram Likes") |
| 176 | + @FormatMetric(dict, "article_extended_attributes.instagram_followers", "Instagram Followers") |
| 177 | + </div> |
| 178 | + </td> |
| 179 | + </tr> |
| 180 | + </table> |
| 181 | + </div> |
| 182 | + </td> |
| 183 | + </tr> |
| 184 | + } |
| 185 | + else |
| 186 | + { |
| 187 | + <div>Failed to parse data.</div> |
| 188 | + } |
| 189 | + } |
| 190 | + </table> |
| 191 | +} |
| 192 | +else |
| 193 | +{ |
| 194 | + <div>No data found.</div> |
| 195 | +} |
0 commit comments