Commit 24d31deb by Urvil Shah

Add The Get Url Feature

parent 6314ad9e
Pipeline #8057 passed with stages
in 23 minutes 51 seconds
...@@ -16,7 +16,9 @@ using System.IO; ...@@ -16,7 +16,9 @@ using System.IO;
using System.Collections; using System.Collections;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Net.Mail; using System.Net.Mail;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Text;
namespace Mobile.Search.Web.Controllers namespace Mobile.Search.Web.Controllers
{ {
...@@ -77,6 +79,8 @@ namespace Mobile.Search.Web.Controllers ...@@ -77,6 +79,8 @@ namespace Mobile.Search.Web.Controllers
{ {
return View("Edit", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>")); return View("Edit", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>"));
} }
public ActionResult CreateFroala() public ActionResult CreateFroala()
{ {
return View("FroalaIndex", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>")); return View("FroalaIndex", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>"));
...@@ -142,13 +146,15 @@ namespace Mobile.Search.Web.Controllers ...@@ -142,13 +146,15 @@ namespace Mobile.Search.Web.Controllers
// POST: Template/Edit/5 // POST: Template/Edit/5
[HttpPost, ValidateInput(false)] [ValidateInput(false)]
public ActionResult FroalaIndex(string key, string value, string EmailId, bool isSendEmail = false,bool WrapUrl=false, bool AdvertiserHasUnSub=false) [HttpPost]
public ActionResult FroalaIndex(string key, string value, string EmailId, bool isSendEmail = false, bool WrapUrl = false, bool AdvertiserHasUnSub = false, bool isGetUrl = false)
{ {
try try
{ {
string url = "http://config.minbox.email/Offer/Create?template_attributes=";
string url = "http://config.minbox.email/Offer/Create?template_attributes=";
string OriginalValue = value;
Match m; Match m;
string HRefPattern = "href\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))"; string HRefPattern = "href\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))";
// _dynamoClient.WriteSingle("prd_2click_templates", d); // _dynamoClient.WriteSingle("prd_2click_templates", d);
...@@ -160,26 +166,37 @@ namespace Mobile.Search.Web.Controllers ...@@ -160,26 +166,37 @@ namespace Mobile.Search.Web.Controllers
if (!isSendEmail) if (!isSendEmail)
WrapUrl = true; WrapUrl = true;
HashSet<string> Url = new HashSet<string>();
HashSet<string> UrlWrap = new HashSet<string>(); HashSet<string> UrlWrap = new HashSet<string>();
StringBuilder sb = new StringBuilder();
while (m.Success && WrapUrl) while (m.Success && WrapUrl)
{ {
count=count-1; count = count - 1;
if (!m.Value.Contains("Wrap")) if (!m.Value.Contains("Wrap"))
{ {
string to_replace = String.Format("{{{{WrapUrl('{0}')}}}}", m.Groups[1]); string to_replace = String.Format("{{{{WrapUrl('{0}')}}}}", m.Groups[1]);
if(count==0 && AdvertiserHasUnSub) if (count == 0 && AdvertiserHasUnSub)
{ {
to_replace= String.Format("{{{{WrapAdvertiserUnsubscribeUrl('{0}')}}}}", m.Groups[1]); to_replace = String.Format("{{{{WrapAdvertiserUnsubscribeUrl('{0}')}}}}", m.Groups[1]);
} }
if(m.Groups[1].Value.Count()>0 && !m.Groups[1].Value.Contains("anchor") && !UrlWrap.Contains(m.Groups[1].Value)) if (m.Groups[1].Value.Count() > 0 && !m.Groups[1].Value.Contains("anchor") && !Url.Contains(m.Groups[1].Value) && !m.Groups[1].Value.Contains(".css") && !m.Groups[1].Value.Contains(".js"))
{ {
string changeset = Request.Form[count.ToString()];
if (changeset != null)
{
to_replace = changeset;
}
value = value.Replace(m.Groups[1].Value, to_replace); value = value.Replace(m.Groups[1].Value, to_replace);
UrlWrap.Add(m.Groups[1].Value); Url.Add(m.Groups[1].Value);
UrlWrap.Add(to_replace);
string s = String.Format("<textarea id='{0}' name='{0}' runat='server' style =width:90% rows=1 cols=100>{1}</textarea>", count, to_replace);
sb.Append(s);
sb.Append("<br/> <br/>");
} }
} }
m = m.NextMatch(); m = m.NextMatch();
} }
var d = new Dictionary<string, object> var d = new Dictionary<string, object>
{ {
...@@ -187,8 +204,13 @@ namespace Mobile.Search.Web.Controllers ...@@ -187,8 +204,13 @@ namespace Mobile.Search.Web.Controllers
{"html", value} {"html", value}
}; };
if (isGetUrl)
{
return Json(new { Allstring = sb.ToString() });
if (isSendEmail) }
else if (isSendEmail)
{ {
if (sendEmail(value, EmailId)) if (sendEmail(value, EmailId))
{ {
...@@ -201,6 +223,7 @@ namespace Mobile.Search.Web.Controllers ...@@ -201,6 +223,7 @@ namespace Mobile.Search.Web.Controllers
} }
} }
else else
{ {
_dynamoClient.WriteSingle("prd_2click_templates", d); _dynamoClient.WriteSingle("prd_2click_templates", d);
...@@ -214,7 +237,7 @@ namespace Mobile.Search.Web.Controllers ...@@ -214,7 +237,7 @@ namespace Mobile.Search.Web.Controllers
{ {
Log.Error("Edit: Error " + x); Log.Error("Edit: Error " + x);
return Json(new { status = "Failed" }); return Json(new { status = "Failed" });
} }
} }
......
@model KeyValuePair<string, string> @model KeyValuePair<string, string>
@{ @{
ViewBag.Title = "FroalaIndex"; ViewBag.Title = "FroalaIndex";
Layout = null; Layout = null;
var Urls = (HashSet<string>)TempData["message"];
} }
<html> <html>
...@@ -93,7 +95,8 @@ ...@@ -93,7 +95,8 @@
</style> </style>
</head> </head>
<body> <body>
@using (Html.BeginForm("FroalaIndex", "Template", FormMethod.Post, new { @class = "pure-form pure-form-stacked" }))
@using (Html.BeginForm("FroalaIndex", "Template", FormMethod.Post | FormMethod.Get, new { @class = "pure-form pure-form-stacked" }))
{ {
<div class="left col"> <div class="left col">
...@@ -158,11 +161,19 @@ ...@@ -158,11 +161,19 @@
</td> </td>
</tr> </tr>
</table> </table>
</div>
</div>
<div>
<div class="pure-controls">
<button type="submit" id="GetUrls" class="pure-button pure-button-primary">Get All Urls</button>
</div>
<div id="output" style="width:80%; margin-right:10px;margin-left:10px">
</div> </div>
</div> </div>
</div> </div>
</div> </div>
...@@ -177,7 +188,7 @@ ...@@ -177,7 +188,7 @@
</div> </div>
</div> </div>
} }
@Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jquery")
<script type="text/javascript" src="~/Scripts/CodeMirror/lib/codemirror.js"></script> <script type="text/javascript" src="~/Scripts/CodeMirror/lib/codemirror.js"></script>
<script type="text/javascript" src="~/Scripts/CodeMirror/mode/xml/xml.js"></script> <script type="text/javascript" src="~/Scripts/CodeMirror/mode/xml/xml.js"></script>
...@@ -191,23 +202,7 @@ ...@@ -191,23 +202,7 @@
<!-- Include Editor JS files. --> <!-- Include Editor JS files. -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.7.6/js/froala_editor.pkgd.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.7.6/js/froala_editor.pkgd.min.js"></script>
<script> <script>
//$(function () {
// $('textarea').froalaEditor({
// heightMin: 900,
// })
//});
//$(function () {
// $('textarea')
// .on('froalaEditor.contentChanged froalaEditor.initialized', function (e, editor) {
// $('pre#eg-previewer').text(editor.codeBeautifier.run(editor.html.get()))
// $('pre#eg-previewer').removeClass('prettyprinted');
// prettyPrint()
// })
// .froalaEditor()
//});
$(document).ready(function () { $(document).ready(function () {
var original_helpers = $.FE.MODULES.helpers; var original_helpers = $.FE.MODULES.helpers;
$.FE.MODULES.helpers = function (editor) { $.FE.MODULES.helpers = function (editor) {
...@@ -217,7 +212,6 @@ ...@@ -217,7 +212,6 @@
// This is the original sanitizer. // This is the original sanitizer.
helpers.sanitizeURL = function (url) { helpers.sanitizeURL = function (url) {
console.log('hello :)')
return url; return url;
}; };
...@@ -245,6 +239,7 @@ ...@@ -245,6 +239,7 @@
$('#SendEmail').click(function (e) { $('#SendEmail').click(function (e) {
e.preventDefault(); e.preventDefault();
var Content = $('#FroalaHtmlEditor').froalaEditor('html.get'); var Content = $('#FroalaHtmlEditor').froalaEditor('html.get');
if (Content.length < 1) { if (Content.length < 1) {
Content = $('#FroalaHtmlEditor').froalaEditor('codeView.get'); Content = $('#FroalaHtmlEditor').froalaEditor('codeView.get');
} }
...@@ -280,7 +275,55 @@ ...@@ -280,7 +275,55 @@
}); });
}); });
$('#GetUrls').click(function (e) {
e.preventDefault();
var Content = $('#FroalaHtmlEditor').froalaEditor('html.get');
if (Content.length < 1) {
Content = $('#FroalaHtmlEditor').froalaEditor('codeView.get');
}
var EmailId = document.getElementById("EmailId").value;
var key = document.getElementById("KeyValue").value;
var WrapUrl = document.getElementById("WrapUrl").checked;
var WrapAdvertiserUrl = document.getElementById("WrapAdvertiserUrl").checked;
//$('#GetUrls').hide();
//$('#sent_to_email_failed').hide();
//$('WrapUrl').hide();
//$('WrapAdvertiserUrl').hide();
$.ajax({
url: "/Template/FroalaIndex",
type: "POST",
data: JSON.stringify({ 'key': key, 'value': Content, 'EmailId': EmailId, 'isSendEmail': false, 'WrapUrl': WrapUrl, 'AdvertiserHasUnSub': WrapAdvertiserUrl, 'isGetUrl': true }),
dataType: "json",
traditional: true,
async: false,
cache: false,
contentType: "application/json; charset=utf-8",
success: function (data) {
$('#output').html(data.Allstring);
if (data.status == "Success") {
$('#sent_to_email_failed').hide();
$('#email_id').empty().append(EmailId);
$('#sent_to_email').show();
document.getElementById("EmailId").value = ""
} else {
$('#sent_to_email').hide();
$('#email_id_failed').empty().append(EmailId);
$('#sent_to_email_failed').hide();
document.getElementById("EmailId").value = ""
}
}
});
});
}); });
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment