feat: /support (#22194)

* added: /support

* refactor code and implemented fail checks

* removed unused imports

* changed filter from from title to name

* refactor code to move context inside main

* removed unused variable

* added: /support

* refactor code and implemented fail checks

* removed unused imports

* changed filter from from title to name

* refactor code to move context inside main

* removed unused variable

* refactor: renamed set to get

Co-authored-by: Shivam Mishra <scmmishra@users.noreply.github.com>
Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com>
diff --git a/erpnext/support/doctype/support_settings/support_settings.json b/erpnext/support/doctype/support_settings/support_settings.json
index 1c1b0c3..5d3d3ac 100644
--- a/erpnext/support/doctype/support_settings/support_settings.json
+++ b/erpnext/support/doctype/support_settings/support_settings.json
@@ -1,5 +1,5 @@
 {
- "actions": [],
+ "actions": "",
  "creation": "2017-02-17 13:07:35.686409",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -22,6 +22,10 @@
   "post_description_key",
   "post_route_key",
   "post_route_string",
+  "greetings_section_section",
+  "greeting_title",
+  "column_break_19",
+  "greeting_subtitle",
   "search_apis_sb",
   "search_apis"
  ],
@@ -127,11 +131,40 @@
    "fieldname": "allow_resetting_service_level_agreement",
    "fieldtype": "Check",
    "label": "Allow Resetting Service Level Agreement"
+  },
+  {
+   "default": "We're here to help",
+   "fieldname": "greeting_title",
+   "fieldtype": "Data",
+   "label": "Greeting Title",
+   "show_days": 1,
+   "show_seconds": 1
+  },
+  {
+   "fieldname": "column_break_19",
+   "fieldtype": "Column Break",
+   "show_days": 1,
+   "show_seconds": 1
+  },
+  {
+   "default": "Browse help topics",
+   "fieldname": "greeting_subtitle",
+   "fieldtype": "Data",
+   "label": "Greeting Subtitle",
+   "show_days": 1,
+   "show_seconds": 1
+  },
+  {
+   "fieldname": "greetings_section_section",
+   "fieldtype": "Section Break",
+   "label": "Greetings Section",
+   "show_days": 1,
+   "show_seconds": 1
   }
  ],
  "issingle": 1,
  "links": [],
- "modified": "2020-06-05 17:56:17.491684",
+ "modified": "2020-06-11 13:08:38.473616",
  "modified_by": "Administrator",
  "module": "Support",
  "name": "Support Settings",
diff --git a/erpnext/www/support/__init__.py b/erpnext/www/support/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/www/support/__init__.py
diff --git a/erpnext/www/support/index.html b/erpnext/www/support/index.html
new file mode 100644
index 0000000..824f0bd
--- /dev/null
+++ b/erpnext/www/support/index.html
@@ -0,0 +1,55 @@
+{% extends "templates/web.html" %}
+
+{% block content %}
+<section class="section section-padding-top section-padding-bottom">
+	<div class='container'>
+		<div class="hero-content">
+			<h1 class="h1">{{ _(greeting_title) or _("We're here to help") }}</h1>
+			<p class="hero-subtitle">{{ greeting_subtitle or _("Browse help topics.") }}</p>
+		</div>
+	</div>
+</section>
+
+{% if favorite_article_list %}
+<section class="section section-padding-top section-padding-bottom">
+	<div class='container'>
+		<h3>{{ _("Frequently Read Articles") }}</h3>
+		<div class="row">
+			{% for favorite_article in favorite_article_list %}
+				<div class="mt-4 col-12 col-sm-6 col-lg-4">
+					<div class="card card-md h-100">
+						<div class="card-body">
+							<h6 class="card-subtitle mb-2 text-uppercase small text-muted">{{ favorite_article['category'] }}</h6>
+							<h3 class="card-title">{{ favorite_article['title'] }}</h3>
+							<p class="card-text">{{ favorite_article['description'] }}</p>
+						</div>
+						<a href="{{ favorite_article['route'] }}" class="stretched-link"></a>
+					</div>
+				</div>
+			{% endfor %}
+		</div>
+	</div>
+</section>
+{% endif %}
+
+{% if help_article_list %}
+<section class="section section-padding-top section-padding-bottom bg-light">
+	<div class='container'>
+		<h3>{{ _("Help Articles") }}</h3>
+		<div class="row">
+			{% for item in help_article_list %}
+			<div class="mt-5 col-12 col-sm-6 col-lg-4">
+				<h5>{{ item['category'].name }}</h5>
+				<div>
+					{% for article in item['articles'] %}
+					<a href="{{ article.route }}" class="mt-2 d-block">{{ article.title }}</a>
+					{% endfor %}
+				</div>
+			</div>
+			{% endfor %}
+		</div>
+	</div>
+</section>
+{% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/erpnext/www/support/index.py b/erpnext/www/support/index.py
new file mode 100644
index 0000000..58ca8f7
--- /dev/null
+++ b/erpnext/www/support/index.py
@@ -0,0 +1,74 @@
+from __future__ import unicode_literals
+import frappe
+
+def get_context(context):
+	context.no_cache = 1
+	context.align_greeting = ''
+	setting = frappe.get_doc("Support Settings")
+
+	context.greeting_title = setting.greeting_title
+	context.greeting_subtitle = setting.greeting_subtitle
+	
+	# Support content
+	favorite_articles = get_favorite_articles_by_page_view()
+	if len(favorite_articles) < 6:
+		name_list = []
+		if favorite_articles:
+			for article in favorite_articles:
+				name_list.append(article.name)
+		for record in (frappe.get_all("Help Article", 
+			fields=["title", "content", "route", "category"], 
+			filters={"name": ['not in', tuple(name_list)], "published": 1}, 
+			order_by="creation desc", limit=(6-len(favorite_articles)))):
+			favorite_articles.append(record)
+		
+	context.favorite_article_list = get_favorite_articles(favorite_articles)
+	context.help_article_list = get_help_article_list()
+	
+def get_favorite_articles_by_page_view():
+	return frappe.db.sql(
+			"""
+			SELECT
+				t1.name as name,
+				t1.title as title,
+				t1.content as content,
+				t1.route as route,
+				t1.category as category,
+				count(t1.route) as count 
+			FROM `tabHelp Article` AS t1 
+				INNER JOIN
+				`tabWeb Page View` AS t2 
+			ON t1.route = t2.path 
+			WHERE t1.published = 1
+			GROUP BY route 
+			ORDER BY count DESC
+			LIMIT 6;
+			""", as_dict=True)
+
+def get_favorite_articles(favorite_articles):
+	favorite_article_list=[]
+	for article in favorite_articles:
+		description = frappe.utils.strip_html(article.content)
+		if len(description) > 175:
+			description = description[:172] + '...'
+		favorite_article_dict = {
+			'title': article.title,
+			'description': description,
+			'route': article.route,
+			'category': article.category,
+		}
+		favorite_article_list.append(favorite_article_dict)
+	return favorite_article_list
+
+def get_help_article_list():
+	help_article_list=[]
+	category_list = frappe.get_all("Help Category", fields="name")
+	for category in category_list:
+		help_articles = frappe.get_all("Help Article", fields="*", filters={"category": category.name, "published": 1}, order_by="modified desc", limit=5)
+		if help_articles:
+			help_aricles_per_caetgory = {
+				'category': category,
+				'articles': help_articles,
+			}
+			help_article_list.append(help_aricles_per_caetgory)
+	return help_article_list
\ No newline at end of file