Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1485 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/git_work

UI: Diff Screen to review changes between document trees
  • Loading branch information
mettta authored Dec 3, 2023
2 parents e32d01f + b7955f8 commit 91245ce
Show file tree
Hide file tree
Showing 31 changed files with 1,724 additions and 97 deletions.
1 change: 1 addition & 0 deletions drafts/requirements/strictdoc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ features = [
# "REQUIREMENTS_COVERAGE_SCREEN",
# "REQUIREMENT_TO_SOURCE_TRACEABILITY",
"HTML2PDF",
"DIFF",
]
1 change: 1 addition & 0 deletions strictdoc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ features = [
"TRACEABILITY_SCREEN",
"DEEP_TRACEABILITY_SCREEN",
"SEARCH",
"DIFF",

# Stable features but not used by StrictDoc.
# "MATHJAX"
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/free_text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import html
from typing import List

from strictdoc.backend.sdoc.models.anchor import Anchor
Expand Down Expand Up @@ -44,6 +45,9 @@ def get_parts_as_text(self) -> str:
raise NotImplementedError(part)
return text

def get_parts_as_text_escaped(self) -> str:
return html.escape(self.get_parts_as_text())


class FreeTextContainer(FreeText):
def __init__(self, parts):
Expand Down
11 changes: 11 additions & 0 deletions strictdoc/backend/sdoc/models/requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,17 @@ def enumerate_fields(self):
for requirement_field_list in requirement_fields:
yield from requirement_field_list

def enumerate_all_fields(self):
for field in self.enumerate_fields():
if field.field_name == "REFS":
continue
meta_field_value = (
field.field_value
if field.field_value
else field.field_value_multiline
)
yield field.field_name, meta_field_value

def enumerate_meta_fields(
self, skip_single_lines=False, skip_multi_lines=False
):
Expand Down
15 changes: 7 additions & 8 deletions strictdoc/backend/sdoc/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from strictdoc.backend.sdoc.processor import ParseContext, SDocParsingProcessor
from strictdoc.helpers.cast import assert_cast
from strictdoc.helpers.exception import StrictDocException
from strictdoc.helpers.file_modification_time import get_file_modification_time
from strictdoc.helpers.md5 import get_file_md5
from strictdoc.helpers.pickle import pickle_dump, pickle_load
from strictdoc.helpers.textx import drop_textx_meta

Expand Down Expand Up @@ -92,6 +92,8 @@ def read_from_file(self, file_path: str) -> Document:
else os.path.abspath(file_path)
)

file_md5 = get_file_md5(file_path)

# File name contains an MD5 hash of its full path to ensure the
# uniqueness of the cached items. Additionally, the unique file name
# contains a full path to the output root to prevent collisions
Expand All @@ -102,7 +104,7 @@ def read_from_file(self, file_path: str) -> Document:
unique_identifier.encode("utf-8")
).hexdigest()
file_name = os.path.basename(full_path_to_file)
file_name += "_" + unique_identifier_md5
file_name += "_" + unique_identifier_md5 + "_" + file_md5

path_to_cached_file = os.path.join(
path_to_tmp_dir,
Expand All @@ -111,12 +113,9 @@ def read_from_file(self, file_path: str) -> Document:
)

if os.path.isfile(path_to_cached_file):
cached_file_mtime = get_file_modification_time(path_to_cached_file)
sdoc_file_mtime = get_file_modification_time(file_path)
if sdoc_file_mtime < cached_file_mtime:
with open(path_to_cached_file, "rb") as cache_file:
sdoc_pickled = cache_file.read()
return assert_cast(pickle_load(sdoc_pickled), Document)
with open(path_to_cached_file, "rb") as cache_file:
sdoc_pickled = cache_file.read()
return assert_cast(pickle_load(sdoc_pickled), Document)

path_to_cached_file_dir = os.path.dirname(path_to_cached_file)
Path(path_to_cached_file_dir).mkdir(parents=True, exist_ok=True)
Expand Down
7 changes: 7 additions & 0 deletions strictdoc/core/project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ProjectFeature(str, Enum):
SEARCH = "SEARCH"
HTML2PDF = "HTML2PDF"
REQIF = "REQIF"
DIFF = "DIFF"
PROJECT_STATISTICS_SCREEN = "PROJECT_STATISTICS_SCREEN"
STANDALONE_DOCUMENT_SCREEN = "STANDALONE_DOCUMENT_SCREEN"
REQUIREMENTS_COVERAGE_SCREEN = "REQUIREMENTS_COVERAGE_SCREEN"
Expand Down Expand Up @@ -238,6 +239,12 @@ def is_activated_search(self):
def is_activated_html2pdf(self) -> bool:
return ProjectFeature.HTML2PDF in self.project_features

def is_activated_diff(self) -> bool:
return (
self.is_running_on_server
and ProjectFeature.DIFF in self.project_features
)

def is_activated_reqif(self) -> bool:
return ProjectFeature.REQIF in self.project_features

Expand Down
19 changes: 19 additions & 0 deletions strictdoc/export/html/_static/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@

/* redefine main layout grid */

[data-viewtype="diff"] .main {
padding: var(--base-gap);
padding-bottom: 0;
position: relative;
overflow: hidden;
scroll-behavior: smooth;
height: 100%;
width: 100%;
background-color: var(--color-bg-main);

display: grid;
place-items: stretch stretch;
place-content: stretch stretch;
grid-template-columns: minmax(0, 1fr) /* issue#1370 https://css-tricks.com/preventing-a-grid-blowout/ */
minmax(0, 1fr);
grid-template-rows: minmax(0, max-content) minmax(0, max-content);
gap: var(--base-rhythm);
}

[data-viewtype="source-file"] .main {
padding: 0;
background: white;
Expand Down
47 changes: 47 additions & 0 deletions strictdoc/export/html/_static/controllers/diff_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Stimulus.register("diff", class extends Controller {
initialize() {

const leftColumn = this.element.querySelector('.diff[left]');
const rightColumn = this.element.querySelector('.diff[right]');

const leftOpenBtn = document.getElementById('diff_left_open');
const leftCloseBtn = document.getElementById('diff_left_close');
const rightOpenBtn = document.getElementById('diff_right_open');
const rightCloseBtn = document.getElementById('diff_right_close');

const detailsLeftAll = [...leftColumn.querySelectorAll('details')];
const detailsRightAll = [...rightColumn.querySelectorAll('details')];
const detailsLeft = [...leftColumn.querySelectorAll('details[modified]')];
const detailsRight = [...rightColumn.querySelectorAll('details[modified]')];

// Add event listener
leftOpenBtn.addEventListener("click", function(event){
event.preventDefault();
openAll(detailsLeft);
});
leftCloseBtn.addEventListener("click", function(event){
event.preventDefault();
closeAll(detailsLeftAll);
});
rightOpenBtn.addEventListener("click", function(event){
event.preventDefault();
openAll(detailsRight);
});
rightCloseBtn.addEventListener("click", function(event){
event.preventDefault();
closeAll(detailsRightAll);
});

}
});

function closeAll(details) {
details.forEach(detail => {
detail.removeAttribute("open")
});
}
function openAll(details) {
details.forEach(detail => {
detail.setAttribute("open", "")
});
}
Loading

0 comments on commit 91245ce

Please sign in to comment.